2.3.0 • Published 11 months ago

style-dictionary-sets v2.3.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
11 months ago

npm version tests workflow

Style Dictionary Sets

This is a collection of transforms and formatters for adding support for sets to Style Dictionary.

Installation

for yarn:

yarn add style-dictionary-sets

for npm:

npm install style-dictionary-sets

Usage

attribute/sets transform

In the config.js bring in the transform, register it to Style Dictionary and add it to the transforms array.

const StyleDictionary = require("style-dictionary");
const AttributeSetsTransform = require("style-dictionary-sets").AttributeSetsTransform;

StyleDictionary.registerTransform(AttributeSetsTransform);

module.exports = {
  source: ["tokens/**/*.json"],
  platforms: {
    JSON: {
      buildPath: "dist/json/",
      transforms: ["attribute/sets"],
      files: ...
    },
  },
};

This will add the sets array property to the attributes object on DesignToken if a token path contains the keyword sets. The value added to the sets array is the subsequent string in the path object.

Examples

A source like this (tests/fixtures/basic.json):

{
  "component": {
    "size": {
      "sets": {
        "mobile": {
          "value": "15px"
        },
        "desktop": {
          "value": "12px"
        }
      }
    }
  }
}

will transform the tokens to provide the following data to subsequent transforms and formatters:

{
  tokens: [
    {
      value: "15px",
      filePath: "tests/fixtures/basic.json",
      isSource: true,
      original: { value: "15px" },
      name: "component-size-sets-mobile",
      attributes: { sets: ["mobile"] },
      path: ["component", "size", "sets", "mobile"],
    },
    {
      value: "12px",
      filePath: "tests/fixtures/basic.json",
      isSource: true,
      original: { value: "12px" },
      name: "component-size-sets-desktop",
      attributes: { sets: ["desktop"] },
      path: ["component", "size", "sets", "desktop"],
    },
  ];
}

If you add multiple nested 'sets', it will add the subsequent strings in path order.

So this source data:

{
  "component": {
    "size": {
      "sets": {
        "subSystemOne": {
          "sets": {
            "mobile": {
              "value": "15px"
            },
            "desktop": {
              "value": "12px"
            }
          }
        },
        "subSystemTwo": {
          "sets": {
            "mobile": {
              "value": "16px"
            },
            "desktop": {
              "value": "13px"
            }
          }
        }
      }
    }
  }
}

will add transform the tokens to have the sets attribute like this:

{
  tokens: [
    {
      value: "15px",
      filePath: "tests/fixtures/nest-sets-no-refs.json",
      isSource: true,
      original: { value: "15px" },
      name: "component-size-sets-sub-system-one-sets-mobile",
      attributes: { sets: ["subSystemOne", "mobile"] },
      path: ["component", "size", "sets", "subSystemOne", "sets", "mobile"],
    },
    {
      value: "12px",
      filePath: "tests/fixtures/nest-sets-no-refs.json",
      isSource: true,
      original: { value: "12px" },
      name: "component-size-sets-sub-system-one-sets-desktop",
      attributes: { sets: ["subSystemOne", "desktop"] },
      path: ["component", "size", "sets", "subSystemOne", "sets", "desktop"],
    },
    {
      value: "16px",
      filePath: "tests/fixtures/nest-sets-no-refs.json",
      isSource: true,
      original: { value: "16px" },
      name: "component-size-sets-sub-system-two-sets-mobile",
      attributes: { sets: ["subSystemTwo", "mobile"] },
      path: ["component", "size", "sets", "subSystemTwo", "sets", "mobile"],
    },
    {
      value: "13px",
      filePath: "tests/fixtures/nest-sets-no-refs.json",
      isSource: true,
      original: { value: "13px" },
      name: "component-size-sets-sub-system-two-sets-desktop",
      attributes: { sets: ["subSystemTwo", "desktop"] },
      path: ["component", "size", "sets", "subSystemTwo", "sets", "desktop"],
    },
  ];
}

font/openType transform

This utility converts font-weight values from standard Open Type syntax into a CSS-safe format.

ValueCommon weight name
100Thin (Hairline)
200Extra Light (Ultra Light)
300Light
400Normal (Regular)
500Medium
600Semi Bold (Demi Bold)
700Bold
800Extra Bold (Ultra Bold)
900Black (Heavy)
950Extra Black (Ultra Black)

In the config.js bring in the transform, register it to Style Dictionary and add it to the transforms array.

const StyleDictionary = require("style-dictionary");
const CSSOpenTypeTransform = require("style-dictionary-sets").CSSOpenTypeTransform;

StyleDictionary.registerTransform(CSSOpenTypeTransform);

module.exports = {
  source: ["tokens/**/*.json"],
  platforms: {
    JSON: {
      buildPath: "dist/json/",
      transforms: [CSSOpenTypeTransform.name],
      files: ...
    },
  },
};

json/sets formatter

Some of this functionality is still being updated and refined for specific uses.

css/sets formatter

WIP

2.3.0

11 months ago

2.2.0

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.3

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.0.6

2 years ago

1.4.1

2 years ago

1.3.2

2 years ago

1.0.5

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.0.4

2 years ago

1.0.1

2 years ago