-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add CSS variable transformer for sd #58
Conversation
Hey @douglaszaltron, I somehow figured this would be part of a It has the benefit of flexibility but would need to be applied in correct order. Also did you test it with nested tokens. We must make sure to avoid issues where the referenced token is already transformed to a css value (this could be done using the Somehow it feels more fitting for me to have this done in the formatter, I guess in this function. But I am open to being convinced that transformers are better. |
At first, I thought about creating it as a formater, but as a transformer, I can apply the value modification for both JavaScript/* and JSON/*. It would extend more easily. I did realize about the correct order, that the value mutations need to be done beforehand.
|
src/transformer/variables-css.ts
Outdated
transformer: (token: StyleDictionary.TransformedToken, options: StyleDictionary.Options) => { | ||
const cssVarPrefix = getCssVarPrefix(options); | ||
const varPrefix = cssVarPrefix ? `${cssVarPrefix}-` : '' | ||
return `var(--${varPrefix}${token.name})` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's better to add the value as fallback.
var(--${varPrefix}${token.name}, token.value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this can be an option? e.g. valueFallback
?
@lukasoppermann I made the adjustments, take a look. |
Looks great, I'll have to test it and will merge it afterwards. |
Hey @douglaszaltron, sorry, I just noted that I completely misread this PR. So what this does is it replaces the value of a token with it's own name as a css variable. E.g. So do you want to target the reference or are you really looking for replacing a variables value with it's own name. |
#56