Skip to content
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

Question: Is there a way to transform alias into css variables without resolving the actual value? #396

Closed
davidx1 opened this issue Mar 6, 2020 · 7 comments

Comments

@davidx1
Copy link

davidx1 commented Mar 6, 2020

Is there a way to NOT resolve alias to values, but rather transform alias into css variable names?

For example, if I have defined in my properties like so:

//base.json
{
   "color": {
           "g500": { "value": "green" },
       }
    }
}

//other.json
{
   "color": {
           "success": { "value": {color.g500} },
       }
    }
}

Is there a way to generate:

:root {
  --g500: green;  
  --success: var(--g500);
}

EDIT:
The reason I ask is that we want to use StoryBooks' Design Token addon which uses css variable aliases to identify when two tokens are actually the same color and display them as such:

eg: here, both success and published are g500

image

@dbanksdesign
Copy link
Member

There is no way in the built-in transforms and formats, but you could write a custom one to do that (in kind of a hacky way). You could write a custom format that iterates over each token and does a check to see if token.original contains {} meaning it references another token. If it does, get the name of that token and put it in a var() instead of outputting the token's resolved value.

@chazzmoney
Copy link
Collaborator

If you build one, we would love a PR for a format that includes this!

@avkvirtru
Copy link

FYI, I've been tinkering with the solution to this started in #428

@GarthDB
Copy link

GarthDB commented Sep 10, 2020

This is how Adobe handles aliases (keeping them intact) in Spectrum CSS. I am building a new design system for a personal project and was looking for the same functionality in Style Dictionary. If there's anything I can do to help, let me know.

@avkvirtru
Copy link

@GarthDB I have a solution for this locally. Haven't had a chance to open a PR and contribute back here. Would be happy to coordinate on that. Can we start by seeing if my solution helps you: [email protected] ?

@tonyjwalt
Copy link
Contributor

tonyjwalt commented Sep 10, 2020 via email

@chazzmoney
Copy link
Collaborator

This is now possible via the merge of #504

Thanks @dbanksdesign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants