Skip to content

Commit

Permalink
fix(ThemeProvider): fix custom themes
Browse files Browse the repository at this point in the history
  • Loading branch information
LexSwed committed Oct 4, 2020
1 parent 39aa4dd commit 67775fa
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/lib/ThemeProvider/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
theme?: ThemeName | Swatch;
};

const themeContext = createContext('blue');
const themeContext = createContext<string | null>(null);

const styles = {
display: 'contents',
Expand All @@ -24,20 +24,24 @@ const ThemeProvider: React.FC<Props> = ({ theme, children }) => {
return css.theme(theme as Swatch);
}

return themes[(theme as ThemeName) || (contextTheme as ThemeName)];
}, [contextTheme, theme]);
return themes[theme as ThemeName];
}, [theme]);

if (!themeClass) {
const className = themeClass || contextTheme;

if (!className) {
return <>{children}</>;
}

return (
<themeContext.Provider value={themeClass}>
<Box className={themeClass} css={styles} as="span">
<themeContext.Provider value={className}>
<Box className={className} css={styles} as="span">
{children}
</Box>
</themeContext.Provider>
);
};

export default ThemeProvider;

export const useTheme = () => useContext(themeContext);

1 comment on commit 67775fa

@vercel
Copy link

@vercel vercel bot commented on 67775fa Oct 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.