Skip to content

Commit 3ed4344

Browse files
Macraheeliftikhar5
Mac
authored andcommitted
treeSelect Component
1 parent 1587f0b commit 3ed4344

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

client/packages/lowcoder/src/comps/comps/treeComp/treeComp.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import { SelectEventHandlerControl } from "comps/controls/eventHandlerControl";
3333
import { trans } from "i18n";
3434
import { useContext } from "react";
3535
import { EditorContext } from "comps/editorState";
36+
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
37+
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
38+
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
3639

3740
type TreeStyleType = StyleConfigType<typeof TreeStyle>;
3841

@@ -76,9 +79,9 @@ const childrenMap = {
7679
label: withDefault(LabelControl, { position: "column" }),
7780
// TODO: more event
7881
onEvent: SelectEventHandlerControl,
79-
style: styleControl(InputFieldStyle),
80-
labelStyle: styleControl(LabelStyle.filter((style) => ['accent', 'validate'].includes(style.name) === false)),
81-
inputFieldStyle:styleControl(TreeStyle)
82+
style: styleControl(InputFieldStyle , 'style'),
83+
labelStyle: styleControl(LabelStyle.filter((style) => ['accent', 'validate'].includes(style.name) === false), 'labelStyle'),
84+
inputFieldStyle:styleControl(TreeStyle, 'inputFieldStyle')
8285
};
8386

8487
const TreeCompView = (props: RecordConstructorToView<typeof childrenMap>) => {
@@ -150,7 +153,27 @@ const TreeCompView = (props: RecordConstructorToView<typeof childrenMap>) => {
150153
};
151154

152155
let TreeBasicComp = (function () {
153-
return new UICompBuilder(childrenMap, (props) => <TreeCompView {...props} />)
156+
return new UICompBuilder(childrenMap, (props , dispatch) => {
157+
158+
const theme = useContext(ThemeContext);
159+
const compType = useContext(CompTypeContext);
160+
const compTheme = theme?.theme?.components?.[compType];
161+
const styleProps: Record<string, any> = {};
162+
['style', 'labelStyle', 'inputFieldStyle'].forEach((key: string) => {
163+
styleProps[key] = (props as any)[key];
164+
});
165+
166+
useEffect(() => {
167+
setInitialCompStyles({
168+
dispatch,
169+
compTheme,
170+
styleProps,
171+
});
172+
}, []);
173+
174+
175+
return(<TreeCompView {...props} />)}
176+
)
154177
.setPropertyViewFn((children) => (
155178
<>
156179
<Section name={sectionNames.basic}>

client/packages/lowcoder/src/comps/comps/treeComp/treeSelectComp.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ import { BaseSelectRef } from "rc-select";
3636
import { RefControl } from "comps/controls/refControl";
3737
import { useContext } from "react";
3838
import { EditorContext } from "comps/editorState";
39+
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
40+
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
41+
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
3942

4043
const StyledTreeSelect = styled(TreeSelect)<{ $style: TreeSelectStyleType }>`
4144
width: 100%;
@@ -65,9 +68,9 @@ const childrenMap = {
6568
allowClear: BoolControl,
6669
showSearch: BoolControl.DEFAULT_TRUE,
6770
inputValue: stateComp<string>(""), // search value
68-
style:styleControl(InputFieldStyle),
69-
labelStyle:styleControl(LabelStyle),
70-
inputFieldStyle: withDefault(styleControl(TreeSelectStyle), {borderWidth: '1px'}),
71+
style:styleControl(InputFieldStyle , 'style'),
72+
labelStyle:styleControl(LabelStyle , 'labelStyle'),
73+
inputFieldStyle: styleControl(TreeSelectStyle, 'inputFieldStyle'),
7174
viewRef: RefControl<BaseSelectRef>,
7275
};
7376

@@ -145,9 +148,27 @@ const TreeCompView = (
145148
};
146149

147150
let TreeBasicComp = (function () {
148-
return new UICompBuilder(childrenMap, (props, dispatch) => (
151+
return new UICompBuilder(childrenMap, (props, dispatch) => {
152+
153+
const theme = useContext(ThemeContext);
154+
const compType = useContext(CompTypeContext);
155+
console.log("compType", compType)
156+
const compTheme = theme?.theme?.components?.[compType];
157+
const styleProps: Record<string, any> = {};
158+
['style', 'labelStyle', 'inputFieldStyle'].forEach((key: string) => {
159+
styleProps[key] = (props as any)[key];
160+
});
161+
162+
useEffect(() => {
163+
setInitialCompStyles({
164+
dispatch,
165+
compTheme,
166+
styleProps,
167+
});
168+
}, []);
169+
return(
149170
<TreeCompView {...props} dispatch={dispatch} />
150-
))
171+
)})
151172
.setPropertyViewFn((children) => (
152173
<>
153174
<Section name={sectionNames.basic}>

0 commit comments

Comments
 (0)