[RFC] Define a design token structure starting with colors #32013
Replies: 4 comments 9 replies
-
To reiterate what I shared when we last talked, for people reading this RFC:
Hard agree on the problem statement:
Desired token propertiesNow, to develop the right taxonomy, let's first align on desirable properties:
1. Support for light and dark modesThis is a must to match current features of the theming API v1. Adopting modes implies no side effects on tooling or code architecture. Modes can also easily be extracted from tokens to inject in the core stories and Chromatic, so they would be fully viewable and testable with the current tools. 2. Applying modes by region@shilman curious to see if you think there is user demand here, just for process's sake. Re: feasibility, injecting modes/themes anywhere in the app is trivial if we use CSS properties to deliver tokens. It's typically done by adding a CSS class to the element where you want to inject properties. As DOM is not modifiable by end users, we could allow 3. Degree of themeabilityI have no stake or comment on which theming option is right. I think this is a product/business question. I'm just providing implementation comments, and I must warn that switching between both will be prohibitively expensive, and so the choice is likely definitive. Light themingThe computing of a theme is easily done through Style Dictionary / Terrazzo, though this involves a pre-build step. It is also possible to build a CSS system that fully automates computations from a base value, especially with colour because we have CSS color functions. For spacing/typography sizes, we'd likely need a lot of Fully customisableThis can't be carried by semantic tokens alone, as there is no universal taxonomy for every brand ID out there. Try to implement Merck's brand identity on a Material app for instance. From experience, every taxonomy needs constraints to ensure different roles can be placed next to each other and be recognisable. Most orgs build a taxonomy that constrains around their product/UI needs and their brand identity. To do full white-label, we need escape hatches, aka component tokens. They allow reworking a component that won't behave as expected. The direct implications are more tokens to maintain, and more well thought-out theming APIs for each component.
Size mode automationAdobe does something interesting with its size tokens though: they have very few base values and then get transformed based on components' size prop. Combined with mise en mode, we could end up with something simple. Reusing the corner radius example from Garth's video: Input code: <Button size="small">Accept this RFC</Button> .button {
border-radius: var(--border-radius-default);
} Generated code: :root {
/* For tiny components e.g. checkbox */
--border-radius-small: 4px;
/* For 95% of components */
--border-radius-default: 6px;
}
.size-small {
--border-radius-small: 3px;
--border-radius-default: 4px;
}
.size-large {
--border-radius-small: 5px;
--border-radius-default: 8px;
}
// etc Output: // 4px radius
<button class="button size-small">Accept this RFC</button> We can automate/simplify even further by computing the small/large values of a token from a base modifier to the extent where these size modifiers just scale a component up and down. We mostly use sizes to make the UI more dense, so let's apply this just to spacings, as scaling down typography would ruin our UI. (I believe this is what they're doing in Spectrum 2 based on https://spectrum.adobe.com/page/platform-scale/, I can ask around if you want confirmation) Input code: <Button density="dense">Accept this RFC</Button> .button {
border-radius: var(--border-radius-default);
} Generated code: :root {
--spacing-base: 1;
--border-radius-default: calc(--spacing-base * 6px, 6px);
}
.density-dense {
--spacing-base: .8;
}
.density-airy {
--spacing-base: 1.15;
}
// etc Output: // 4.8px radius; paddings also scaled down by 80% but not font
<button class="button density-dense">Accept this RFC</button> Color mode automationAstro Starlight successfully exposes hues for major colours like success, warning, note. They don't even do semantic tokens but we could do that just for more clarity for end users. We could add the main brand and an accent colour and it would cover the needs for light theming, and it would allow a first layer of easy customisation if we go the full theming route. Taxonomy structureI'd love to do a quick audit of product/UX concepts we need, and of the interaction patterns used to convey something is clickable, focusable, currently selected, etc. So we know what vocabulary we want for semantic tokens. I'd definitely keep the structure identical within a type of token though, to allow for adding values without name conflicts. It's also useful to separate types of information in separate bits of a token's name:
|
Beta Was this translation helpful? Give feedback.
-
To add to the resources list, more cool Adobe stuff: |
Beta Was this translation helpful? Give feedback.
-
The proposed structure is JSON/JS object, that looks like format from the Design Tokens Community Group (@Sidnioulz can you help me out here, what is the actual name of the format? I can't find it anywhere)
It looks like Brad+Ian Frost's Design Tokens Course answers a lot of my questions above, so it might make sense to invest time for one of us to actually go through the course and see what they recommend. I explored the idea of the format instead just being hand-authored CSS Custom Properties, but I'm not sure if that is too error prone on a larger scale, and I'm not sure how to do that when considering Tier 2 and 3 also: :root {
--sb-color-white-0: hsl(bla, bla bla);
--sb-color-white-1: hsl(bla, bla bla);
--sb-color-white-2: hsl(bla, bla bla);
--sb-color-white-3: hsl(bla, bla bla);
--sb-color-neutral-0: hsl(bla, bla bla);
--sb-color-neutral-1: hsl(bla, bla bla);
--sb-color-neutral-2: hsl(bla, bla bla);
--sb-color-neutral-3: hsl(bla, bla bla);
} |
Beta Was this translation helpful? Give feedback.
-
Hey all! Great conversation, and apologies for being late to the party. I'm happy our course has helped address some of the questions, and happy to weigh in in more detail. Here are a few thoughts:
If there's other things I can be helpful with, just let me know! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I propose we take a pass at coming up with a defined token structure that will be used as a basis for eventual design token implementations. This will help organize our design tokens, make them predictable, reduce the need for one-off implementations, and afford flexibility for user-defined tokens and themes.
In the near-term, I want to agree on a structure to start implementing updates to color schemes for Storybook 10. Long term, this will help us plan for, and eventually implement, design tokens.
Problem Statement
There are a range of problems with our current theme and color implementation:
Non-goals
Implementation
This is a WIP and I will do my best to keep the latest proposal updated here.
Here is roughly what I am picturing along with a few questions:
Prior Art
There is a ton of prior research and opinions on this stuff. Here are a few resources worth peeking at, many of which were recommended to me by @Sidnioulz :
I will add more to this list as this is a WIP.
Deliverables
We will document a defined token structure to eventually use. Likely, there will be spikes for implementation, but this RFC is primarily to get us aligned.
Risks
Unresolved Questions
property.modifier.state
? Something else?Alternatives considered / Abandoned Ideas
No response
Beta Was this translation helpful? Give feedback.
All reactions