1
- import { CompAction , RecordConstructorToView , changeChildAction } from "lowcoder-core" ;
1
+ import { CompAction , RecordConstructorToComp , RecordConstructorToView , changeChildAction } from "lowcoder-core" ;
2
2
import { styleControl } from "comps/controls/styleControl" ;
3
3
import { AnimationStyle , AnimationStyleType , startButtonStyle , StartButtonStyleType , timerStyle , timerStyleType } from "comps/controls/styleControlConstants" ;
4
- import { UICompBuilder } from "comps/generators/uiCompBuilder" ;
4
+ import { NewChildren , UICompBuilder } from "comps/generators/uiCompBuilder" ;
5
5
import { NameConfig , NameConfigHidden , withExposingConfigs } from "comps/generators/withExposing" ;
6
6
import { Section , sectionNames } from "lowcoder-design" ;
7
7
import { hiddenPropertyView , showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils" ;
@@ -15,6 +15,7 @@ import { EditorContext } from "comps/editorState";
15
15
import { dropdownControl } from "../controls/dropdownControl" ;
16
16
import { stringExposingStateControl } from "comps/controls/codeStateControl" ;
17
17
import { BoolControl } from "comps/controls/boolControl" ;
18
+ import React from "react" ;
18
19
19
20
const Container = styled . div < {
20
21
$style : timerStyleType | undefined ;
@@ -113,7 +114,9 @@ const childrenMap = {
113
114
hideButton : BoolControl ,
114
115
} ;
115
116
116
- const AvatarGroupView = ( props : RecordConstructorToView < typeof childrenMap > & { dispatch : ( action : CompAction ) => void ; } ) => {
117
+ type ChildrenType = NewChildren < RecordConstructorToComp < typeof childrenMap > > ;
118
+
119
+ const TimerCompView = React . memo ( ( props : RecordConstructorToView < typeof childrenMap > & { dispatch : ( action : CompAction ) => void ; } ) => {
117
120
const [ startTime , setStartTime ] = useState ( 0 )
118
121
const [ timerState , setTimerState ] = useState ( 'stoped' )
119
122
const [ elapsedTime , setElapsedTime ] = useState ( 0 )
@@ -219,51 +222,57 @@ const AvatarGroupView = (props: RecordConstructorToView<typeof childrenMap> & {
219
222
</ ButtonWarrper >
220
223
</ Container >
221
224
) ;
222
- } ;
225
+ } ) ;
223
226
224
- let AvatarGroupBasicComp = ( function ( ) {
225
- return new UICompBuilder ( childrenMap , ( props , dispatch ) => < AvatarGroupView { ...props } dispatch = { dispatch } /> )
226
- . setPropertyViewFn ( ( children ) => (
227
- < >
228
- { [ "logic" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
229
- < >
230
- < Section name = { sectionNames . basic } >
231
- { children . timerType . propertyView ( {
232
- label : trans ( 'timer.timerType' )
233
- } ) }
234
- { children . defaultValue . propertyView ( {
235
- label : trans ( 'timer.defaultValue' )
236
- } ) }
237
- { children . hideButton . propertyView ( {
238
- label : trans ( 'timer.hideButton' )
239
- } ) }
240
- </ Section >
241
- < Section name = { sectionNames . interaction } >
242
- { children . onEvent . propertyView ( ) }
243
- { hiddenPropertyView ( children ) }
244
- { showDataLoadingIndicatorsPropertyView ( children ) }
245
- </ Section >
246
- </ >
247
- ) }
248
-
249
- { [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
250
- < >
251
- < Section name = { sectionNames . style } >
252
- { children . style . getPropertyView ( ) }
253
- </ Section >
254
- < Section name = { sectionNames . animationStyle } hasTooltip = { true } >
255
- { children . animationStyle . getPropertyView ( ) }
256
- </ Section >
257
- < Section name = { sectionNames . startButtonStyle } >
258
- { children . startButtonStyle . getPropertyView ( ) }
227
+ const TimerCompPropertyView = React . memo ( ( props : {
228
+ children : ChildrenType
229
+ } ) => {
230
+ return (
231
+ < >
232
+ { [ "logic" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
233
+ < >
234
+ < Section name = { sectionNames . basic } >
235
+ { props . children . timerType . propertyView ( {
236
+ label : trans ( 'timer.timerType' )
237
+ } ) }
238
+ { props . children . defaultValue . propertyView ( {
239
+ label : trans ( 'timer.defaultValue' )
240
+ } ) }
241
+ { props . children . hideButton . propertyView ( {
242
+ label : trans ( 'timer.hideButton' )
243
+ } ) }
259
244
</ Section >
260
- < Section name = { sectionNames . resetButtonStyle } >
261
- { children . resetButtonStyle . getPropertyView ( ) }
245
+ < Section name = { sectionNames . interaction } >
246
+ { props . children . onEvent . propertyView ( ) }
247
+ { hiddenPropertyView ( props . children ) }
248
+ { showDataLoadingIndicatorsPropertyView ( props . children ) }
262
249
</ Section >
263
- </ >
264
- ) }
265
- </ >
266
- ) )
250
+ </ >
251
+ ) }
252
+
253
+ { [ "layout" , "both" ] . includes ( useContext ( EditorContext ) . editorModeStatus ) && (
254
+ < >
255
+ < Section name = { sectionNames . style } >
256
+ { props . children . style . getPropertyView ( ) }
257
+ </ Section >
258
+ < Section name = { sectionNames . animationStyle } hasTooltip = { true } >
259
+ { props . children . animationStyle . getPropertyView ( ) }
260
+ </ Section >
261
+ < Section name = { sectionNames . startButtonStyle } >
262
+ { props . children . startButtonStyle . getPropertyView ( ) }
263
+ </ Section >
264
+ < Section name = { sectionNames . resetButtonStyle } >
265
+ { props . children . resetButtonStyle . getPropertyView ( ) }
266
+ </ Section >
267
+ </ >
268
+ ) }
269
+ </ >
270
+ )
271
+ } ) ;
272
+
273
+ let TimerCompBasic = ( function ( ) {
274
+ return new UICompBuilder ( childrenMap , ( props , dispatch ) => < TimerCompView { ...props } dispatch = { dispatch } /> )
275
+ . setPropertyViewFn ( ( children ) => < TimerCompPropertyView children = { children } /> )
267
276
. setExposeMethodConfigs ( [
268
277
{
269
278
method : {
@@ -294,7 +303,7 @@ let AvatarGroupBasicComp = (function () {
294
303
. build ( ) ;
295
304
} ) ( ) ;
296
305
297
- export const TimerComp = withExposingConfigs ( AvatarGroupBasicComp , [
306
+ export const TimerComp = withExposingConfigs ( TimerCompBasic , [
298
307
new NameConfig ( "defaultValue" , trans ( "timer.defaultValue" ) ) ,
299
308
new NameConfig ( "elapsedTime" , trans ( "timer.elapsedTime" ) ) ,
300
309
new NameConfig ( "timerState" , trans ( "timer.timerState" ) ) ,
0 commit comments