amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.93k stars 557 forks source link

Is it possible to export only the tokens without value? #872

Closed thayna-oliveira closed 2 years ago

thayna-oliveira commented 2 years ago

Hello,

I have the following color.tokens.json:

{
  "color": {
    "vivid": {
      "700": {  "value": "#006963" },
      "600": {  "value": "#00a8a0" },
      ......
    },
    "accent": {
      "700": { "value": "#7f2d1c" },
      "600": { "value": "#cc492d" },
      ......
      }
    }
}

And I want a list of the names of the tokens, something like this:

{
  "colors": [
        "color-vivid-700",
        "color-vivid-600",
        ......
   ]
}

I want a list to create a type in the typescript, like this:

export type Colors =
  | 'color-vivid-700'
  | 'color-vivid-600'
  .....
 ';

Do you guys know if it is possible? Or even if it is possible to generate a type?

I need this type to ensure my component only accepts the available tokens in the design system.

dbanksdesign commented 2 years ago

There is not a built-in format to do this, but I created a quick example that I believe does what you are looking for: https://stackblitz.com/edit/node-sq2wvj?file=sd.config.js

This is a really good idea though to provide union types for each type of design token!

thayna-oliveira commented 2 years ago

This is exactly what I was looking for! I'll try it! thanks a lot, @dbanksdesign! 👏👏👏

adamdehaven commented 1 year ago

@dbanksdesign it seems like your example here has since been updated. Can you provide a code snippet?