ShtukbaseStandard
страница пакета→ /design/contract.md

pages/design/contract.md

82 строки, 4.9 КБ. Как страница.

Этот текст ещё не переведён. Ниже английский оригинал.

  1. ---
  2. type: Page
  3. title: "The token contract"
  4. description: "The fixed list of CSS custom property names that a style defines, that components use and that viewers read: what is required, what is optional, how a style meets it, the check."
  5. icon: "🤝"
  6. ---
  7. # The token contract
  8. One list of names joins every design package. A **style** fills the list. **Components** use only the names on the list.
  9. **Viewers** (the style specimen, the component catalog) read the list. So a style, a component library and a viewer can each
  10. be swapped for another one built to the same contract. The list is data: [contract.json](contract.json), version 1.
  11. ## Why these names (owner decision, 29.11.2026)
  12. The base of the contract is the **shadcn/ui theme variables, unchanged**: they are the most widely used set of theme names, so
  13. every shadcn theme and every theme generator already produces a valid style, and shadcn components take our style as it is.
  14. The fonts and shadows are the **Tailwind v4 theme namespaces**. Only what these two lack is our own, under the prefix `--sb-`.
  15. ## What a style defines
  16. A style is a set of CSS custom properties on `:root` (the light scheme) and on `.dark, [data-theme="dark"]` (the dark scheme).
  17. **Required, the shadcn theme names.** Every colour name has a value in both schemes.
  18. | Group | Names |
  19. |---|---|
  20. | Surface | `--background`, `--foreground`, `--card`, `--card-foreground`, `--popover`, `--popover-foreground` |
  21. | Action | `--primary`, `--primary-foreground`, `--secondary`, `--secondary-foreground`, `--accent`, `--accent-foreground`, `--destructive` |
  22. | Quiet | `--muted`, `--muted-foreground`, `--border`, `--input`, `--ring` |
  23. | Charts | `--chart-1` … `--chart-5` |
  24. | Sidebar | `--sidebar`, `--sidebar-foreground`, `--sidebar-primary`, `--sidebar-primary-foreground`, `--sidebar-accent`, `--sidebar-accent-foreground`, `--sidebar-border`, `--sidebar-ring` |
  25. | Shape | `--radius` (one value for both schemes) |
  26. **Optional, the Tailwind v4 namespaces** (one value for both schemes): `--font-sans`, `--font-mono`, `--shadow-sm`,
  27. `--shadow-md`, `--shadow-lg`. A plain shadcn theme does not set them, so they have defaults (the system fonts, the Tailwind
  28. shadows): any shadcn theme passes the check as it is (the owner, 29.11.2026: as compatible with shadcn as possible).
  29. **Optional, our extension, with defaults.** A style may leave these out; the default in `contract.json` applies, and it is
  30. derived from the required names, so a plain shadcn theme still works.
  31. | Name | What | Default |
  32. |---|---|---|
  33. | `--font-display` | the display font | `--font-sans` |
  34. | `--sb-hue-1` … `--sb-hue-12` | the palette; each has `-soft` (a light fill), `-tint` (a lighter fill), `-ink` (text on the fill) | the five chart colours, repeated; the fills mixed with `--background`, the ink with `--foreground` |
  35. | `--sb-shadow-lift` | the hover shadow | `--shadow-md` |
  36. | `--sb-shadow-sheet` | the shadow of area backgrounds | `--shadow-sm` |
  37. | `--sb-glow` | the rim of the Basic card, a box-shadow | a thin ring of `--primary` |
  38. | `--sb-edge` | the card edge, a box-shadow | a thin ring of `--border` |
  39. | `--sb-ease`, `--sb-dur` | the motion curve and duration | `cubic-bezier(0.2, 0, 0, 1)`, `160ms` |
  40. ## `contract.json`
  41. ```json
  42. {"version": 1, "required": ["--background", "…"], "colors": ["--background", "…"], "extension": {"--font-display": "var(--font-sans)", "…": "…"}}
  43. ```
  44. - `required`: every name a style must define in `:root`.
  45. - `colors`: the required names that need a dark value too.
  46. - `extension`: each optional name with its default value.
  47. Other packages read it with `readContract()` from the `design-tokens` package (`lib/contract.ts`): the style packages for
  48. their own checks, the viewers for the specimen, the libraries for the defaults.
  49. ## How a style meets the contract
  50. 1. Write the tokens as DTCG files: `/design/<style>/tokens.json` and `/design/<style>/tokens.dark.json`. A token path maps to a
  51. name: `card-foreground` is `--card-foreground`, `sb.hue.1` is `--sb-hue-1`.
  52. 2. Build them with the `build` action of this package (the dark selector is `.dark, [data-theme="dark"]`) into
  53. `/design/<style>/tokens.css`.
  54. 3. Choose the style on [Design](design.md): `style: <style id>`.
  55. 4. Run `shtuk check`: the check `contract` ([DTK-R03](/norms/rules/design-tokens/DTK-R03.md)) fails when a required name or a
  56. dark value is missing. It names the optional names left out, so you see which defaults apply.
  57. For any CSS file by hand (a shadcn theme, a generator's output): `shtuk run design-tokens contract --css <file>`.
  58. The same judgement as a report that never fails, in bands (full, missing, fallbacks, extra): `shtuk run design-tokens health`. How to make a style from a skeleton: the convention [A design style](conventions/style.md).
  59. ## Versions
  60. The contract is versioned (`version` in `contract.json`). A library says which version it needs; a change that removes or
  61. renames a required name is a new version, a new optional name is not.