I can't generate variables css to a specific class
See original GitHub issueHello!
We are use the Style Dictionary to generate our tokens, but we have a problem here.
The tokens are building to different products (themes) and we like use variables css, but in the generated files, we got:
// theme-x.css
:root {
// variables
}
// theme-y.css
:root {
// variables
}
How change the destiny of variables css to custom class, like a:
// theme-x.css
.theme-x {
// variables
}
// theme-y.css
.theme-y {
// variables
}
🍻
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:14 (4 by maintainers)
Top Results From Across the Web
How to use CSS variables like a pro - LogRocket Blog
To declare a variable in CSS, come up with a name for the variable, then append two hyphens (–) as the prefix. element...
Read more >Using CSS custom properties (variables) - MDN Web Docs
Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific ...
Read more >Overwriting css root variables by adding a class to element
So to fix the issue, you can add the class, you called it .night , to the root element itself. Here's a quick...
Read more >Everything you need to know about CSS Variables
I'll show how easy CSS variables make creating site-wide theme styles. ... Now when the .red class is used, the browser notes the...
Read more >A Complete Guide To CSS Variables [With Examples]
The CSS variables are case-sensitive. Therefore, the variables my_var and My_var are both different. CSS Variable Cannot Be A Property Name. The ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Unfortunately the built-in css/variables format does not allow this. But that would be a good addition! Here is the code: https://github.com/amzn/style-dictionary/blob/master/lib/common/formats.js#L106
You could write a custom format that does this too if you can’t wait for that change to be made into the core library:
Note: this is untested code, but should probably work and doesn’t include full working code. Also it won’t exactly match the functionality of ‘css/variables’ format, but if you want to you could copy the functions in https://github.com/amzn/style-dictionary/blob/main/lib/common/formats.js to make it work exactly the same.
Let me know if this helps!
Hi!
I think is worth pointing out that you can also use Custom format helpers. To make use of the functions already defined in the library without having to re-write the formatter, if you only need to change/add a selector/class!