Skip to content

Handle json sizing tokens and style dictionary transforms and output#2536

Draft
itsmedavep wants to merge 4 commits intomainfrom
dave_sd_handle_JSON_sizing_tokens
Draft

Handle json sizing tokens and style dictionary transforms and output#2536
itsmedavep wants to merge 4 commits intomainfrom
dave_sd_handle_JSON_sizing_tokens

Conversation

@itsmedavep
Copy link
Copy Markdown
Collaborator

This allow for us to export w3c design token group spec JSON from Figma.

The Figma limitation that necessitates the need for this is Figma variables when exported to JSON only have $type: number. Our scss uses lots of variables with units.

Added top leve intent detection per token file

File type creation now comes from source basename
sass -> filename.sass
css -> filement.css

mixed intent + non intent (in exported JSON) -> non intent creates filename.default.css to avoid overwrites

Made number rounding to the 4th decimal place universal because Figma variables have float noise so rounding removes that in the file output values

Introduced taxonomy in JSON (and Figma) of:
Top level intent based
-- sass
|_ Tokens intended for scss vars
|_ creates filename.scss
-- css
|_ Tokens intended for css custom props
|_ creates filename.css
-- unitless
|_ Routed through default css
|_ creates filename.css if no top level intent exists (preserves default behavior)
|_ creates filename.default.css when mixed top level intent and no intent exists

Within the intents second level taxonomy controls units:

  1. dimension-px
  2. dimension-rem
  3. dimension-em
  4. unitless

Refactored SD config to break it into seperation of concerns and make it more maintainable.

Additions

  • style-dictionary-utilities/
  • style-dictionary-utilities/color.js
  • style-dictionary-utilities/css-variables-no-space-commas.js
  • style-dictionary-utilities/file-discovery.js
  • style-dictionary-utilities/path-utils.js
  • style-dictionary-utilities/platforms.js
  • style-dictionary-utilities/sizing.js

Removals

Changes

  • style-dictionary.config.js

Testing

  1. Yarn tokens
  2. Yarn star
  3. Make sure everything looks the same/no regressions

Screenshots

Notes

Todos

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows the standards laid out in the CFPB development guidelines
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Visually tested in supported browsers and devices (see checklist below 👇)
  • Project documentation has been updated
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist

Browsers

  • Chrome on desktop
  • Firefox
  • Safari on macOS
  • Edge
  • Safari on iOS
  • Chrome on Android

Accessibility

  • Keyboard friendly
  • Screen reader friendly

Other

  • Is useable without CSS
  • Is useable without JS
  • Flexible from small to large screens
  • No linting errors or warnings
  • JavaScript tests are passing

Now sizing.json is exported from Figma

Since Figma export only has $type: number from w3c spec we have to do some SD transformation to handle things properly.

We mingle css custom props and scss vars in our sizing-variables.scss file with and without units.

To decouple that we need to treat it as two dimensions. unitIntent and emitIntent.

In Figma split variables into groups within the sizing variable collection of:

sass/unitless
sass/dimension-px
sass/dimension-em
css/unitless
css/dimension-px

We will use those buckets in the resulting JSON to have SD generate the appropriate thing.

Meaning we can build separate SD outputs per the above buckets

dimension-px uses size/px (built in SD transform)
dimension-em uses size/em (custom SD transform)
unitless uses no transform

Then generate separate scss and css files from those groups in the JSON. Then aggregate them via their own wrapper so consumers can still import easily.

Keeping all formula/aliases (eg font size adjust) in one hand rolled shim. Basically our existing sizing-vars.scss where we import the separated scss and css files.

We need to forward ./sizing-tokens because there are other consumers of sizing-vars.scss in the legacy components.

That gets us to Figma sizing JSON tokens transformed into scss and css files and then combined in sizing-vars.scss.

1 Figma export, 1 JSON token file. Slight changes to sizing vars/custom properties organization.
Moved to format then dimension naming convention structure in Figma export JSON

We now have this we key off in the JSON:

no group -> emits .css
no group and group format in same JSON -> emits css for no group and then corresponding format

If it is format/dimension then we append the appropriate unit to the given format
Moved the refactored SD utilities to style-dictionary/plugins to match project structure. Updated paths in SD config to import from new location.

Updated sizing.json to pick up --select-border-width-error: 2px and regened tokens.
@itsmedavep itsmedavep force-pushed the dave_sd_handle_JSON_sizing_tokens branch from 8134aa1 to 1f907f0 Compare March 2, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant