Design Tokens
Workflow
- Define globals (
tokens/global.json) — raw values, no semantics. - Create alias mappings (
tokens/alias.json) — semantic role → global ref. - Bind component tokens (
tokens/components/*.json) — component → alias ref. - Validate — lint names, check unused, verify no broken refs.
- Generate platform outputs via Style Dictionary (CSS, iOS, Android, JS).
Validate after each step before proceeding.
Source Token File (`tokens/global.json`)
{
"color": {
"blue": { "500": { "value": "#3b82f6", "type": "color" },
"600": { "value": "#2563eb", "type": "color" } },
"gray": { "100": { "value": "#f3f4f6", "type": "color" },
"900": { "value": "#111827", "type": "color" } }
},
"spacing": {
"1": { "value": "0.25rem", "type": "dimension" },
"2": { "value": "0.5rem", "type": "dimension" },
"4": { "value": "1rem", "type": "dimension" }
}
}
tokens/alias.json:
{
"color": {
"primary": { "value": "{color.blue.500}", "type": "color" },
"primary-hover": { "value": "{color.blue.600}", "type": "color" },
"surface": { "value": "{color.gray.100}", "type": "color" },
"on-surface": { "value": "{color.gray.900}", "type": "color" }
},
"spacing": {
"inset-x": { "value": "{spacing.4}", "type": "dimension" },
"inset-y": { "value": "{spacing.2}", "type": "dimension" }
}
}
Give every alias an explicit type. A reference does not inherit the type of
the token it points to, and type-filtered formats such as android/colors
silently drop untyped tokens.
tokens/components/button.json (step 3 — component tokens referencing alias tier):
{
"button": {
"bg": { "value": "{color.primary}", "type": "color" },
"bg-hover": { "value": "{color.primary-hover}", "type": "color" },
"bg-disabled": { "value": "{color.surface}", "type": "color" },
"text": { "value": "{color.on-surface}", "type": "color" },
"padding-x": { "value": "{spacing.inset-x}", "type": "dimension" },
"padding-y": { "value": "{spacing.inset-y}", "type": "dimension" }
}
}
Component tokens always reference alias names, never global names directly.
This applies to every category (spacing, radius, weight), not just color. The
only literals allowed are keywords such as transparent or none.
Style Dictionary Config (`style-dictionary.config.mjs`)
Targets Style Dictionary v4 (Node 18+) or v5 (Node 22+), both ESM with an async API. v3 used a different API
(require(...).extend(), synchronous builds); pin style-dictionary@^5 or
@^4 in package.json.
export default {
source: ["tokens/**/*.json"],
platforms: {
css: {
transformGroup: "css",
buildPath: "build/css/",
files: [{ destination: "tokens.css", format: "css/variables",
options: { outputReferences: true } }]
},
ios: {
transformGroup: "ios-swift",
buildPath: "build/ios/",
files: [{ destination: "Tokens.swift", format: "ios-swift/class.swift",
options: { className: "Tokens" } }]
},
android: {
transformGroup: "android",
buildPath: "build/android/",
files: [
{ destination: "colors.xml", format: "android/colors" },
{ destination: "dimens.xml", format: "android/dimens" }
]
},
js: {
transformGroup: "js",
buildPath: "build/js/",
files: [{ destination: "tokens.js", format: "javascript/es6" }]
}
}
};
Run: npx style-dictionary build --config style-dictionary.config.mjs
A build that exits 0 can still emit unusable output. Check that
build/ios/Tokens.swift declares public class Tokens and that
build/android/colors.xml contains the alias colors (color_primary, ...).
Validation Checkpoints
Run after each workflow step. Fail closed: any failure exits nonzero.
npm install --save-dev @babel/parser@^7 # parses JS/JSX/TS for the raw-hex check (Node 18+)
cp <skill>/assets/validate-tokens.mjs scripts/validate-tokens.mjs
node scripts/validate-tokens.mjs