ShtukbaseStandard
页面/design/tokens.md

这段内容尚未翻译,下面是英文原文。

Design tokens

The project's design tokens in the W3C Design Tokens (DTCG) format: where they live, how to build CSS variables, norms.

页面字段(6)
icon🎨
sourcedesign/tokens.json
darkdesign/tokens.dark.json
outdesign/tokens.css
prefix
darkSelector.dark

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 (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: the tokens. An example: colors, spacing, radii, font, motion, shadow, border, text style.
  • tokens.dark.json: the dark scheme: the same tokens with other values. Optional.
  • 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; the project's choice is on Design. The check contract judges the chosen style, or any CSS file: shtuk run design-tokens contract --css <file>.

Norms

NormWhatCheck
DTK-R01Tokens are valid by the DTCG format, references lead to tokens of the right typevalid
DTK-R02CSS from tokens is rebuiltfresh
DTK-R03The chosen style meets the token contractcontract

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}.

包 Design tokens (W3C DTCG) 会把此页面放在 /design/tokens.md。源文本