1
- import React , { Component , Fragment } from " react" ;
2
- import { connect } from " react-redux" ;
1
+ import React , { Component , Fragment } from ' react' ;
2
+ import { connect } from ' react-redux' ;
3
3
4
4
// import PropTypes from 'prop-types';
5
- import { withStyles } from " @material-ui/core/styles" ;
6
- import Chip from " @material-ui/core/Chip" ;
7
- import Avatar from " @material-ui/core/Avatar" ;
8
- import FormControl from " @material-ui/core/FormControl" ;
9
- import Grid from " @material-ui/core/Grid" ;
10
- import TextField from " @material-ui/core/TextField" ;
11
- import Button from " @material-ui/core/Button" ;
12
- import Select from " @material-ui/core/Select" ;
13
- import Switch from " @material-ui/core/Switch" ;
14
- import InputLabel from " @material-ui/core/InputLabel" ;
15
- import RemoveCircleOutlineIcon from " @material-ui/icons/RemoveCircleOutline" ;
16
- import { addProp , deleteProp } from " ../actions/components" ;
17
- import DataTable from " ./DataTable.jsx" ;
5
+ import { withStyles } from ' @material-ui/core/styles' ;
6
+ import Chip from ' @material-ui/core/Chip' ;
7
+ import Avatar from ' @material-ui/core/Avatar' ;
8
+ import FormControl from ' @material-ui/core/FormControl' ;
9
+ import Grid from ' @material-ui/core/Grid' ;
10
+ import TextField from ' @material-ui/core/TextField' ;
11
+ import Button from ' @material-ui/core/Button' ;
12
+ import Select from ' @material-ui/core/Select' ;
13
+ import Switch from ' @material-ui/core/Switch' ;
14
+ import InputLabel from ' @material-ui/core/InputLabel' ;
15
+ import RemoveCircleOutlineIcon from ' @material-ui/icons/RemoveCircleOutline' ;
16
+ import { addProp , deleteProp } from ' ../actions/components' ;
17
+ import DataTable from ' ./DataTable.jsx' ;
18
18
19
19
const styles = theme => ( {
20
20
root : {
21
- display : " flex" ,
22
- justifyContent : " center" ,
23
- flexWrap : " wrap"
21
+ display : ' flex' ,
22
+ justifyContent : ' center' ,
23
+ flexWrap : ' wrap' ,
24
24
} ,
25
25
chip : {
26
26
margin : theme . spacing . unit ,
27
- color : " #eee" ,
28
- backgroundColor : " #333333"
27
+ color : ' #eee' ,
28
+ backgroundColor : ' #333333' ,
29
29
} ,
30
30
column : {
31
- display : " inline-flex" ,
32
- alignItems : " baseline"
31
+ display : ' inline-flex' ,
32
+ alignItems : ' baseline' ,
33
33
} ,
34
34
icon : {
35
- fontSize : " 20px" ,
36
- color : " #eee" ,
37
- opacity : " 0.7" ,
38
- transition : " all .2s ease" ,
35
+ fontSize : ' 20px' ,
36
+ color : ' #eee' ,
37
+ opacity : ' 0.7' ,
38
+ transition : ' all .2s ease' ,
39
39
40
- " &:hover" : {
41
- color : " red"
42
- }
40
+ ' &:hover' : {
41
+ color : ' red' ,
42
+ } ,
43
43
} ,
44
44
cssLabel : {
45
- color : " white" ,
45
+ color : ' white' ,
46
46
47
- " &$cssFocused" : {
48
- color : " green"
49
- }
47
+ ' &$cssFocused' : {
48
+ color : ' green' ,
49
+ } ,
50
50
} ,
51
51
cssFocused : { } ,
52
52
input : {
53
- color : " #eee" ,
54
- marginBottom : " 10px" ,
55
- width : " 60%"
53
+ color : ' #eee' ,
54
+ marginBottom : ' 10px' ,
55
+ width : ' 60%' ,
56
56
} ,
57
57
light : {
58
- color : " #eee"
58
+ color : ' #eee' ,
59
59
} ,
60
60
avatar : {
61
- color : " #eee" ,
62
- fontSize : " 10px"
63
- }
61
+ color : ' #eee' ,
62
+ fontSize : ' 10px' ,
63
+ } ,
64
64
} ) ;
65
65
66
66
const mapDispatchToProps = dispatch => ( {
67
- addProp : ( { key, value, required, type } ) =>
68
- dispatch (
69
- addProp ( {
70
- key,
71
- value,
72
- required,
73
- type
74
- } )
75
- ) ,
76
- deleteProp : propId => dispatch ( deleteProp ( propId ) )
67
+ addProp : ( {
68
+ key, value, required, type,
69
+ } ) => dispatch (
70
+ addProp ( {
71
+ key,
72
+ value,
73
+ required,
74
+ type,
75
+ } ) ,
76
+ ) ,
77
+ deleteProp : propId => dispatch ( deleteProp ( propId ) ) ,
77
78
} ) ;
78
79
79
80
const mapStateToProps = store => ( {
80
- focusComponent : store . workspace . focusComponent
81
+ focusComponent : store . workspace . focusComponent ,
81
82
} ) ;
82
83
83
84
const availablePropTypes = {
84
- string : " STR" ,
85
- object : " OBJ" ,
86
- array : " ARR" ,
87
- number : " NUM" ,
88
- bool : " BOOL" ,
89
- func : " FUNC" ,
90
- symbol : " SYM" ,
91
- node : " NODE" ,
92
- element : " ELEM"
85
+ string : ' STR' ,
86
+ object : ' OBJ' ,
87
+ array : ' ARR' ,
88
+ number : ' NUM' ,
89
+ boolean : ' BOOL' ,
90
+ function : ' FUNC' ,
91
+ symbol : ' SYM' ,
92
+ node : ' NODE' ,
93
+ element : ' ELEM' ,
93
94
} ;
94
95
95
96
const typeOptions = [
96
97
< option value = "" key = "" /> ,
97
98
...Object . keys ( availablePropTypes ) . map ( type => (
98
- < option value = { type } key = { type } style = { { color : " #000" } } >
99
+ < option value = { type } key = { type } style = { { color : ' #000' } } >
99
100
{ type }
100
101
</ option >
101
- ) )
102
+ ) ) ,
102
103
] ;
103
104
104
105
class Props extends Component {
105
106
state = {
106
- propKey : "" ,
107
- propValue : "" ,
107
+ propKey : '' ,
108
+ propValue : '' ,
108
109
propRequired : false ,
109
- propType : ""
110
+ propType : '' ,
110
111
} ;
111
112
112
- handleChange = event => {
113
+ handleChange = ( event ) => {
113
114
this . setState ( {
114
- [ event . target . id ] : event . target . value . trim ( )
115
+ [ event . target . id ] : event . target . value . trim ( ) ,
115
116
} ) ;
116
117
} ;
117
118
118
119
togglePropRequired = ( ) => {
119
120
this . setState ( {
120
- propRequired : ! this . state . propRequired
121
+ propRequired : ! this . state . propRequired ,
121
122
} ) ;
122
123
} ;
123
124
124
- handleAddProp = event => {
125
+ handleAddProp = ( event ) => {
125
126
event . preventDefault ( ) ;
126
127
127
- const { propKey, propValue, propRequired, propType } = this . state ;
128
+ const {
129
+ propKey, propValue, propRequired, propType,
130
+ } = this . state ;
128
131
129
132
// check if prop exists with same key. CANNOT have doubles
130
133
const savedPropKeys = this . props . focusComponent . props . map ( p => p . key ) ;
@@ -137,36 +140,38 @@ class Props extends Component {
137
140
key : propKey ,
138
141
value : propValue ,
139
142
required : propRequired ,
140
- type : propType
143
+ type : propType ,
141
144
} ) ;
142
145
143
146
this . setState ( {
144
- propKey : "" ,
145
- propValue : "" ,
147
+ propKey : '' ,
148
+ propValue : '' ,
146
149
propRequired : false ,
147
- propType : ""
150
+ propType : '' ,
148
151
} ) ;
149
152
} ;
150
153
151
154
render ( ) {
152
- const { focusComponent, classes, deleteProp, addProp } = this . props ;
155
+ const {
156
+ focusComponent, classes, deleteProp, addProp,
157
+ } = this . props ;
153
158
154
- const rowHeader = [ " _Key" , " Value" , " Type" , " Required" ] ;
159
+ const rowHeader = [ ' _Key' , ' Value' , ' Type' , ' Required' ] ;
155
160
// prepare the saved Props in a nice way, so you can sent them to TableData
156
161
const propsRows = focusComponent . props . map ( prop => ( {
157
162
_Key : prop . key ,
158
163
Value : prop . value ,
159
164
Type : prop . type ,
160
165
Required : prop . required ,
161
- id : prop . id
166
+ id : prop . id ,
162
167
} ) ) ;
163
168
164
169
return (
165
170
// <div style={{ display: rightColumnOpen ? "inline" : "none" }}>
166
171
< div >
167
- { " " }
172
+ { ' ' }
168
173
{ Object . keys ( focusComponent ) . length < 1 ? (
169
- < div style = { { marginTop : " 20px" , marginLeft : " 20px" } } >
174
+ < div style = { { marginTop : ' 20px' , marginLeft : ' 20px' } } >
170
175
Click a component to view its props.
171
176
</ div >
172
177
) : (
@@ -186,10 +191,10 @@ class Props extends Component {
186
191
value = { this . state . propKey }
187
192
required
188
193
InputProps = { {
189
- className : classes . input
194
+ className : classes . input ,
190
195
} }
191
196
InputLabelProps = { {
192
- className : classes . input
197
+ className : classes . input ,
193
198
} }
194
199
/>
195
200
</ Grid >
@@ -200,20 +205,17 @@ class Props extends Component {
200
205
margin = "normal"
201
206
onChange = { this . handleChange }
202
207
InputProps = { {
203
- className : classes . input
208
+ className : classes . input ,
204
209
} }
205
210
InputLabelProps = { {
206
- className : classes . input
211
+ className : classes . input ,
207
212
} }
208
213
value = { this . state . propValue }
209
214
/>
210
215
</ Grid >
211
216
< Grid item xs = { 6 } >
212
217
< FormControl required >
213
- < InputLabel
214
- className = { classes . light }
215
- htmlFor = "propType"
216
- >
218
+ < InputLabel className = { classes . light } htmlFor = "propType" >
217
219
Type
218
220
</ InputLabel >
219
221
< Select
@@ -231,10 +233,7 @@ class Props extends Component {
231
233
</ Grid >
232
234
< Grid item xs = { 6 } >
233
235
< div className = { classes . column } >
234
- < InputLabel
235
- className = { classes . light }
236
- htmlFor = "propRequired"
237
- >
236
+ < InputLabel className = { classes . light } htmlFor = "propRequired" >
238
237
Required?
239
238
</ InputLabel >
240
239
< Switch
@@ -305,5 +304,5 @@ class Props extends Component {
305
304
306
305
export default connect (
307
306
mapStateToProps ,
308
- mapDispatchToProps
307
+ mapDispatchToProps ,
309
308
) ( withStyles ( styles ) ( Props ) ) ;
0 commit comments