Closed kevinjn3640 closed 3 years ago
How to switch themes without browser reload using css variables
`
const themes = { light: { color: "green" }, dark: { color: "blue" } };
if (document.documentElement.hasAttribute("data-force-color-mode", "light")) { cssVars({ variables: themes.light, }); }
if (document.documentElement.hasAttribute("data-force-color-mode", "dark")) { cssVars({ variables: themes.dark, }); }`
Please help
@Kevinjn0123 --
You haven't specified how you want to trigger the theme switch. Here's a quick demo with one way to do it:
https://codesandbox.io/s/css-vars-ponyfill-157-jdng3
How to switch themes without browser reload using css variables
`
const themes = { light: { color: "green" }, dark: { color: "blue" } };
if (document.documentElement.hasAttribute("data-force-color-mode", "light")) { cssVars({ variables: themes.light, }); }
if (document.documentElement.hasAttribute("data-force-color-mode", "dark")) { cssVars({ variables: themes.dark, }); }`
Please help