forked from abner/for-legacy-web
Merge pull request #188 from brecert/theme_shop
This commit is contained in:
@@ -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"]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user