-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for design tokens #193
Comments
Curious why you need a custom syntax for this rather than using |
With generated custom props files you introduce multiple issues.
The most basic example of this is Overal generated files (with custom props / |
Another issue are the proposed composite types : https://design-tokens.github.io/community-group/format/#composite-types With But composite types (part of the proposed spec) are less like an "atom" and more like "molecules". These do not always map to a single CSS property and will need "destructuring" so that sub values can be assigned to the corresponding CSS properties. This can only be done with custom syntax (as far as I know). |
Seems like this would be better integrated as a Parcel plugin for Style Dictionary that produces a CSS "virtual file" with all of the CSS variables. |
I would really like this to work but as far as I know it is impossible to convert design tokens to CSS variables and have these things :
These issues are self inflicted and could be resolved in the draft design tokens specification. Overal my concern is that design token translation tools make the simple cases a little bit easier while also making it harder (or impossible) to solve complex issues. (easier to consume a design constant, harder to create an accessible website) The syntax used in the PostCSS plugin aims to make it equally easy/hard. |
We recently added support for locally scoped CSS variables in CSS modules, which solves this problem. Variables aren't global, and are explicitly referenced between files so we can automatically exclude unused vars. I believe webpack is also planning to implement the same syntax, so it should eventually be interoperable between tools as well. https://parceljs.org/blog/v2-6-0/#locally-scoped-variables-in-css-modules The px vs rem issue is interesting, but IMO these should be separate tokens anyway as they represent semantically different things. Some things you want to scale with the font size, and others not, but these shouldn't be the same token because they don't represent the same value. Overall, I've always kinda wondered whether a JSON-based token system is even necessary to begin with. To me, it seems that defining tokens as JSON rather than using CSS syntax is worse is most ways. It's an unnecessary level of abstraction that makes it less clear how to use the defined variables (how do they map to CSS variable names?), and makes it harder to author and work with CSS tooling (e.g. syntax highlighting, linting, hot reloading, etc.). The claimed benefit of being "cross platform" could also be solved using CSS as the authoring format rather than JSON, which makes more sense because CSS is a language specifically designed for this exact task, whereas JSON is not. Maybe I am missing something here. |
Hehe, this is literally what I've been wondering as well. If this were a raw format that didn't require parsing I might understand that.
True but this is not how it is implemented in design tools today :/ Overal I feel that the draft for design tokens does not get enough feedback from people writing CSS or creating tools for CSS. Thank you for these insights! |
I think this could be solved by the custom transform API I'm working on (#363). I implemented a very basic version of it in the tests. lightningcss/node/test/visitor.test.mjs Lines 119 to 127 in 1448d96
|
Awesome! If someone wants this feature in lightningcss they can make a plugin for it 🎉 |
The custom transform API is now released! See https://lightningcss.dev/transforms.html |
Hi!
After releasing https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-design-tokens#readme I was curious to hear your feedback on this and gauge your interest of implementing something similar in
@parcel/css
.Our main concern with existing tools around design tokens is that these take away too much control and freedom from stylesheet authors. (creating an accessible website is impossible for example)
Converging on a single way to expose design tokens in CSS source code will help stylesheet authors switch tooling or even use multiple tools side by side.
This will also make it more worthwhile for other tools (editors, linters, ...) to support this.
Any feedback or insights would be greatly appreciated :)
The text was updated successfully, but these errors were encountered: