1
1
import React , { Fragment } from 'react' ;
2
2
import { withStyles } from '@material-ui/core/styles' ;
3
3
import Typography from '@material-ui/core/Typography' ;
4
+ import TextField from '@material-ui/core/TextField' ;
4
5
import List from '@material-ui/core/List' ;
5
6
import ListItem from '@material-ui/core/ListItem' ;
6
7
import ListItemText from '@material-ui/core/ListItemText' ;
@@ -25,8 +26,12 @@ interface LeftColExpPanPropsInt extends PropsInt {
25
26
componentId : number ;
26
27
stateComponents : ComponentsInt ;
27
28
} ) : void ;
28
- toggleComponentState ( arg : { id : number } ) : void ;
29
- toggleComponentClass ( arg : { id : number } ) : void ;
29
+ toggleComponentState ( arg : { id : number } ) : void ;
30
+ toggleComponentClass ( arg : { id : number } ) : void ;
31
+ editMode : number ;
32
+ toggleEditMode ( arg : { id : number } ) : void ;
33
+ handleChangeName ( event : string ) : void ;
34
+ handleEditComponent ( ) : void ;
30
35
}
31
36
//interface created but never used
32
37
// interface TypographyProps {
@@ -44,7 +49,11 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
44
49
selectableChildren,
45
50
deleteComponent,
46
51
toggleComponentState,
47
- toggleComponentClass
52
+ toggleComponentClass,
53
+ editMode,
54
+ toggleEditMode,
55
+ handleChangeName,
56
+ handleEditComponent,
48
57
} = props ;
49
58
const { title, id, color, stateful, classBased } = component ;
50
59
function isFocused ( ) {
@@ -53,14 +62,23 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
53
62
// boolean flag to determine if the component card is focused or not
54
63
// state/class toggles will be displayed when a component is focused
55
64
const focusedToggle = isFocused ( ) === 'focused' ? true : false ;
65
+
66
+ const handleEdit = ( ) => {
67
+ if ( editMode !== id ) {
68
+ handleChangeName ( title ) ;
69
+ toggleEditMode ( { id } ) ;
70
+ } else {
71
+ toggleEditMode ( { id : - 1 } ) ;
72
+ }
73
+ } ;
56
74
return (
57
75
< Grid
58
76
container
59
- direction = ' row'
60
- justify = ' center'
61
- alignItems = ' center'
77
+ direction = " row"
78
+ justify = " center"
79
+ alignItems = " center"
62
80
style = { {
63
- minWidth : '470px'
81
+ minWidth : '470px' ,
64
82
} }
65
83
>
66
84
< Grid item xs = { 9 } >
@@ -71,7 +89,7 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
71
89
focusedToggle
72
90
? {
73
91
boxShadow : '4px 4px 4px rgba(0, 0, 0, .4)' ,
74
- borderRadius : '8px'
92
+ borderRadius : '8px' ,
75
93
}
76
94
: { }
77
95
}
@@ -93,48 +111,86 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
93
111
backgroundColor : 'none' ,
94
112
borderRadius : '10px' ,
95
113
minWidth : '340px' ,
96
- border : `2px solid ${ color } `
114
+ border : `2px solid ${ color } ` ,
97
115
} }
98
116
>
99
- < List style = { { color : 'red' } } >
117
+ < List
118
+ style = {
119
+ {
120
+ // color: 'red'
121
+ }
122
+ }
123
+ >
100
124
< ListItem
101
125
// button // commented out to disable materialUI hover shading effect. TBD if any adverse effects occur
102
- style = { { color : 'red' } }
126
+ // style={{ color: 'red' }}
103
127
onClick = { ( ) => {
104
- changeFocusComponent ( { title } ) ;
128
+ if ( focusComponent . title !== title )
129
+ changeFocusComponent ( { title } ) ;
105
130
} }
106
131
>
107
132
< ListItemText
108
- disableTypography
109
- className = { classes . light }
133
+ // disableTypography
134
+ // className={classes.light}
110
135
primary = {
111
136
< div >
112
- < Typography
113
- //type='body2'
114
- style = { {
115
- color : '#fff' ,
116
- textShadow : '1px 1px 2px rgba(0, 0, 0, 0.7)' ,
117
- fontSize : '1.40rem'
118
- } }
119
- >
120
- { title }
121
- </ Typography >
137
+ { editMode !== id ? (
138
+ < Typography
139
+ //type='body2'
140
+ onDoubleClick = { ( ) => handleEdit ( ) }
141
+ style = { {
142
+ color : '#fff' ,
143
+ textShadow : '1px 1px 2px rgba(0, 0, 0, 0.7)' ,
144
+ fontSize : '1.40rem' ,
145
+ } }
146
+ >
147
+ { title }
148
+ </ Typography >
149
+ ) : (
150
+ < TextField
151
+ id = "filled"
152
+ label = "Change Component Name"
153
+ defaultValue = { title }
154
+ variant = "outlined"
155
+ className = { classes . text }
156
+ InputProps = { {
157
+ className : classes . light ,
158
+ } }
159
+ InputLabelProps = { {
160
+ className : classes . inputLabel ,
161
+ } }
162
+ autoFocus
163
+ onChange = { e => handleChangeName ( e . target . value ) }
164
+ onKeyPress = { ev => {
165
+ if ( ev . key === 'Enter' ) {
166
+ handleEditComponent ( ) ;
167
+ ev . preventDefault ( ) ;
168
+ }
169
+ } }
170
+ onKeyUp = { ev => {
171
+ if ( ev . keyCode === 27 ) {
172
+ handleEdit ( ) ;
173
+ ev . preventDefault ( ) ;
174
+ }
175
+ } }
176
+ />
177
+ ) }
122
178
{ /* ALL OF THE STATE/CLASS TOGGLES AND LABELS ARE ONLY RENDERED IF THEIR COMPONENT IS THE FOCUSED COMPONENT
123
179
TO DO : IMPROVE DRYNESS OF CODE BY RENDERING ALL FOUR MATERIAL ELEMENTS (LABELS/SWITCH) IN ONE CONDITIONAL
124
180
*/ }
125
181
{ /* LABEL AND TOGGLE(SWITCH) FOR STATEFULNESS */ }
126
182
{ focusedToggle ? (
127
183
< span style = { { display : 'inline-flex' } } >
128
184
< InputLabel
129
- htmlFor = ' stateful'
185
+ htmlFor = " stateful"
130
186
style = { {
131
187
color : '#fff' ,
132
188
marginBottom : '0px' ,
133
189
marginTop : '10px' ,
134
190
marginLeft : '11px' ,
135
191
padding : '0px' ,
136
192
fontSize : '18px' ,
137
- textShadow : '1px 1px 2px rgba(0, 0, 0, 0.7)'
193
+ textShadow : '1px 1px 2px rgba(0, 0, 0, 0.7)' ,
138
194
} }
139
195
>
140
196
State?
@@ -145,20 +201,20 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
145
201
toggleComponentState ( { id } ) ;
146
202
changeFocusComponent ( { title } ) ;
147
203
} }
148
- value = ' stateful'
149
- color = ' primary'
204
+ value = " stateful"
205
+ color = " primary"
150
206
// id={props.id.toString()}
151
207
/>
152
208
< InputLabel
153
- htmlFor = ' classBased'
209
+ htmlFor = " classBased"
154
210
style = { {
155
211
color : '#fff' ,
156
212
marginBottom : '0px' ,
157
213
marginTop : '10px' ,
158
214
marginLeft : '11px' ,
159
215
padding : '0px' ,
160
216
fontSize : '18px' ,
161
- textShadow : '1px 1px 2px rgba(0, 0, 0, 0.7)'
217
+ textShadow : '1px 1px 2px rgba(0, 0, 0, 0.7)' ,
162
218
} }
163
219
>
164
220
Class?
@@ -169,44 +225,44 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
169
225
toggleComponentClass ( { id } ) ;
170
226
changeFocusComponent ( { title } ) ;
171
227
} }
172
- value = ' classBased'
173
- color = ' primary'
228
+ value = " classBased"
229
+ color = " primary"
174
230
/>
175
231
</ span >
176
232
) : (
177
233
''
178
234
) }
179
235
{ focusedToggle && component . id !== 1 ? (
180
236
< Button
181
- variant = ' text'
182
- size = ' small'
183
- color = ' default'
184
- aria-label = ' Delete'
237
+ variant = " text"
238
+ size = " small"
239
+ color = " default"
240
+ aria-label = " Delete"
185
241
className = { classes . margin }
186
242
onClick = { ( ) =>
187
243
deleteComponent ( {
188
244
componentId : id ,
189
- stateComponents : components
245
+ stateComponents : components ,
190
246
} )
191
247
}
192
248
style = { {
193
249
color : 'white' ,
194
250
marginBottom : '0px' ,
195
- marginTop : '4px'
251
+ marginTop : '4px' ,
196
252
} }
197
253
>
198
254
< DeleteIcon
199
255
style = { {
200
256
color : '#b30000' ,
201
- textShadow : '1px 1px 2px rgba(0, 0, 0, 0.5)'
257
+ textShadow : '1px 1px 2px rgba(0, 0, 0, 0.5)' ,
202
258
} }
203
259
/>
204
260
< div
205
261
style = { {
206
262
marginTop : '4px' ,
207
263
marginLeft : '5px' ,
208
264
fontSize : '15px' ,
209
- textShadow : '1px 1px 2px rgba(0, 0, 0, 0.8)'
265
+ textShadow : '1px 1px 2px rgba(0, 0, 0, 0.8)' ,
210
266
} }
211
267
>
212
268
Delete Component
@@ -230,12 +286,12 @@ const LeftColExpansionPanel = (props: LeftColExpPanPropsInt) => {
230
286
< div />
231
287
) : (
232
288
< Tooltip
233
- title = ' add as child'
234
- aria-label = ' add as child'
235
- placement = ' left'
289
+ title = " add as child"
290
+ aria-label = " add as child"
291
+ placement = " left"
236
292
>
237
293
< IconButton
238
- aria-label = ' Add'
294
+ aria-label = " Add"
239
295
onClick = { ( ) => {
240
296
addChild ( { title, childType : 'COMP' } ) ;
241
297
} }
@@ -253,14 +309,28 @@ function styles(): object {
253
309
root : {
254
310
width : '100%' ,
255
311
marginTop : 10 ,
256
- backgroundColor : '#333333'
257
312
} ,
258
313
light : {
259
314
color : '#eee' ,
260
315
'&:hover' : {
261
- color : '#1de9b6'
262
- }
263
- }
316
+ color : '#1de9b6' ,
317
+ } ,
318
+ } ,
319
+ inputLabel : {
320
+ fontSize : '16px' ,
321
+ color : '#fff' ,
322
+ } ,
323
+ text : {
324
+ '& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline' : {
325
+ borderColor : 'white' ,
326
+ } ,
327
+ '&:hover .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline' : {
328
+ borderColor : 'white' ,
329
+ } ,
330
+ '& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline' : {
331
+ borderColor : 'white' ,
332
+ } ,
333
+ } ,
264
334
} ;
265
335
}
266
336
export default withStyles ( styles ) ( LeftColExpansionPanel ) ;
0 commit comments