@@ -34,7 +34,9 @@ const HTMLPanel = (props): JSX.Element => {
34
34
const [ alertOpen , setAlertOpen ] = React . useState < boolean > ( false ) ;
35
35
const state = useSelector ( ( store : RootState ) => store . appState ) ;
36
36
const roomCode = useSelector ( ( store : RootState ) => store . roomSlice . roomCode ) ;
37
- const currentID = useSelector ( ( store : RootState ) => store . appState . customElementId ) ;
37
+ const currentID = useSelector (
38
+ ( store : RootState ) => store . appState . customElementId
39
+ ) ;
38
40
39
41
const dispatch = useDispatch ( ) ;
40
42
@@ -54,8 +56,8 @@ const HTMLPanel = (props): JSX.Element => {
54
56
let dupe = false ;
55
57
checkList . forEach ( ( HTMLTag ) => {
56
58
if (
57
- HTMLTag . name . toLowerCase ( ) === inputName . toLowerCase ( )
58
- || HTMLTag . tag . toLowerCase ( ) === inputName . toLowerCase ( )
59
+ HTMLTag . name . toLowerCase ( ) === inputName . toLowerCase ( ) ||
60
+ HTMLTag . tag . toLowerCase ( ) === inputName . toLowerCase ( )
59
61
) {
60
62
dupe = true ;
61
63
}
@@ -65,19 +67,21 @@ const HTMLPanel = (props): JSX.Element => {
65
67
66
68
const triggerError = ( type : string ) => {
67
69
setErrorStatus ( true ) ;
68
- if ( type === 'empty' ) setErrorMsg ( '* Input cannot be blank. *' ) ;
69
- if ( type === 'dupe' ) setErrorMsg ( '* Input already exists. *' ) ;
70
- if ( type === 'letters' ) setErrorMsg ( '* Input must start with a letter. *' ) ;
71
- if ( type === 'symbolsDetected' ) setErrorMsg ( '* Input must not contain symbols. *' ) ;
72
- if ( type === 'length' ) setErrorMsg ( '* Input cannot exceed 10 characters. *' ) ;
70
+ if ( type === 'empty' ) setErrorMsg ( 'Input cannot be blank.' ) ;
71
+ if ( type === 'dupe' ) setErrorMsg ( 'Input already exists.' ) ;
72
+ if ( type === 'letters' ) setErrorMsg ( 'Input must start with a letter.' ) ;
73
+ if ( type === 'symbolsDetected' )
74
+ setErrorMsg ( 'Input must not contain symbols.' ) ;
75
+ if ( type === 'length' ) setErrorMsg ( 'Input cannot exceed 10 characters.' ) ;
73
76
} ;
74
77
75
78
const resetError = ( ) => setErrorStatus ( false ) ;
76
79
77
80
const createOption = ( inputTag : string , inputName : string ) => {
78
81
// format name so first letter is capitalized and there are no whitespaces
79
82
const inputNameClean = inputName . replace ( / \s + / g, '' ) ;
80
- const formattedName = inputNameClean . charAt ( 0 ) . toUpperCase ( ) + inputNameClean . slice ( 1 ) ;
83
+ const formattedName =
84
+ inputNameClean . charAt ( 0 ) . toUpperCase ( ) + inputNameClean . slice ( 1 ) ;
81
85
// add new component to state
82
86
const newElement = {
83
87
id : currentID ,
@@ -86,7 +90,7 @@ const HTMLPanel = (props): JSX.Element => {
86
90
style : { } ,
87
91
placeHolderShort : name ,
88
92
placeHolderLong : '' ,
89
- icon : null ,
93
+ icon : null
90
94
} ;
91
95
92
96
dispatch ( addElement ( newElement ) ) ;
@@ -108,16 +112,22 @@ const HTMLPanel = (props): JSX.Element => {
108
112
e . preventDefault ( ) ;
109
113
110
114
if ( tag . trim ( ) === '' || name . trim ( ) === '' ) return triggerError ( 'empty' ) ;
111
- if ( ! tag . charAt ( 0 ) . match ( / [ a - z A - Z ] / ) || ! name . charAt ( 0 ) . match ( / [ a - z A - Z ] / ) ) return triggerError ( 'letters' ) ;
112
- if ( ! alphanumeric ( tag ) || ! alphanumeric ( name ) ) return triggerError ( 'symbolsDetected' ) ;
115
+ if ( ! tag . charAt ( 0 ) . match ( / [ a - z A - Z ] / ) || ! name . charAt ( 0 ) . match ( / [ a - z A - Z ] / ) )
116
+ return triggerError ( 'letters' ) ;
117
+ if ( ! alphanumeric ( tag ) || ! alphanumeric ( name ) )
118
+ return triggerError ( 'symbolsDetected' ) ;
113
119
if ( checkNameDupe ( tag ) || checkNameDupe ( name ) ) return triggerError ( 'dupe' ) ;
114
120
if ( name . length > 10 ) return triggerError ( 'length' ) ;
115
121
createOption ( tag , name ) ;
116
122
resetError ( ) ;
117
123
} ;
118
124
119
125
const handleCreateElement = useCallback ( ( e ) => {
120
- if ( e . key === 'Enter' && e . target . tagName !== 'TEXTAREA' && e . target . id !== 'filled-hidden-label-small' ) {
126
+ if (
127
+ e . key === 'Enter' &&
128
+ e . target . tagName !== 'TEXTAREA' &&
129
+ e . target . id !== 'filled-hidden-label-small'
130
+ ) {
121
131
e . preventDefault ( ) ;
122
132
document . getElementById ( 'submitButton' ) . click ( ) ;
123
133
}
@@ -132,12 +142,18 @@ const HTMLPanel = (props): JSX.Element => {
132
142
133
143
const handleAlertOpen = ( ) => setAlertOpen ( true ) ;
134
144
135
- const handleAlertClose = ( event : React . SyntheticEvent | Event , reason ?: string ) => {
145
+ const handleAlertClose = (
146
+ event : React . SyntheticEvent | Event ,
147
+ reason ?: string
148
+ ) => {
136
149
if ( reason === 'clickaway' ) return ;
137
150
setAlertOpen ( false ) ;
138
151
} ;
139
152
140
- const Alert = React . forwardRef < HTMLDivElement , AlertProps > ( function Alert ( props , ref ) {
153
+ const Alert = React . forwardRef < HTMLDivElement , AlertProps > ( function Alert (
154
+ props ,
155
+ ref
156
+ ) {
141
157
return < MuiAlert elevation = { 6 } ref = { ref } variant = "filled" { ...props } /> ;
142
158
} ) ;
143
159
@@ -157,19 +173,22 @@ const HTMLPanel = (props): JSX.Element => {
157
173
autoComplete = "off"
158
174
placeholder = "Custom Element Name"
159
175
sx = { { width : '80%' } }
160
- // style={{ marginTop: '10px' }}
161
176
onChange = { handleNameChange }
162
177
/>
163
- { ( ! name . charAt ( 0 ) . match ( / [ A - Z a - z ] / )
164
- || ! alphanumeric ( name )
165
- || name . trim ( ) === ''
166
- || name . length > 10
167
- || checkNameDupe ( name ) ) && (
168
- < span className = { `${ classes . errorMessage } /* ${ classes . errorMessageDark } */` } >
178
+ { ( ! name . charAt ( 0 ) . match ( / [ A - Z a - z ] / ) ||
179
+ ! alphanumeric ( name ) ||
180
+ name . trim ( ) === '' ||
181
+ name . length > 10 ||
182
+ checkNameDupe ( name ) ) && (
183
+ < span
184
+ className = { `${ classes . errorMessage } /* ${ classes . errorMessageDark } */` }
185
+ >
169
186
< em > { errorMsg } </ em >
170
187
</ span >
171
188
) }
172
- < div style = { { display : 'flex' , alignItems : 'center' , width : '100%' } } >
189
+ < div
190
+ style = { { display : 'flex' , alignItems : 'center' , width : '100%' } }
191
+ >
173
192
< TextField
174
193
id = "outlined-basic"
175
194
label = "Custom Tag Name"
@@ -181,11 +200,13 @@ const HTMLPanel = (props): JSX.Element => {
181
200
sx = { { width : '80%' } }
182
201
onChange = { handleTagChange }
183
202
/>
184
- { ( ! tag . charAt ( 0 ) . match ( / [ A - Z a - z ] / )
185
- || ! alphanumeric ( tag )
186
- || tag . trim ( ) === ''
187
- || checkNameDupe ( tag ) ) && (
188
- < span className = { `${ classes . errorMessage } /* ${ classes . errorMessageDark } */` } >
203
+ { ( ! tag . charAt ( 0 ) . match ( / [ A - Z a - z ] / ) ||
204
+ ! alphanumeric ( tag ) ||
205
+ tag . trim ( ) === '' ||
206
+ checkNameDupe ( tag ) ) && (
207
+ < span
208
+ className = { `${ classes . errorMessage } /* ${ classes . errorMessageDark } */` }
209
+ >
189
210
< em > { errorMsg } </ em >
190
211
</ span >
191
212
) }
@@ -213,7 +234,11 @@ const HTMLPanel = (props): JSX.Element => {
213
234
anchorOrigin = { { vertical : 'top' , horizontal : 'center' } }
214
235
onClose = { handleAlertClose }
215
236
>
216
- < Alert onClose = { handleAlertClose } severity = "success" sx = { { width : '100%' , color : 'white' } } >
237
+ < Alert
238
+ onClose = { handleAlertClose }
239
+ severity = "success"
240
+ sx = { { width : '100%' , color : 'white' , backgroundColor : '#f88e16' } }
241
+ >
217
242
HTML Tag Created!
218
243
</ Alert >
219
244
</ Snackbar >
@@ -232,49 +257,49 @@ const useStyles = makeStyles({
232
257
backgroundColor : 'rgba(255,255,255,0.15)' ,
233
258
margin : '0px 0px 0px 10px' ,
234
259
width : '100%' ,
235
- height : '30px' ,
260
+ height : '30px'
236
261
} ,
237
262
inputWrapper : {
238
263
width : '100%' ,
239
- marginBottom : '0px ' , // was originally 10px, decreased to 0 to decrease overall menu height
240
- alignItems : 'center' ,
264
+ marginBottom : '10px ' , // was originally 10px, decreased to 0 to decrease overall menu height
265
+ alignItems : 'center'
241
266
} ,
242
267
addComponentWrapper : {
243
- width : '100%' ,
268
+ width : '100%'
244
269
} ,
245
270
input : {
246
271
width : '500px' ,
247
272
whiteSpace : 'nowrap' ,
248
273
overflowX : 'hidden' ,
249
274
textOverflow : 'ellipsis' ,
250
275
margin : '0px 0px 0px 0px' ,
251
- alignSelf : 'center' ,
276
+ alignSelf : 'center'
252
277
} ,
253
278
lightThemeFontColor : {
254
279
color : 'white' ,
255
280
'& .MuiInputBase-root' : {
256
- color : 'rgba (0, 0, 0, 0.54)' ,
257
- } ,
281
+ color : 'rgba (0, 0, 0, 0.54)'
282
+ }
258
283
} ,
259
284
darkThemeFontColor : {
260
285
color : '#ffffff' ,
261
286
'& .MuiInputBase-root' : {
262
- color : '#fff' ,
263
- } ,
287
+ color : '#fff'
288
+ }
264
289
} ,
265
290
errorMessage : {
266
291
display : 'flex' ,
267
292
alignSelf : 'center' ,
268
293
fontSize : '11px' ,
269
294
marginTop : '10px' ,
270
- width : '150px' ,
295
+ width : '150px'
271
296
} ,
272
297
errorMessageLight : {
273
- color : '#6B6B6B' ,
298
+ color : '#6B6B6B'
274
299
} ,
275
300
errorMessageDark : {
276
- color : 'white' ,
277
- } ,
301
+ color : 'white'
302
+ }
278
303
} ) ;
279
304
280
305
export default HTMLPanel ;
0 commit comments