Ability to create global theme with media queries #1119
Replies: 2 comments 2 replies
-
Okay, with a bit of digging, it turns out I can use globalStyle(':root', {
'@media': {
'(prefers-color-scheme: light)': {
vars: assignVars(ContextualColors, lightThemeColors)
},
'(prefers-color-scheme: dark)': {
vars: assignVars(ContextualColors, darkThemeColors)
},
},
}); From the documentation it wasn't immediately obvious that assignVars can also be used with a globalThemeContract. Makes sense, but getting to this point was a bit of maze. This is the best way to go about it right? |
Beta Was this translation helpful? Give feedback.
-
I’m having the same problem, and I think that a simpler way to solve it for modern browsers is to use the new const colors = createGlobalTheme(':root', {
page: {
a: 'light-dark(white, dark)'
},
neutral: {
a: 'light-dark(hsl(189 67% 6% / 0.8), hsl(45 100% 99% / 0.8)'
},
}); And then you simply set one of the following styles on the root: :root {
color-scheme: light dark; /* Respect user preference */
color-scheme: light; /* Force light theme */
color-scheme: dark; /* Force dark theme */
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm enjoying VanillaExtract a lot, but have run into a bit of a roadblock.
Context
:root
element.createGlobalThemeContract
API. This allows me to have a nice typesafe object to refer to theme variables.createGlobalTheme
API, attaching them to their:root
selectors.Problem
I need to extend this with the ability to start with a sensible default based on the
@media (prefers-color-scheme: dark)
media query. ThecreateGlobalTheme
API only supports a string selector.Any way I can do this? The following is an example code snippet which illustrates the issue.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions