New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
USWDS - JSON Tokens: Color MVP #5898
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation notes:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom color map template
Modified version of map-deep.template provided by style-dictionary.
Numbers keys will be output without quotes and paired with their value.
Strings values with a nested maps will be output with quotes and their nested maps will be evaluated.
@@ -52,6 +52,7 @@ | |||
}, | |||
"scripts": { | |||
"build": "gulp", | |||
"format-tokens": "node style-dictionary/color.config.js && npx prettier --write 'packages/uswds-core/src/styles/tokens/color/*.scss'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
The new format-tokens
script runs the color config JS file and then runs prettier on the output files to clean up some minor code styles for consistency. The changes from prettier are very minor and prevents linting errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
This file exports a map of all the color tokens to be used in color.config.js
. It filters any files that are not .json
and then slices the file type from the name.
filter: { | ||
attributes: { | ||
category: colorToken | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
This filter makes it so each output scss file only contains the relevant color token and not a map of all the tokens combined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
Existing token structure is not needed for style-dictionary implementation. I decided to start barebones and we can add additional properties as the need for them arises.
Summary
MVP to use style-dictionary to convert JSON color tokens to scss. The existing JSON files have been simplified and the output scss maps match the existing counterparts to prevent styles from breaking.
Breaking change
This is not a breaking change.
Related issue
Related to #5506
Closes #5844
Related pull requests
Preview link
Preview link →
Major changes
style-dictionary
andlodash
dependenciescolor.config.js
format-tokens
scriptTesting and review
Note
This work exclusively covers color tokens and the style-dictionary configuration will likely change to accommodate future tokens
Dependency updates
lodash
style-dictionary