1
- import React , { Component , Fragment } from " react" ;
2
- import { connect } from " react-redux" ;
3
- import { withStyles } from " @material-ui/core/styles" ;
4
- import FormControl from " @material-ui/core/FormControl" ;
5
- import Grid from " @material-ui/core/Grid" ;
6
- import TextField from " @material-ui/core/TextField" ;
7
- import Button from " @material-ui/core/Button" ;
8
- import Select from " @material-ui/core/Select" ;
9
- import Switch from " @material-ui/core/Switch" ;
10
- import InputLabel from " @material-ui/core/InputLabel" ;
11
- import { addProp , deleteProp } from " ../actions/components.ts" ;
12
- import DataTable from " ./DataTable.tsx" ;
13
- import { ComponentInt } from " ../utils/interfaces.ts" ;
1
+ import React , { Component , Fragment } from ' react' ;
2
+ import { connect } from ' react-redux' ;
3
+ import { withStyles } from ' @material-ui/core/styles' ;
4
+ import FormControl from ' @material-ui/core/FormControl' ;
5
+ import Grid from ' @material-ui/core/Grid' ;
6
+ import TextField from ' @material-ui/core/TextField' ;
7
+ import Button from ' @material-ui/core/Button' ;
8
+ import Select from ' @material-ui/core/Select' ;
9
+ import Switch from ' @material-ui/core/Switch' ;
10
+ import InputLabel from ' @material-ui/core/InputLabel' ;
11
+ import { addProp , deleteProp } from ' ../actions/components.ts' ;
12
+ import DataTable from ' ./DataTable.tsx' ;
13
+ import { ComponentInt } from ' ../utils/interfaces.ts' ;
14
14
15
15
interface PropInt {
16
16
addProp : any ;
@@ -21,125 +21,126 @@ interface PropInt {
21
21
22
22
const styles = ( theme : any ) : any => ( {
23
23
root : {
24
- display : " flex" ,
25
- justifyContent : " center" ,
26
- flexWrap : " wrap"
24
+ display : ' flex' ,
25
+ justifyContent : ' center' ,
26
+ flexWrap : ' wrap' ,
27
27
} ,
28
28
chip : {
29
- color : " #eee" ,
30
- backgroundColor : " #333333"
29
+ color : ' #eee' ,
30
+ backgroundColor : ' #333333' ,
31
31
} ,
32
32
column : {
33
- display : " inline-flex" ,
34
- alignItems : " baseline"
33
+ display : ' inline-flex' ,
34
+ alignItems : ' baseline' ,
35
35
} ,
36
36
icon : {
37
- fontSize : " 20px" ,
38
- color : " #eee" ,
39
- opacity : " 0.7" ,
40
- transition : " all .2s ease" ,
37
+ fontSize : ' 20px' ,
38
+ color : ' #eee' ,
39
+ opacity : ' 0.7' ,
40
+ transition : ' all .2s ease' ,
41
41
42
- " &:hover" : {
43
- color : " red"
44
- }
42
+ ' &:hover' : {
43
+ color : ' red' ,
44
+ } ,
45
45
} ,
46
46
cssLabel : {
47
- color : " white" ,
47
+ color : ' white' ,
48
48
49
- " &$cssFocused" : {
50
- color : " green"
51
- }
49
+ ' &$cssFocused' : {
50
+ color : ' green' ,
51
+ } ,
52
52
} ,
53
53
cssFocused : { } ,
54
54
input : {
55
- color : " #eee" ,
56
- marginBottom : " 10px" ,
57
- width : " 60%"
55
+ color : ' #eee' ,
56
+ marginBottom : ' 10px' ,
57
+ width : ' 60%' ,
58
58
} ,
59
59
light : {
60
- color : " #eee"
60
+ color : ' #eee' ,
61
61
} ,
62
62
avatar : {
63
- color : " #eee" ,
64
- fontSize : " 10px"
65
- }
63
+ color : ' #eee' ,
64
+ fontSize : ' 10px' ,
65
+ } ,
66
66
} ) ;
67
67
68
68
const mapDispatchToProps = ( dispatch : any ) => ( {
69
69
addProp : ( {
70
70
key,
71
71
value,
72
72
required,
73
- type
73
+ type,
74
74
} : {
75
- key : string ;
76
- value : string ;
77
- required : boolean ;
78
- type : string ;
79
- } ) =>
80
- dispatch (
81
- addProp ( {
82
- key,
83
- value,
84
- required,
85
- type
86
- } )
87
- ) ,
88
- deleteProp : ( propId : number ) => dispatch ( deleteProp ( propId ) )
75
+ key : string ;
76
+ value : string ;
77
+ required : boolean ;
78
+ type : string ;
79
+ } ) => dispatch (
80
+ addProp ( {
81
+ key,
82
+ value,
83
+ required,
84
+ type,
85
+ } ) ,
86
+ ) ,
87
+ deleteProp : ( propId : number ) => dispatch ( deleteProp ( propId ) ) ,
89
88
} ) ;
90
89
91
90
const mapStateToProps = ( store : any ) => ( {
92
- focusComponent : store . workspace . focusComponent
91
+ focusComponent : store . workspace . focusComponent ,
93
92
} ) ;
94
93
95
94
const availablePropTypes = {
96
- string : " STR" ,
97
- number : " NUM" ,
98
- object : " OBJ" ,
99
- array : " ARR" ,
100
- boolean : " BOOL" ,
101
- function : " FUNC" ,
95
+ string : ' STR' ,
96
+ number : ' NUM' ,
97
+ object : ' OBJ' ,
98
+ array : ' ARR' ,
99
+ boolean : ' BOOL' ,
100
+ function : ' FUNC' ,
102
101
// symbol: 'SYM',
103
- node : " NODE" ,
104
- element : " ELEM" ,
105
- any : " ANY" ,
106
- tuple : " TUP" ,
107
- enum : " ENUM"
102
+ node : ' NODE' ,
103
+ element : ' ELEM' ,
104
+ any : ' ANY' ,
105
+ tuple : ' TUP' ,
106
+ enum : ' ENUM' ,
108
107
} ;
109
108
110
109
const typeOptions = [
111
110
< option value = "" key = "" /> ,
112
111
...Object . keys ( availablePropTypes ) . map ( type => (
113
- < option value = { type } key = { type } style = { { color : " #000" } } >
112
+ < option value = { type } key = { type } style = { { color : ' #000' } } >
114
113
{ type }
115
114
</ option >
116
- ) )
115
+ ) ) ,
117
116
] ;
118
117
119
118
class Props extends Component < PropInt > {
120
119
state = {
121
- propKey : "" ,
122
- propValue : "" ,
120
+ propKey : '' ,
121
+ propValue : '' ,
123
122
propRequired : true ,
124
- propType : ""
123
+ propType : '' ,
125
124
} ;
126
125
127
126
handleChange = ( event : any ) => {
128
127
this . setState ( {
129
- [ event . target . id ] : event . target . value . trim ( )
128
+ [ event . target . id ] : event . target . value . trim ( ) ,
130
129
} ) ;
131
130
} ;
132
131
133
132
togglePropRequired = ( ) => {
134
133
this . setState ( {
135
- propRequired : ! this . state . propRequired
134
+ propRequired : ! this . state . propRequired ,
136
135
} ) ;
137
136
} ;
138
137
139
138
handleAddProp = ( event : any ) => {
140
139
event . preventDefault ( ) ;
141
140
142
- const { propKey, propValue, propRequired, propType } = this . state ;
141
+ const {
142
+ propKey, propValue, propRequired, propType,
143
+ } = this . state ;
143
144
144
145
// check if prop exists with same key. CANNOT have duplicates
145
146
const savedPropKeys = this . props . focusComponent . props . map ( p => p . key ) ;
@@ -150,53 +151,55 @@ class Props extends Component<PropInt> {
150
151
151
152
// check if prop starts with digits. Digits at string start breaks indexedDB
152
153
if ( / ^ \d / . test ( propKey ) ) {
153
- window . alert ( " Props are not allowed to begin with digits" ) ;
154
+ window . alert ( ' Props are not allowed to begin with digits' ) ;
154
155
return ;
155
156
}
156
157
157
158
this . props . addProp ( {
158
159
key : propKey ,
159
160
value : propValue ,
160
161
required : propRequired ,
161
- type : propType
162
+ type : propType ,
162
163
} ) ;
163
164
164
165
this . setState ( {
165
- propKey : "" ,
166
- propValue : "" ,
166
+ propKey : '' ,
167
+ propValue : '' ,
167
168
propRequired : true ,
168
- propType : ""
169
+ propType : '' ,
169
170
} ) ;
170
171
} ;
171
172
172
173
render ( ) {
173
- const { focusComponent, classes, deleteProp, addProp } = this . props ;
174
+ const {
175
+ focusComponent, classes, deleteProp, addProp,
176
+ } = this . props ;
174
177
175
- const rowHeader = [ " _Key" , " Value" , " Type" , " Required" ] ;
178
+ const rowHeader = [ ' _Key' , ' Value' , ' Type' , ' Required' ] ;
176
179
// prepare the saved Props in a nice way, so you can sent them to TableData
177
180
const propsRows = focusComponent . props . map ( prop => ( {
178
181
_Key : prop . key ,
179
182
Value : prop . value ,
180
183
Type : prop . type ,
181
184
Required : prop . required ,
182
- id : prop . id
185
+ id : prop . id ,
183
186
} ) ) ;
184
187
185
188
return (
186
- < div className = { " htmlattr" } >
187
- { " " }
189
+ < div className = { ' htmlattr' } >
190
+ { ' ' }
188
191
{ Object . keys ( focusComponent ) . length < 1 ? (
189
- < div style = { { marginTop : " 20px" , width : " 90%" } } >
192
+ < div style = { { marginTop : ' 20px' , width : ' 90%' } } >
190
193
Click a component to view its props.
191
194
</ div >
192
195
) : (
193
196
< Fragment >
194
197
< div
195
198
className = "props-container"
196
- style = { { marginTop : " 20px" , width : " 90%" , height : " 80%" } }
199
+ style = { { marginTop : ' 20px' , width : ' 90%' , height : ' 80%' } }
197
200
>
198
201
< Grid container spacing = { 8 } >
199
- < Grid item xs = { 4 } >
202
+ < Grid item xs = { 3 } >
200
203
< form className = "props-input" onSubmit = { this . handleAddProp } >
201
204
< Grid container spacing = { 8 } >
202
205
< Grid item xs = { 6 } >
@@ -209,10 +212,10 @@ class Props extends Component<PropInt> {
209
212
value = { this . state . propKey }
210
213
required
211
214
InputProps = { {
212
- className : classes . input
215
+ className : classes . input ,
213
216
} }
214
217
InputLabelProps = { {
215
- className : classes . input
218
+ className : classes . input ,
216
219
} }
217
220
/>
218
221
</ Grid >
@@ -223,20 +226,17 @@ class Props extends Component<PropInt> {
223
226
margin = "normal"
224
227
onChange = { this . handleChange }
225
228
InputProps = { {
226
- className : classes . input
229
+ className : classes . input ,
227
230
} }
228
231
InputLabelProps = { {
229
- className : classes . input
232
+ className : classes . input ,
230
233
} }
231
234
value = { this . state . propValue }
232
235
/>
233
236
</ Grid >
234
237
< Grid item xs = { 6 } >
235
238
< FormControl required >
236
- < InputLabel
237
- className = { classes . light }
238
- htmlFor = "propType"
239
- >
239
+ < InputLabel className = { classes . light } htmlFor = "propType" >
240
240
Type
241
241
</ InputLabel >
242
242
< Select
@@ -254,10 +254,7 @@ class Props extends Component<PropInt> {
254
254
</ Grid >
255
255
< Grid item xs = { 6 } >
256
256
< div className = { classes . column } >
257
- < InputLabel
258
- className = { classes . light }
259
- htmlFor = "propRequired"
260
- >
257
+ < InputLabel className = { classes . light } htmlFor = "propRequired" >
261
258
Required?
262
259
</ InputLabel >
263
260
< Switch
@@ -291,6 +288,7 @@ class Props extends Component<PropInt> {
291
288
deletePropHandler = { deleteProp }
292
289
/>
293
290
</ Grid >
291
+ < Grid item xs = { 1 } />
294
292
</ Grid >
295
293
</ div >
296
294
</ Fragment >
@@ -302,5 +300,5 @@ class Props extends Component<PropInt> {
302
300
303
301
export default connect (
304
302
mapStateToProps ,
305
- mapDispatchToProps
303
+ mapDispatchToProps ,
306
304
) ( withStyles ( styles ) ( Props ) ) ;
0 commit comments