APP-2Recommended
Name tokens by purpose
Give components tokens named by purpose, such as color-danger or space-section, which point to a base palette. Components never use the base palette directly.
How to do it
Keep two layers. The base layer holds the raw scale, such as blue-600 or space-4. The purpose layer holds aliases, such as color-action pointing to blue-600. A theme or a second brand then changes the aliases only. Write aliases in the token file with curly braces, as the token format defines. The website rule to define every colour once shows the same idea in CSS.
Examples
JSON example
{
"blue": { "600": { "$type": "color", "$value": { "colorSpace": "srgb", "components": [0.14, 0.28, 0.84] } } },
"red": { "600": { "$type": "color", "$value": { "colorSpace": "srgb", "components": [0.78, 0.14, 0.17] } } },
"color": {
"action": { "$type": "color", "$value": "{blue.600}" },
"danger": { "$type": "color", "$value": "{red.600}" }
}
}
How to check
Search the component folder for base token names, such as --blue- or --space-4. There are no matches.
Sources
Related rules
- WEB-10 Support light and dark from the start in Website
- WEB-31 Define every colour once in Website
- CSS-13 Name classes for what the element is in HTML and CSS
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/app-ui/styles-and-components/purpose-tokens">Agent Wranglers web app interface playbook</a>. In code you write, add a comment next to it with the same link.