1
- import { BoolCodeControl } from "comps/controls/codeControl" ;
1
+ import { BoolCodeControl , StringControl } from "comps/controls/codeControl" ;
2
2
import React , { ReactNode , useContext , useRef } from "react" ;
3
3
import { ExternalEditorContext } from "util/context/ExternalEditorContext" ;
4
4
import { Comp , CompParams , MultiBaseComp } from "lowcoder-core" ;
@@ -22,10 +22,14 @@ import {
22
22
MethodConfigsType ,
23
23
withMethodExposing ,
24
24
} from "./withMethodExposing" ;
25
+ import { Section } from "lowcoder-design" ;
26
+ import { trans } from "i18n" ;
25
27
26
28
export type NewChildren < ChildrenCompMap extends Record < string , Comp < unknown > > > =
27
29
ChildrenCompMap & {
28
30
hidden : InstanceType < typeof BoolCodeControl > ;
31
+ id : InstanceType < typeof StringControl > ;
32
+ className : InstanceType < typeof StringControl > ;
29
33
} ;
30
34
31
35
export function HidableView ( props : {
@@ -50,12 +54,46 @@ export function HidableView(props: {
50
54
}
51
55
}
52
56
57
+ export function ExtendedComponentView ( props : {
58
+ children : JSX . Element | React . ReactNode ;
59
+ id : string ;
60
+ className : string ;
61
+ } ) {
62
+ if ( ! props . id && ! props . className ) {
63
+ return < > { props . children } </ > ;
64
+ }
65
+
66
+ return (
67
+ < div id = { props . id } className = { props . className } >
68
+ { props . children }
69
+ </ div >
70
+ ) ;
71
+ }
72
+
73
+ export function ExtendedPropertyView <
74
+ ChildrenCompMap extends Record < string , Comp < unknown > > ,
75
+ > ( props : {
76
+ children : JSX . Element | React . ReactNode ,
77
+ childrenMap : NewChildren < ChildrenCompMap >
78
+ }
79
+ ) {
80
+ return (
81
+ < >
82
+ { props . children }
83
+ < Section name = { trans ( "prop.component" ) } >
84
+ { props . childrenMap . id ?. propertyView ( { label : trans ( "prop.id" ) } ) }
85
+ { props . childrenMap . className ?. propertyView ( { label : trans ( "prop.className" ) } ) }
86
+ </ Section >
87
+ </ >
88
+ ) ;
89
+ }
90
+
53
91
export function uiChildren <
54
92
ChildrenCompMap extends Record < string , Comp < unknown > > ,
55
93
> (
56
94
childrenMap : ToConstructor < ChildrenCompMap >
57
95
) : ToConstructor < NewChildren < ChildrenCompMap > > {
58
- return { ...childrenMap , hidden : BoolCodeControl } as any ;
96
+ return { ...childrenMap , hidden : BoolCodeControl , id : StringControl , className : StringControl } as any ;
59
97
}
60
98
61
99
type ViewReturn = ReactNode ;
@@ -89,10 +127,22 @@ export class UICompBuilder<
89
127
setPropertyViewFn (
90
128
propertyViewFn : PropertyViewFnTypeForComp < NewChildren < ChildrenCompMap > >
91
129
) {
92
- this . propertyViewFn = propertyViewFn ;
130
+ this . propertyViewFn = this . decoratePropertyViewFn ( propertyViewFn ) ;
93
131
return this ;
94
132
}
95
133
134
+ decoratePropertyViewFn (
135
+ propertyViewFn : PropertyViewFnTypeForComp < NewChildren < ChildrenCompMap > >
136
+ ) : PropertyViewFnTypeForComp < NewChildren < ChildrenCompMap > > {
137
+ return ( childrenMap , dispatch ) => {
138
+ return (
139
+ < ExtendedPropertyView childrenMap = { childrenMap } >
140
+ { propertyViewFn ( childrenMap , dispatch ) }
141
+ </ ExtendedPropertyView >
142
+ ) ;
143
+ } ;
144
+ }
145
+
96
146
setExposeStateConfigs (
97
147
configs : ExposingConfig < ChildrenToComp < ChildrenCompMap > > [ ]
98
148
) {
@@ -113,6 +163,12 @@ export class UICompBuilder<
113
163
if ( this . childrenMap . hasOwnProperty ( "hidden" ) ) {
114
164
throw new Error ( "already has hidden" ) ;
115
165
}
166
+ if ( this . childrenMap . hasOwnProperty ( "id" ) ) {
167
+ throw new Error ( "already has id" ) ;
168
+ }
169
+ if ( this . childrenMap . hasOwnProperty ( "className" ) ) {
170
+ throw new Error ( "already has className" ) ;
171
+ }
116
172
const newChildrenMap = uiChildren ( this . childrenMap ) ;
117
173
const builder = this ;
118
174
@@ -185,8 +241,10 @@ function UIView(props: { comp: any; viewFn: any }) {
185
241
//END ADD BY FRED
186
242
187
243
return (
188
- < HidableView hidden = { childrenProps . hidden as boolean } >
189
- { props . viewFn ( childrenProps , comp . dispatch ) }
190
- </ HidableView >
244
+ < ExtendedComponentView id = { childrenProps . id as string } className = { childrenProps . className as string } >
245
+ < HidableView hidden = { childrenProps . hidden as boolean } >
246
+ { props . viewFn ( childrenProps , comp . dispatch ) }
247
+ </ HidableView >
248
+ </ ExtendedComponentView >
191
249
) ;
192
250
}
0 commit comments