-
Notifications
You must be signed in to change notification settings - Fork 567
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
Strings get converted to unquoted strings in scss & css #462
Comments
Some tokens would get wrapped in quotes, depending on the type of token and the transforms applied to that token. In some cases unquoted would be expected, like if you define a color as a hex string. In CSS or SCSS variables you would not want that to be quoted. And your example of "uppercase" you would actually want that unquoted in CSS and SCSS as well or else it wouldn't work. There are some built-in transforms that quote certain types of tokens, such as the content/quote transform which wraps values in quotes if the token has a category of "content." The built-in transforms work by matching certain kinds of tokens based on the category/type/item of the token and transforming them appropriately. Not everyone uses the CTI method of defining what a type a token is, and you can define custom transforms that suite your needs. Hopefully this helps! Let me know if you have any questions. |
Hey @dbanksdesign sorry, that was a bad example indeed. But I understand the idea behind the CTI method but feel this is very limiting. Especially since it does not allow for token groups, e.g. Did you ever think about a |
For We didn't include a {
"color-background-primary": {
"value": "#fff",
"type": "color"
}
} And then use that const StyleDictionary = require('style-dictionary');
const chroma = require('chroma-js');
StyleDictionary.registerTransform({
name: 'customColorTransform'
type: 'value'
matcher: (token) => token.type === 'color', // here is where you can use 'type' or any data on the token
transformer: (token) => chroma(token.value).hsl()
}); The CTI structure categorizes tokens implicitly by object structure. So anything under the top-level namespace of "color" has the category of color, 2nd-level namespace of "background" has the type of background, etc. This CTI categorization happens in a built-in transform, the Our aim was to not prescribe any one singular way to structure and type tokens because everyone has different needs and opinions on how to do that. There are lots of people that don't use CTI and define their own way to type tokens. Does that make sense? |
CSS seemed to be an odd one for us because some strings cannot be wrapped in quotes, while it's required for others. On my team we thought this behavior was a format thing, so we built a solution into our custom formatter. You can see that in PR 428 in the formatter file on line 32. We applied a solution similar to what @dbanksdesign recommended, but used As @dbanksdesign said, there are several ways to solve it. I just thought I'd share what we did if it helps. |
Hey @tonyjwalt I think this is an interesting solution for me. @dbanksdesign to clarify where I am coming from. I am currently working on a figma design token export plugin. I would like to ideally export a json file that can be converted by style-dictionary without any additional magic from my side. CTI seems a bit limiting, as by default in Figma things like font styles include sizes, fonts and other things. If I understand you correct, I would have to include the "font-family" under the specific category Currently I have a json (before trying to transform it for style-dictionary) that looks like this: "body": {
"h3": {
"description": null,
"values": {
"fontSize": {
"value": 20,
"unit": "pixels"
},
"textDecoration": {
"value": "none"
},
"fontFamily": {
"value": "Roboto"
},
"fontStyle": {
"value": "Medium"
},
"letterSpacing": {
"value": 2,
"unit": "percent"
},
"lineHeight": {
"value": 160.0000023841858,
"unit": "percent"
},
"paragraphIndent": {
"value": 5,
"unit": "pixels"
},
"paragraphSpacing": {
"value": 8,
"unit": "pixels"
},
"textCase": {
"value": "uppercase"
}
}
} I think it would make sense to have this converted into tokens like: --font-body-h3-fontSize: 20px;
--font-body-h3-textDecoration: none;
--font-body-h3-fontFamily: "Roboto"; Does this make sense? Or am I missing something here? |
Hey,
I noticed that all strings end up being unquoted, for example:
Will show up in the css file as:
The text was updated successfully, but these errors were encountered: