@@ -829,6 +829,48 @@ const ResetIcon = styled(IconReset)`
829
829
}
830
830
` ;
831
831
832
+ const useThemeStyles = (
833
+ styleKey : string ,
834
+ props : Record < string , string | undefined > ,
835
+ ) => {
836
+ const editorState = useContext ( EditorContext ) ;
837
+ const { comp, compType} = useContext ( CompContext ) ;
838
+ const theme = useContext ( ThemeContext ) ;
839
+ const bgColor = useContext ( BackgroundColorContext ) ;
840
+ const { themeId } = theme || { } ;
841
+ const isPreviewTheme = themeId === 'preview-theme' ;
842
+ const isDefaultTheme = themeId === 'default-theme-id' ;
843
+
844
+ const appSettingsComp = editorState ?. getAppSettingsComp ( ) ;
845
+ const preventAppStylesOverwriting = appSettingsComp ?. getView ( ) ?. preventAppStylesOverwriting ;
846
+ const { appliedThemeId, preventStyleOverwriting } = ( comp ?. comp || { } ) ;
847
+ const appTheme = isPreviewTheme || isDefaultTheme || ( ! preventStyleOverwriting && ! preventAppStylesOverwriting )
848
+ ? theme ?. theme
849
+ : defaultTheme ;
850
+ let compTheme : JSONValue | undefined = { } ;
851
+ if ( appliedThemeId !== themeId ) {
852
+ compTheme = isPreviewTheme || isDefaultTheme || ( compType && ! preventStyleOverwriting && ! preventAppStylesOverwriting )
853
+ ? {
854
+ ...( omit ( defaultTheme , 'components' , 'chart' ) ) ,
855
+ ...defaultTheme . components ?. [ compType ] ?. [ styleKey ] as unknown as Record < string , string > ,
856
+ ...( omit ( theme ?. theme , 'components' , 'chart' ) ) ,
857
+ ...theme ?. theme ?. components ?. [ compType ] ?. [ styleKey ] as unknown as Record < string , string > ,
858
+ }
859
+ : defaultTheme . components ?. [ compType ] ?. [ styleKey ] ;
860
+ }
861
+ const styleProps = ( ! comp && ! compType ) || preventStyleOverwriting || preventAppStylesOverwriting || appliedThemeId === themeId
862
+ ? props
863
+ : { } ;
864
+
865
+ return {
866
+ appTheme,
867
+ styleProps,
868
+ bgColor,
869
+ compTheme,
870
+ compType,
871
+ }
872
+ } ;
873
+
832
874
export function styleControl < T extends readonly SingleColorConfig [ ] > (
833
875
colorConfigs : T ,
834
876
styleKey : string = '' ,
@@ -888,39 +930,16 @@ export function styleControl<T extends readonly SingleColorConfig[]>(
888
930
return new ControlItemCompBuilder (
889
931
childrenMap as ToConstructor < { [ K in Names < T > ] : ColorControl } > ,
890
932
( props ) => {
891
- // const compType = useContext(CompTypeContext);
892
- const editorState = useContext ( EditorContext ) ;
893
- const { comp, compType} = useContext ( CompContext ) ;
894
- const theme = useContext ( ThemeContext ) ;
895
- const bgColor = useContext ( BackgroundColorContext ) ;
896
- const { themeId } = theme || { } ;
897
- const isPreviewTheme = themeId === 'preview-theme' ;
898
- const isDefaultTheme = themeId === 'default-theme-id' ;
899
-
900
-
901
- const appSettingsComp = editorState ?. getAppSettingsComp ( ) ;
902
- const preventAppStylesOverwriting = appSettingsComp ?. getView ( ) ?. preventAppStylesOverwriting ;
903
- const { appliedThemeId, preventStyleOverwriting } = ( comp ?. comp || { } ) ;
904
- const appTheme = isPreviewTheme || isDefaultTheme || ( ! preventStyleOverwriting && ! preventAppStylesOverwriting )
905
- ? theme ?. theme
906
- : defaultTheme ;
907
- let compTheme : JSONValue | undefined = { } ;
908
- if ( appliedThemeId !== themeId ) {
909
- compTheme = isPreviewTheme || isDefaultTheme || ( compType && ! preventStyleOverwriting && ! preventAppStylesOverwriting )
910
- ? {
911
- ...( omit ( defaultTheme , 'components' , 'chart' ) ) ,
912
- ...defaultTheme . components ?. [ compType ] ?. [ styleKey ] as unknown as Record < string , string > ,
913
- ...( omit ( theme ?. theme , 'components' , 'chart' ) ) ,
914
- ...theme ?. theme ?. components ?. [ compType ] ?. [ styleKey ] as unknown as Record < string , string > ,
915
- }
916
- : defaultTheme . components ?. [ compType ] ?. [ styleKey ] ;
917
- }
918
- const styleProps = ( ! comp && ! compType ) || preventStyleOverwriting || preventAppStylesOverwriting || appliedThemeId === themeId
919
- ? props as ColorMap
920
- : { } as ColorMap ;
933
+ const {
934
+ styleProps,
935
+ appTheme,
936
+ bgColor,
937
+ compTheme,
938
+ compType,
939
+ } = useThemeStyles ( styleKey , props as Record < string , string > ) ;
921
940
922
941
return calcColors (
923
- styleProps ,
942
+ styleProps as ColorMap ,
924
943
colorConfigs ,
925
944
appTheme ,
926
945
bgColor ,
@@ -932,21 +951,26 @@ export function styleControl<T extends readonly SingleColorConfig[]>(
932
951
)
933
952
. setControlItemData ( { filterText : label , searchChild : true } )
934
953
. setPropertyViewFn ( ( children ) => {
935
- const theme = useContext ( ThemeContext ) ;
936
- const compType = useContext ( CompTypeContext ) ;
937
- const bgColor = useContext ( BackgroundColorContext ) ;
938
954
const isMobile = useIsMobile ( ) ;
939
- const compTheme = compType
940
- ? theme ?. theme ?. components ?. [ compType ] ?. [ styleKey ]
941
- : undefined ;
955
+ const childrenProps = childrenToProps ( children ) as Record < string , string > ;
956
+ const {
957
+ styleProps,
958
+ appTheme,
959
+ bgColor,
960
+ compTheme,
961
+ compType,
962
+ } = useThemeStyles ( styleKey , childrenProps ) ;
942
963
943
964
const props = calcColors (
944
- childrenToProps ( children ) as ColorMap ,
965
+ styleProps as ColorMap ,
945
966
colorConfigs ,
946
- theme ?. theme ,
967
+ appTheme ,
947
968
bgColor ,
948
969
compTheme as Record < string , string > | undefined ,
970
+ compType ,
971
+ styleKey ,
949
972
) ;
973
+
950
974
const showReset = Object . values ( childrenToProps ( children ) ) . findIndex ( ( item ) => item ) > - 1 ;
951
975
return (
952
976
< >
0 commit comments