Skip to content

Commit 01b256d

Browse files
Theme: created a hook to merge styles initially
1 parent 9fe2bbd commit 01b256d

File tree

1 file changed

+30
-0
lines changed
  • client/packages/lowcoder/src/util

1 file changed

+30
-0
lines changed

client/packages/lowcoder/src/util/hooks.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import { EditorContext } from "comps/editorState";
1717
import { getDataSourceStructures } from "redux/selectors/datasourceSelectors";
1818
import { DatasourceStructure } from "api/datasourceApi";
1919
import { loadAuthSearchParams } from "pages/userAuth/authUtils";
20+
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext";
21+
import { CompTypeContext } from "@lowcoder-ee/comps/utils/compTypeContext";
22+
import { setInitialCompStyles } from "@lowcoder-ee/comps/utils/themeUtil";
23+
import { CompAction, changeChildAction } from "lowcoder-core";
2024

2125
export const ForceViewModeContext = React.createContext<boolean>(false);
2226

@@ -162,3 +166,29 @@ export function useMetaData(datasourceId: string) {
162166
[datasourceStructure, datasourceId]
163167
);
164168
}
169+
170+
171+
export function useMergeCompStyles(
172+
props: Record<string, any>,
173+
dispatch: (action: CompAction) => void
174+
) {
175+
const theme = useContext(ThemeContext);
176+
const compType = useContext(CompTypeContext);
177+
const compTheme = theme?.theme?.components?.[compType];
178+
const themeId = theme?.themeId;
179+
180+
const styleKeys = Object.keys(props).filter(key => key.toLowerCase().endsWith('style'));
181+
const styleProps: Record<string, any> = {};
182+
styleKeys.forEach((key: string) => {
183+
styleProps[key] = (props as any)[key];
184+
});
185+
186+
useEffect(() => {
187+
setInitialCompStyles({
188+
dispatch,
189+
compTheme,
190+
styleProps,
191+
themeId,
192+
});
193+
}, []);
194+
}

0 commit comments

Comments
 (0)