Merge pull request #188 from brecert/theme_shop

This commit is contained in:
Paul Makles
2021-09-09 21:58:13 +01:00
committed by GitHub
8 changed files with 416 additions and 19 deletions

View File

@@ -278,14 +278,18 @@ export const PRESETS: Record<string, Theme> = {
const keys = Object.keys(PRESETS.dark);
const GlobalTheme = createGlobalStyle<{ theme: Theme }>`
:root {
${(props) =>
(Object.keys(props.theme) as Variables[]).map((key) => {
if (!keys.includes(key)) return;
return `--${key}: ${props.theme[key]};`;
})}
${(props) => generateVariables(props.theme)}
}
`;
export const generateVariables = (theme: Theme) => {
const mergedTheme = { ...PRESETS[theme.light ? 'light' : 'dark'], ...theme }
return (Object.keys(mergedTheme) as Variables[]).map((key) => {
if (!keys.includes(key)) return;
return `--${key}: ${mergedTheme[key]};`;
})
}
// Load the default default them and apply extras later
export const ThemeContext = createContext<Theme>(PRESETS["dark"]);