Skip to content

Commit ed8c4b5

Browse files
Theme: apply theme styles in rating comp
1 parent b007b71 commit ed8c4b5

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import { trans } from "i18n";
1717

1818
import { useContext, useEffect, useRef } from "react";
1919
import { EditorContext } from "comps/editorState";
20+
import { CompTypeContext } from "../utils/compTypeContext";
21+
import { ThemeContext } from "../utils/themeContext";
22+
import { setInitialCompStyles } from "../utils/themeUtil";
23+
2024

2125
const EventOptions = [changeEvent] as const;
2226

@@ -43,20 +47,37 @@ const RatingBasicComp = (function () {
4347
allowHalf: BoolControl,
4448
disabled: BoolCodeControl,
4549
onEvent: eventHandlerControl(EventOptions),
46-
style: withDefault(styleControl(InputFieldStyle),{background:'transparent'}) ,
47-
animationStyle: styleControl(AnimationStyle),
50+
style: styleControl(InputFieldStyle, 'style') ,
51+
animationStyle: styleControl(AnimationStyle, 'animationStyle'),
4852
labelStyle: styleControl(
4953
LabelStyle.filter(
5054
(style) => ['accent', 'validate'].includes(style.name) === false
51-
)
55+
),
56+
'labelStyle',
5257
),
53-
inputFieldStyle: migrateOldData(styleControl(RatingStyle), fixOldData),
58+
inputFieldStyle: migrateOldData(styleControl(RatingStyle, 'inputFieldStyle'), fixOldData),
5459
...formDataChildren,
5560
};
56-
return new UICompBuilder(childrenMap, (props) => {
61+
return new UICompBuilder(childrenMap, (props, dispatch) => {
5762
const defaultValue = { ...props.defaultValue }.value;
5863
const value = { ...props.value }.value;
59-
const changeRef = useRef(false)
64+
const changeRef = useRef(false);
65+
const theme = useContext(ThemeContext);
66+
const compType = useContext(CompTypeContext);
67+
const compTheme = theme?.theme?.components?.[compType];
68+
69+
const styleProps: Record<string, any> = {};
70+
['style', 'animationStyle', 'labelStyle', 'inputFieldStyle'].forEach((key: string) => {
71+
styleProps[key] = (props as any)[key];
72+
});
73+
74+
useEffect(() => {
75+
setInitialCompStyles({
76+
dispatch,
77+
compTheme,
78+
styleProps,
79+
});
80+
}, []);
6081

6182
useEffect(() => {
6283
props.value.onChange(defaultValue);

client/packages/lowcoder/src/constants/themeConstants.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ const link = {
4242
}
4343
}
4444

45+
const rating = {
46+
style: {
47+
background: 'transparent',
48+
borderWidth: '0px',
49+
},
50+
labelStyle: {
51+
borderWidth: '0px',
52+
},
53+
inputFieldStyle: {
54+
borderWidth: '0px',
55+
}
56+
}
57+
4558
export const defaultTheme: ThemeDetail = {
4659
primary: "#3377FF",
4760
textDark: "#222222",
@@ -69,5 +82,6 @@ export const defaultTheme: ThemeDetail = {
6982
input,
7083
table,
7184
link,
85+
rating,
7286
},
7387
};

0 commit comments

Comments
 (0)