@@ -17,6 +17,10 @@ import { EditorContext } from "comps/editorState";
17
17
import { getDataSourceStructures } from "redux/selectors/datasourceSelectors" ;
18
18
import { DatasourceStructure } from "api/datasourceApi" ;
19
19
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" ;
20
24
21
25
export const ForceViewModeContext = React . createContext < boolean > ( false ) ;
22
26
@@ -162,3 +166,29 @@ export function useMetaData(datasourceId: string) {
162
166
[ datasourceStructure , datasourceId ]
163
167
) ;
164
168
}
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