GithubHelp home page GithubHelp logo

esthercheran / sux-style-dictionary Goto Github PK

View Code? Open in Web Editor NEW

This project forked from phantasmagoriadigital/sux-style-dictionary

1.0 0.0 0.0 120 KB

License: Apache License 2.0

Ruby 2.92% JavaScript 97.08%

sux-style-dictionary's Introduction

Substrate Design System โ€” Style Dictionary

Style Dictionary is a build tool to generate design tokens across platforms and for use in Figma.

These tokens are part of the Substrate Design System:

Automatically generate separate build files matching categories and components

This config of Style Dictionary generates a 1:1 relationship between build files and token categories.

The use cases:

  • Each token category as its own Sass partial (_colors.scss)
  • Separate component files (button.css, input.css, etc)
  • Tree shaking (only import what you need)

Running the example

First of all, set up the required dependencies running the command npm install in your local CLI environment.

At this point, you can run npm run build. This command will generate the output file in the build folder. Currently the build process exprects style dictionary to be in the same parent directory as the components repository where the stencil components live as they are exported to /components/src/assets/tokens directory.

Exporting for Figma tokens

npm run build-figma-tokens

After this, tokens will be available in the figma-tokens/figma-tokens.json file.

If you use jsonbin.io for your tokens, you can use this script to push tokens:

curl    --header "Content-Type: application/json" \
        --header "secret-key: [your-secret-key-here] " \
        --request PUT \
        --data-binary "@figma-tokens.json" \
        https://api.jsonbin.io/b/[your-bin-id-here]

How does it work

The "build" command processes the JSON files in the tokens folder. The index.js file adds each folder, allowing you to map through them in config.js. The script goes through each folder and generates a file for each folder and populates it with tokens that match the filter.

# tokens/color/base.json
{
   "color": {
       "red": {
            "value": "#FF0000"
        }
   }
}
# tokens/size/base.json
{
   "size": {
       "small": {
            "value": "2px"
        }
   }
}

Because the folder name matches the category, the output would automatically generate separate color and size files.

What to look at

Open the config.js file and see how the script first looks within the tokens directory to map through each folder. The destination then outputs a file that would match the name, and fill that file with the tokens that match the filter criteria.

 files: tokens.map(tokenCategory => ({
          destination: `${tokenCategory}.js`,
          format: "format/js",
          filter: {
            attributes: {
              category: tokenCategory
            }
          }
        }))

Now each new folder that gets added will automatically generate a corresponding file filled with tokens that match the category!

sux-style-dictionary's People

Contributors

phantasmagoriadigital avatar rahulthakur1007 avatar esthercheran avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.