包页面→ /design/tokens.md
pages/design/tokens.md
53 行, 3.3 KB. 以页面形式查看.
这段内容尚未翻译,下面是英文原文。
- ---
- type: Page
- title: "Design tokens"
- description: "The project's design tokens in the W3C Design Tokens (DTCG) format: where they live, how to build CSS variables, norms."
- icon: "🎨"
- source: design/tokens.json
- dark: design/tokens.dark.json
- out: design/tokens.css
- prefix: ""
- darkSelector: .dark
- ---
- # Design tokens
- A token is a named design value: a color, a size, a font, a shadow. Tokens live in one JSON file in the [W3C Design Tokens Community Group](https://www.designtokens.org/tr/2025.10/format/) (DTCG) format. Figma (through plugins), Style Dictionary, Tokens Studio and other tools read this format, so the file is a common language of design and code.
- ## What is where
- - [tokens.json](tokens.json): the tokens. An example: colors, spacing, radii, font, motion, shadow, border, text style.
- - [tokens.dark.json](tokens.dark.json): the dark scheme: the same tokens with other values. Optional.
- - [tokens.css](tokens.css): CSS variables built from the tokens. Not edited by hand.
- ## How the file is arranged (briefly)
- - A group is an object without `$value`; a token is an object with `$value`.
- - `$type` is the type of the value: `color`, `dimension`, `fontFamily`, `fontWeight`, `duration`, `cubicBezier`, `number`, `strokeStyle`, `border`, `transition`, `shadow`, `gradient`, `typography`. A type can be set on a group; all tokens inside inherit it.
- - A reference is `"{color.neutral.900}"`: the value is taken from another token. A reference can also stand inside a composite value (`"color": "{color.muted}"` in a border).
- - A color is an object `{colorSpace, components, alpha, hex}` or a hex string; a size is `{value, unit: px|rem}`.
- - A name cannot contain `{`, `}` or a dot; a name does not start with `$`.
- ## Build into CSS
- `shtuk run design-tokens build` writes `out` (by default `design/tokens.css`): each token becomes a variable `--<path-joined-by-hyphens>` in `:root`; a reference becomes `var(--…)`; a text style is split into `--text-body-font-size` and its neighbors; the dark scheme is a `.dark` block (the `darkSelector` field). The build runs by itself after the package is installed and updated.
- ## Settings
- - `source` is the tokens file; `dark` is the dark scheme file (empty means none).
- - `out` is where to build the CSS; `prefix` is a prefix for variable names (`ds-` → `--ds-color-primary`).
- - `darkSelector` is the selector of the dark scheme.
- ## Styles and the contract
- A style package keeps its own tokens in `/design/<style>/` and builds them with `shtuk run design-tokens build --style <style>`. What names a style defines is fixed by [the token contract](contract.md); the project's choice is on [Design](design.md). The check `contract` judges the chosen style, or any CSS file: `shtuk run design-tokens contract --css <file>`.
- ## Norms
- | Norm | What | Check |
- |---|---|---|
- | [DTK-R01](/norms/rules/design-tokens/DTK-R01.md) | Tokens are valid by the DTCG format, references lead to tokens of the right type | `valid` |
- | [DTK-R02](/norms/rules/design-tokens/DTK-R02.md) | CSS from tokens is rebuilt | `fresh` |
- | [DTK-R03](/norms/rules/design-tokens/DTK-R03.md) | The chosen style meets [the token contract](/design/contract.md) | `contract` |
- Boundary: "modes" and the resolver for token sets (a DTCG draft) are not read by the package; the dark scheme is a separate file. References in the form `$ref` (JSON Pointer) are not supported, only `{a.b}`.