1
- import _ from "lodash" ;
2
- import { useEffect , useState } from "react" ;
1
+ import { useEffect , useMemo , useState } from "react" ;
3
2
import { ConfigItem , Radius , Margin , Padding , GridColumns , BorderWidth , BorderStyle } from "../pages/setting/theme/styledComponents" ;
4
3
import { isValidColor , toHex } from "components/colorSelect/colorUtils" ;
5
4
import { ColorSelect } from "components/colorSelect" ;
@@ -28,6 +27,7 @@ import {
28
27
RotationIcon ,
29
28
} from "lowcoder-design/src/icons" ;
30
29
import { trans } from "i18n" ;
30
+ import { debounce } from "lodash" ;
31
31
32
32
export type configChangeParams = {
33
33
themeSettingKey : string ;
@@ -112,28 +112,22 @@ type CompStyleProps = {
112
112
113
113
export default function ThemeSettingsCompStyles ( props : CompStyleProps ) {
114
114
const { defaultStyle, styleOptions, configChange } = props ;
115
- const [ compStyle , setCompStyle ] = useState ( defaultStyle )
116
-
117
- console . log ( 'defaultStyle' , defaultStyle ) ;
115
+ const [ compStyle , setCompStyle ] = useState ( { ...defaultStyle } ) ;
118
116
119
- const handleChange = ( styleKey : string , styleValue : string ) => {
120
- setCompStyle ( ( style ) => {
121
- const updateStyles = {
122
- ...style ,
123
- [ styleKey ] : styleValue ,
124
- } ;
117
+ const updateThemeWithDebounce = useMemo ( ( ) => {
118
+ return debounce ( ( updateStyles ) => {
125
119
configChange ( updateStyles ) ;
126
- return updateStyles ;
127
- } ) ;
128
- }
129
-
130
- const configChangeWithDebounce = _ . debounce ( configChange , 0 ) ;
131
- const handleChangeWithDebounce = _ . debounce ( handleChange , 0 ) ;
132
-
133
- useEffect ( ( ) => {
134
- console . log ( compStyle ) ;
135
- } , [ compStyle ] ) ;
120
+ } , 500 ) ;
121
+ } , [ configChange ] ) ;
136
122
123
+ const handleChange = ( styleKey : string , styleValue : string ) => {
124
+ const updateStyles = {
125
+ ...compStyle ,
126
+ [ styleKey ] : styleValue ,
127
+ } ;
128
+ setCompStyle ( updateStyles ) ;
129
+ updateThemeWithDebounce ( updateStyles ) ;
130
+ }
137
131
138
132
const getLabelByStyle = ( styleKey : string ) => {
139
133
let label = styleKey ;
@@ -189,79 +183,79 @@ export default function ThemeSettingsCompStyles(props: CompStyleProps) {
189
183
case 'radius' :
190
184
case 'cardRadius' :
191
185
case 'gap' : {
192
- placeholder = '' ;
186
+ placeholder = '2px ' ;
193
187
break ;
194
188
}
195
189
case 'borderWidth' : {
196
- placeholder = '' ;
190
+ placeholder = '1px ' ;
197
191
break ;
198
192
}
199
193
case 'borderStyle' : {
200
- placeholder = '' ;
194
+ placeholder = 'solid ' ;
201
195
break ;
202
196
}
203
197
case 'margin' : {
204
- placeholder = '' ;
198
+ placeholder = '3px ' ;
205
199
break ;
206
200
}
207
201
case 'padding' :
208
202
case 'containerHeaderPadding' :
209
203
case 'containerSiderPadding' :
210
204
case 'containerFooterPadding' :
211
205
case 'containerBodyPadding' : {
212
- placeholder = '' ;
206
+ placeholder = '3px ' ;
213
207
break ;
214
208
}
215
209
case 'opacity' : {
216
- placeholder = '' ;
210
+ placeholder = '1 ' ;
217
211
break ;
218
212
}
219
213
case 'boxShadowColor' : {
220
- placeholder = '' ;
214
+ placeholder = '#FFFFFF ' ;
221
215
break ;
222
216
}
223
217
case 'boxShadow' : {
224
- placeholder = '' ;
218
+ placeholder = '0px 0px 0px ' ;
225
219
break ;
226
220
}
227
221
case 'animationIterationCount' : {
228
- placeholder = '' ;
222
+ placeholder = '0 ' ;
229
223
break ;
230
224
}
231
225
case 'animation' : {
232
- placeholder = '' ;
226
+ placeholder = 'none ' ;
233
227
break ;
234
228
}
235
229
case 'animationDelay' : {
236
- placeholder = '' ;
230
+ placeholder = '0s ' ;
237
231
break ;
238
232
}
239
233
case 'animationDuration' : {
240
- placeholder = '' ;
234
+ placeholder = '0s ' ;
241
235
break ;
242
236
}
243
237
case 'textSize' : {
244
- placeholder = '' ;
238
+ placeholder = '14px ' ;
245
239
break ;
246
240
}
247
241
case 'textWeight' : {
248
- placeholder = '' ;
242
+ placeholder = 'normal ' ;
249
243
break ;
250
244
}
251
245
case 'fontFamily' : {
252
- placeholder = '' ;
246
+ placeholder = 'sans-serif ' ;
253
247
break ;
254
248
}
255
249
case 'textDecoration' : {
256
- placeholder = '' ;
250
+ placeholder = 'none ' ;
257
251
break ;
258
252
}
259
253
case 'textTransform' : {
260
- placeholder = '' ;
254
+ placeholder = 'none ' ;
261
255
break ;
262
256
}
263
257
case 'fontStyle' : {
264
- placeholder = '' ;
258
+ placeholder = 'normal ' ;
265
259
break ;
266
260
}
267
261
case 'backgroundImage' :
@@ -273,11 +267,11 @@ export default function ThemeSettingsCompStyles(props: CompStyleProps) {
273
267
case 'backgroundImageRepeat' :
274
268
case 'headerBackgroundImageRepeat' :
275
269
case 'footerBackgroundImageRepeat' : {
276
- placeholder = '' ;
270
+ placeholder = 'no-repeat ' ;
277
271
break ;
278
272
}
279
273
case 'rotation' : {
280
- placeholder = '' ;
274
+ placeholder = '0deg ' ;
281
275
break ;
282
276
}
283
277
}
@@ -392,13 +386,16 @@ export default function ThemeSettingsCompStyles(props: CompStyleProps) {
392
386
marginBottom : "16px" ,
393
387
} } >
394
388
{ styleOptions . map ( ( styleKey : string ) => (
395
- < ConfigItem style = { {
396
- flexDirection : "row" ,
397
- alignItems : "center" ,
398
- margin : "0" ,
399
- padding : "6px" ,
400
- borderBottom : "1px solid lightgray" ,
401
- } } >
389
+ < ConfigItem
390
+ key = { styleKey }
391
+ style = { {
392
+ flexDirection : "row" ,
393
+ alignItems : "center" ,
394
+ margin : "0" ,
395
+ padding : "6px" ,
396
+ borderBottom : "1px solid lightgray" ,
397
+ } }
398
+ >
402
399
< div className = "text-desc" style = { {
403
400
width : "100px" ,
404
401
minWidth : "auto" ,
@@ -415,14 +412,13 @@ export default function ThemeSettingsCompStyles(props: CompStyleProps) {
415
412
// leading: true,
416
413
// trailing: true,
417
414
// }) }
415
+ changeColor = { ( value ) => handleChange ( styleKey , value ) }
418
416
color = { compStyle [ styleKey ] ! }
419
417
trigger = "hover"
420
418
/>
421
419
< TacoInput
422
420
value = { compStyle [ styleKey ] }
423
- onChange = { ( e ) => {
424
- handleChangeWithDebounce ( styleKey , e . target . value ) ;
425
- } }
421
+ onChange = { ( e ) => handleChange ( styleKey , e . target . value ) }
426
422
// onChange={(e) => setColor(e.target.value)}
427
423
// onBlur={colorInputBlur}
428
424
// onKeyUp={(e) => e.nativeEvent.key === "Enter" && colorInputBlur()}
@@ -437,14 +433,8 @@ export default function ThemeSettingsCompStyles(props: CompStyleProps) {
437
433
{ /* </Radius> */ }
438
434
< TacoInput
439
435
placeholder = { getPlaceholderByStyle ( styleKey ) }
440
- value = { compStyle [ styleKey ] }
441
- onChange = { ( e ) => {
442
- handleChangeWithDebounce ( styleKey , e . target . value ) ;
443
- // setCompStyle((style) => ({
444
- // ...style,
445
- // [styleKey]: e.target.value,
446
- // }))
447
- } }
436
+ defaultValue = { compStyle [ styleKey ] }
437
+ onChange = { ( e ) => handleChange ( styleKey , e . target . value ) }
448
438
// onBlur={(e) => radiusInputBlur(e.target.value)}
449
439
// onKeyUp={(e) => e.nativeEvent.key === "Enter" && radiusInputBlur(e.currentTarget.value)}
450
440
/>
0 commit comments