Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
fix: color mode warning fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Suraj authored and Suraj committed Jun 2, 2023
1 parent 7c644bb commit 9e4d60d
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions packages/react/src/StyledProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ const StyledContext = React.createContext<Config>(defaultContextData);
// config: Config;
// colorMode?: COLORMODES;
// };

const setCurrentColorModeForWeb = (currentColorMode: string) => {
if (Platform.OS === 'web' && currentColorMode) {
set(currentColorMode === 'dark' ? 'dark' : 'light');
}
};
export const StyledProvider: React.FC<{
config: Config;
colorMode?: COLORMODES;
Expand All @@ -48,6 +54,12 @@ export const StyledProvider: React.FC<{
}, [colorMode]);

React.useEffect(() => {
// Add gs class name
if (Platform.OS === 'web') {
document.documentElement.classList.add(`gs`);
}
setCurrentColorModeForWeb(currentColorMode);

onChange((currentColor: string) => {
// only for web
if (Platform.OS === 'web') {
Expand All @@ -59,29 +71,17 @@ export const StyledProvider: React.FC<{
document.documentElement.classList.add(`gs-${currentColor}`);
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
React.useEffect(() => {
if (currentColorMode) {
set(currentColorMode === 'dark' ? 'dark' : 'light');
}

if (Platform.OS === 'web') {
document.documentElement.classList.add(`gs-${get()}`);
}
}, [currentColorMode]);

React.useEffect(() => {
if (Platform.OS === 'web') {
document.documentElement.classList.add(`gs`);
}
}, []);
setCurrentColorModeForWeb(currentColorMode);
}, [currentColorMode]);

// Set colormode server side
// if (typeof window === 'undefined') {
if (Platform.OS === 'web' && currentColorMode) {
set(currentColorMode === 'dark' ? 'dark' : 'light');
if (typeof window === 'undefined') {
setCurrentColorModeForWeb(currentColorMode);
}
// }

let contextValue;
if (Platform.OS === 'web') {
Expand Down

0 comments on commit 9e4d60d

Please sign in to comment.