Skip to content

Commit 203525b

Browse files
jattasNIrajsite
andauthored
Clean up process to modify design tokens (#1183)
# Pull Request ## 🤨 Rationale This started as [a joke to modify some token values](https://60e89457a987cf003efc0a5b-fftmbqhrah.chromatic.com/?path=/story/tests-button--button-theme-matrix) but turned into refactoring how we source our design tokens when I wrapped my head around the problems with our current approach: 1. our documentation describes importing tokens from Adobe XD and using the Design System Provider but those processes no longer work 2. our Style Dictionary configuration and build scripts were in the `dist` directory when they should be source 3. the process to generate Style Dictionary output (the platform specific token files) was manual and the build output was checked into source The new approach is to remove DSP, make Style Dictionary JSON files in this repo our source of truth for design token values, and generate token output as part of the build. The changes I'm making here should make #1175 easier too. (The Figma plugin linked in that issue can output Style Dictionary JSON files). ## 👩‍💻 Implementation 1. Remove everything about storing tokens in XD and Design System Provider. The source of truth is now Style Dictionary JSON files. 2. Move Style Dictionary build configuration to the `source` directory. This required some changes to get lint to pass since some of these files weren't previously linted. (See comments in PR) 3. Generate Style Dictionary output as part of `npm run build` instead of checking it in to source 4. Update CONTRIBUTING docs to describe the current process 5. Pull token values for base tokens story from JS build output instead of JSON source. This changed the order of the tokens in the story. ## 🧪 Testing Made token changes and verified that the built components uptake them. ## ✅ Checklist <!--- Review the list and put an x in the boxes that apply or ~~strike through~~ around items that don't (along with an explanation). --> - [x] I have updated the project documentation to reflect my changes or determined no changes are needed. --------- Co-authored-by: rajsite <[email protected]>
1 parent 2a8092c commit 203525b

29 files changed

+230
-6706
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Storybook updates for design token build changes",
4+
"packageName": "@ni/nimble-components",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Refactor token build output. This removes some source files from the built package.",
4+
"packageName": "@ni/nimble-tokens",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/nimble-components/src/theme-provider/tests/color.stories.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Meta, StoryObj } from '@storybook/html';
22
import { html, repeat } from '@microsoft/fast-element';
3-
import nimbleColorsMapJson from '@ni/nimble-tokens/dist/styledictionary/properties/colors.json';
3+
import * as tokens from '@ni/nimble-tokens/dist/styledictionary/js/tokens';
44
import { createUserSelectedThemeStory } from '../../utilities/tests/storybook';
55
import { controlLabelFont, controlLabelFontColor } from '../design-tokens';
66

@@ -9,12 +9,13 @@ interface NimbleColor {
99
data: string;
1010
}
1111

12-
const nimbleBaseColors: NimbleColor[] = Object.entries(
13-
nimbleColorsMapJson.color
14-
).map(([key, valueObj]) => ({
15-
name: key,
16-
data: valueObj.value
17-
}));
12+
const colorRegExp = /^#([0-9a-zA-Z]{6})$/;
13+
const nimbleBaseColors: NimbleColor[] = Object.entries(tokens)
14+
.filter(([_key, value]) => colorRegExp.test(value))
15+
.map(([key, value]) => ({
16+
name: key,
17+
data: value
18+
}));
1819

1920
const styleMarkup = html`
2021
<style>

packages/nimble-tokens/.eslintignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
dist/*
2-
!dist/styledictionary
32
dist/styledictionary/*
4-
!dist/styledictionary/nimble-extensions.js

packages/nimble-tokens/.eslintrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ module.exports = {
55
],
66
overrides: [
77
{
8+
parserOptions: {
9+
ecmaVersion: '2020'
10+
},
811
files: [
9-
'dist/styledictionary/nimble-extensions.js'
12+
'source/styledictionary/*.js',
1013
],
1114
rules: {
1215
// Build scripts will not be in published package and are allowed to use devDependencies

packages/nimble-tokens/.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# remove the dsp assets as we don't currently
2-
# leverage the dsp component definitions
3-
/assets
4-
51
dist/icons/*
62
!dist/icons/svg
73

84
dist/fonts/scss
95

6+
dist/styledictionary
7+
108
NimbleTokens/bin
119
NimbleTokens/obj
1210
NimbleTokens/.vs

packages/nimble-tokens/CONTRIBUTING.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,11 @@
2020

2121
## Editing Tokens
2222

23-
New tokens are added to this package with the [Adobe XD Visual Studio extension](https://marketplace.visualstudio.com/items?itemName=Adobe.xd&ssr=false#overview).
23+
Tokens are generated using the [Style Dictionary](https://amzn.github.io/style-dictionary/#/) build system, which transforms platform-agnostic token definition files into platform-specific output. These JSON definition files are the source of truth for the colors, fonts, and component design tokens in this repository. To modify the generated tokens, complete these steps:
2424

25-
The source of truth for the colors, fonts, and component design tokens in this repository is an Adobe XD [Design Library file](https://xd.adobe.com/view/33ffad4a-eb2c-4241-b8c5-ebfff1faf6f6-66ac/) maintained by the Visual Design team.
26-
27-
For changes to any token values, work with the Visual Design team to update the library, and then perform the following steps:
28-
29-
1. Open the XD extension (invoke [Show All Commands](https://code.visualstudio.com/docs/getstarted/keybindings#_navigation) and execute command `XD: Toggle Adobe XD Panel`) and load the nimble-tokens-dsp package by selecting the `nimble-tokens` folder.
30-
2. Click the **DSP Setting** button (bottom left). If the button is not available, open the XD extension settings to confirm that the `XD: Global Editor` setting is **checked** for both user and workspace.
31-
3. Scroll to the bottom of the DSP Setting page and click the **Re-import** button to update the CC LIBRARY LINK.
32-
4. Save the settings change.
33-
5. Click the **Start Editing** button and then the **Stop Editing** button to trigger the StyleDictionary token build.
34-
6. Commit these changes to the repo.
35-
36-
For any token metadata changes (e.g. documentation, code snippets, etc.):
37-
38-
1. Follow step 1 above.
39-
2. Click the **Start Editing** button and make your changes.
40-
3. Click the **Stop Editing** button to trigger a token build.
41-
4. Commit these changes to the repo.
25+
1. Edit the JSON files in `source/styledictionary/properties`. Long term these tokens will be sourced from a Figma design spec but for now it's OK to make manual edits.
26+
2. Rebuild the generated token files by running the repository's build command, `npm run build`.
27+
3. Test your changes locally and create a PR using the normal process.
4228

4329
## Updating icons
4430

0 commit comments

Comments
 (0)