страница пакета→ /design/conventions/style.md
pages/design/conventions/style.md
99 строк, 6.6 КБ. Как страница.
Этот текст ещё не переведён. Ниже английский оригинал.
- ---
- type: Convention
- title: "A design style"
- description: "How a style package is made: it fills the names of the token contract in a light and a dark scheme. What it gives, what it expects, what is free (palette, fonts, radii, extensions), how to make an alternative from the skeleton, and its health."
- icon: "🎨"
- ---
- # A design style
- How [conventions](/base/conventions.md) work: this page is the convention of the base package `design-tokens`. The packages that
- follow it say `follows: [design/conventions/style]`: `shtukbase-style`, `shadcn` and `keer-style`.
- ## 1. What it covers
- A **style** is a package that gives a project its look as values: colours, radius, fonts, shadows. It is not components and it
- is not markup. Components (`design-components` and the libraries on it) and viewers read only the names of the token
- contract, so a style can be swapped for another one and the whole project changes its look. `design-tokens` works out of the box
- with the example tokens it lays; a style package replaces them.
- ## 2. Gives
- A style package gives these, and nothing more is required:
- - **The names of the contract** ([The token contract](/design/contract.md), data in [contract.json](/design/contract.json), version 1):
- every required name defined in `:root`, every colour also in the dark scheme.
- - **The tokens** in the DTCG format: `/design/<id>/tokens.json` (the light scheme) and `/design/<id>/tokens.dark.json` (the dark
- scheme). A token path becomes a name: `card-foreground` is `--card-foreground`, `sb.hue.1` is `--sb-hue-1`.
- - **The built CSS** `/design/<id>/tokens.css`: the light scheme on `:root`, the dark scheme on `.dark, [data-theme="dark"]`. It is
- built, not written by hand: the action `build` calls `buildStyle(id)` of `design-tokens`, and runs after install and update.
- - **A way to choose it:** `style: <id>` in the header of [Design](/design/design.md). A style package may set it on install when it
- is empty (the action `adopt` of `shtukbase-style` does).
- The `<id>` is the id of the package. Everything the package lays about its own look (`/design/<id>.md`, fonts, a mark, a
- showcase, its norms) is free, see section 4.
- ## 3. Expects
- From `design-tokens` and nothing else:
- - the contract (`/design/contract.json`) and the build library `buildStyle(id)` in `.shtukbase/packages/design-tokens/actions/build.ts`;
- - the page `/design/design.md` (the choice `style:`).
- Not from the components, not from any other style, not from `icons`. A style does not know which libraries are used with it.
- ## 4. Free to choose
- Everything the contract leaves open. This is where an alternative is creative:
- - the **palette**: any values for the colour names; how many shades and what to call them in the package itself (`--sb-graphite` is
- `shtukbase-style`'s own);
- - the **fonts** (`--font-sans`, `--font-mono`, `--font-display`) and how they are loaded;
- - the **radius** and the **shadows** (`--radius`, `--shadow-sm`, `--shadow-md`, `--shadow-lg`);
- - the **optional extension** of the contract (`--sb-hue-1` … `--sb-hue-12` with `-soft`, `-tint`, `-ink`, `--sb-glow`, `--sb-edge`,
- `--sb-ease`, `--sb-dur`, …): set them or leave them, the defaults apply;
- - names of its own, as many as it needs (they are reported as `extra`, which is only information);
- - anything else it lays: fonts, a mark, a showcase page, norms of its own look.
- ## 5. Make an alternative
- The recipe for an agent who is told "make a style like `shtukbase-style`, but in another taste":
- 1. Copy the **skeleton**: the folder `skeleton/style/` of the package `design-tokens` (installed at
- `.shtukbase/packages/design-tokens/skeleton/style/`; in the repository `apps/standard/packages/design-tokens/skeleton/style/`).
- It is a complete style package with a plain neutral value for every required name in both schemes.
- 2. Make it a package: a new folder `packages/<new-id>/`, rename `my-style` to `<new-id>` in `package.md`, in the folder
- `pages/design/my-style/` and in `actions/build.ts` (the constant `ID`). Keep `follows: [design/conventions/style]`.
- 3. Change the values in `tokens.json` and `tokens.dark.json`. Keep every name; a colour needs both schemes. Add the optional
- extension if the look needs it.
- 4. Build and judge: `shtuk run <new-id> build`, then `shtuk run design-tokens health --style <new-id>`. Read the lines: add what is
- `missing`, and decide for each name in `fallbacks` whether the default is what you want.
- 5. Choose it with `style: <new-id>` on `/design/design.md` and look at it: open `/design/<new-id>/...` showcase if you wrote one,
- or the catalog lens of `design-lenses`, in both schemes.
- 6. Run `shtuk check`: the hard gate [DTK-R03](/norms/rules/design-tokens/DTK-R03.md) and the report DTK-R04 must both be quiet about
- `missing`.
- **References.**
- - `shtukbase-style`: a full style package. Read it for the structure: tokens in DTCG, the built CSS, `build` and `adopt`, the optional
- extension (the 12 hues), fonts, norms of its own look. **Do not copy** its raspberry, Outfit and Onest, the Viewfinder mark, the glow
- and the even edge: that is its taste, not the promise.
- - `shadcn`: the origin of the names. Its theme (`.shtukbase/packages/shadcn/registry/styles/theme.css`) has only the shadcn names and
- is a valid style as it is: judge it with `shtuk run design-tokens health --css <file>`. Read it to see how little a style needs.
- **Do not copy** the `components.json` and component placement: that is `shadcn`'s own business, not a style's.
- - `keer-style`: a style of an earlier product with its own `--ds-` names. It follows the convention in intent but does not fill the
- contract names yet; its health shows what is missing. Read it for the idea of two themes, not as a model.
- ## 6. Health
- The norm [DTK-R04](/norms/rules/design-tokens/DTK-R04.md), enforcer `checks/health.ts`, mode `warn`. It judges the chosen style
- (`--style <id>`, `--all` and `--css <file>` judge others) and prints lines `health style/<id>: <band>`:
- | Band | Means for a style |
- |---|---|
- | `full` | every required name is set, every colour has a dark value, no optional name is left out |
- | `missing` | a required name, a dark value (`--x (dark)`) or a reference that leads nowhere; components that read it fall back to the browser default |
- | `fallbacks` | optional names left out; the defaults of the contract apply (each one derived from the required names), so nothing breaks |
- | `extra` | names outside the contract; may be the style's own, or a hint that the contract should grow |
- It never fails. The hard version of the same judgement is the gate [DTK-R03](/norms/rules/design-tokens/DTK-R03.md) (`shtuk run design-tokens contract`).