Skip to content

Commit d4d8158

Browse files
Theme: apply theme styles on link comp
1 parent 40c3074 commit d4d8158

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

client/packages/lowcoder/src/comps/comps/buttonComp/linkComp.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import { hasIcon } from "comps/utils";
2121
import { RefControl } from "comps/controls/refControl";
2222

2323
import { EditorContext } from "comps/editorState";
24-
import React, { useContext } from "react";
24+
import React, { useContext, useEffect } from "react";
25+
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
26+
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
27+
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
2528

2629
const Link = styled(Button)<{
2730
$style: LinkStyleType;
@@ -85,13 +88,30 @@ const LinkTmpComp = (function () {
8588
onEvent: ButtonEventHandlerControl,
8689
disabled: BoolCodeControl,
8790
loading: BoolCodeControl,
88-
style: migrateOldData(styleControl(LinkStyle), fixOldData),
89-
animationStyle:styleControl(AnimationStyle),
91+
style: migrateOldData(styleControl(LinkStyle, 'style'), fixOldData),
92+
animationStyle: styleControl(AnimationStyle, 'animationStyle'),
9093
prefixIcon: IconControl,
9194
suffixIcon: IconControl,
9295
viewRef: RefControl<HTMLElement>,
9396
};
94-
return new UICompBuilder(childrenMap, (props) => {
97+
return new UICompBuilder(childrenMap, (props, dispatch) => {
98+
const theme = useContext(ThemeContext);
99+
const compType = useContext(CompTypeContext);
100+
const compTheme = theme?.theme?.components?.[compType];
101+
102+
const styleProps: Record<string, any> = {};
103+
['style', 'animationStyle'].forEach((key: string) => {
104+
styleProps[key] = (props as any)[key];
105+
});
106+
107+
useEffect(() => {
108+
setInitialCompStyles({
109+
dispatch,
110+
compTheme,
111+
styleProps,
112+
});
113+
}, []);
114+
95115
// chrome86 bug: button children should not contain only empty span
96116
const hasChildren = hasIcon(props.prefixIcon) || !!props.text || hasIcon(props.suffixIcon);
97117
return (

client/packages/lowcoder/src/comps/controls/styleControl.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,10 @@ export function styleControl<T extends readonly SingleColorConfig[]>(
860860
const theme = useContext(ThemeContext);
861861
const bgColor = useContext(BackgroundColorContext);
862862
const compTheme = compType
863-
? theme?.theme?.components?.[compType]?.[styleKey]
863+
? {
864+
...(defaultTheme.components?.[compType]?.[styleKey] || {}) as unknown as Record<string, string>,
865+
...(theme?.theme?.components?.[compType]?.[styleKey] || {}) as unknown as Record<string, string>
866+
}
864867
: undefined;
865868

866869
return calcColors(

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ const table = {
3535
}
3636
}
3737

38+
const link = {
39+
style: {
40+
borderWidth: '0px',
41+
background: 'transparent',
42+
}
43+
}
44+
3845
export const defaultTheme: ThemeDetail = {
3946
primary: "#3377FF",
4047
textDark: "#222222",
@@ -61,5 +68,6 @@ export const defaultTheme: ThemeDetail = {
6168
text,
6269
input,
6370
table,
71+
link,
6472
},
6573
};

0 commit comments

Comments
 (0)