Skip to content

Conversation

@itsmedavep
Copy link
Contributor

Opening a PR for design token work. We are exploring how feasible it would be to output design tokens from Figma using the free version of Token Studio in .json format and then subsequently ingesting the .json into the build process of the DS.

Additions

Adding in .json files. One file contains all of the CFPB color pallets. The second file contains the vars.scss variables in .json format

Changes

Eventually, will add style dictionary or similar translation tool into the project as a dep and hook it into the build process for the DS

Testing

Screenshots

Notes

This is a first step proof of concept for moving over to using platform agnostic tokens.

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

@netlify
Copy link

netlify bot commented Jul 15, 2025

Thanks for the improvements! Browse a preview of your changes using the link below.

Name Link
🔨 Latest commit 1fe51dd
🔍 Latest deploy log https://app.netlify.com/projects/cfpb-design-system/deploys/68a338e13b56d50008b52781
😎 Deploy Preview https://deploy-preview-2321--cfpb-design-system.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@anselmbradford anselmbradford marked this pull request as draft July 15, 2025 17:13
anselmbradford and others added 25 commits July 15, 2025 14:33
…sponding .json files contain also renaming json

Previously tokens was an object containing all tokens and when we iterated over it we didnt scope the output. We were still applying all tokens to every css output.

This change _should_ update that to generate one css file per json source, each file should be registered individually in the files array with the corresponding input file as a scoped source.

Also simplifying the example by removing some json files. Also this works hand in hand with some json file generation changes from Figma.
Trying new organization structure out of Figma
…ly in the style dictionary config

I also verified in this commit that having a directory under base with any tokens in it duplicates the structure in css. AKA I created a dir a json file under base/sizing to verify.
This required a refactor of cfpb-button.component.scss so that it includes reference to custom css properties and no longer uses the old component button.scss.

This may not be the best ending but it gets us pretty close to having the tokens hooked up.
Based on a review with Ans on Friday there were a few changes suggested.

Fixed up @use in the web component scss so that it uses all of abstracts again. (I initially thought that custom-props scss was still using $ variables. It wasnt)

Refactor button styles for cfpb-button to not be a mixin any longer.

Update index.js in cfpb-button to no longer include cfpb-color-palettes-default-tokens.css because we can just use custom-props from the standard components.

*todo*

Figure out if there is another way to include the btn-default-tokens.css. Right now I have included it in the index.js in order for the styles to be available to the shadow dom. Adding them into cfpb-button.scss with @use or @import is always leaving the css custom properties undefined.
This commit adds:

Json tokens saved out of Figma using my plugin: https://github.com/itsmedavep/figma-dtcg with Style Dictionary JSON (emit #RRGGBB color values) turned on in the export tab.

JSON tokens have been added to a "tokens" folder that the root of src.  Style dictionary then takes all of the json tokens and outputs them to .css which is then added into the web components respective folders (elements) as sidecar files and ultimately they are used in the web components themselves.

You can do that with this command:
yarn style-dictionary build --config ./style-dictionary.config.js

The config walks the tokens folder and then emits .css files into the elements dir mirroring the same structure as the tokens folder. Style dictionary has output references set to TRUE. Which means that we preserve the alias values instead of the resolved values foer the css (e.g. --block-border: var(--gray-40); vs --block-border: #b4b5b6;)

All css files are generated with :host vs :root

These changes are only for color. All of the sizing variables have been pulled out into a partials file _sizing-vars.scss.

Instead of pulling in everything from scr/abstracts I have opted to only use the mixins, media queries, and var-breakpoints since I have duplicated the custom-props and vars to be used with the web components. An eventual clean up TODO: would be to just bring all of src/abstracts over to src/elements/abstracts and then do a import clean up.
npm error Could not resolve dependency:
npm error peer react@"^16.8.0" from [email protected]
npm error node_modules/react-liquid
npm error   react-liquid@"2.0.1" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
Run yarn style-dictionary build --config ./style-dictionary.config.js
  yarn style-dictionary build --config ./style-dictionary.config.js
  shell: /usr/bin/bash -e {0}
Internal Error: cfpb-design-system@workspace:.: This package doesn't seem to be present in your lockfile; run "yarn install" to update the lockfile

Added yarn install step to GH action
Moving yarn install to right before trying to build tokens with style-dictionary
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.

2 participants