Global css vars #294
-
Hi Friends, Loving VE right now. Just been playing around with it over the weekend and considering a migration to it from css modules in our design system. One issue I am finding is that there is no way to create global css vars with a specific name. Suppose I am defining dark/light themes in an application using the following selector:
Currently we are using html[data-theme-mode="light"] {
--brand-blue-primary-base: #23618E
} Other applications are using these variables to drive specific styles that are unrelated to components in the design system. So in order for me to not break those styles, I want to be able to define global css vars in vanilla extract that are a custom name that doesnt get hashed. Is this possible? From what I can see |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Seems like you can use globalStyle(':root', {
vars: {
'--brand-blue-primary-base': '#23618E',
}
});
globalStyle('*', {
boxSizing: 'border-box',
}); For switching variables I'd suggest: globalStyle('html[data-theme-mode="light"]', {
vars: {
'--brand-blue-primary-base': 'blue',
}
}); |
Beta Was this translation helpful? Give feedback.
-
If you don't want hashed variables you could build your own abstraction to achieve this. All the |
Beta Was this translation helpful? Give feedback.
If you don't want hashed variables you could build your own abstraction to achieve this. All the
createVar
API does is return a hashed identifier, disabling hashing would make it completely pointless. The var isn't actually added to the CSS until you consuming it within a style.