Foundations
Tokens
Every token group with its values in both modes, how token names are built, where tokens.json lives, how foundation.css and tokens.resolved.json are generated from it, which component sizes the web and the apps share, and how to move off the former names.
A token is a named value: a color, a shadow, a size. Components and products use the name, never the value, so a value can change in one place and every screen follows in both modes. This page is the reference for every token. The rules for choosing between tokens belong to the foundation that owns each group, linked from each section below.
Principles
- One source. Every token in
tokens.jsonis written once there.foundation.cssis generated from it, and nothing else defines a token value. - Names say the role, not the color.
attention, not pink;layer-canvas, not white. A token keeps its name when its value changes, and the dark value lives under the same name. - Use the role token before the palette. Reach for
palette-*only where no role fits; see Color. - A value used three times becomes a token. A one-off value can stay inline, as an ink step or an
oklch()literal; on its third use, add a token.
Where tokens live
An app that uses Tailwind imports @botiverse/raft-ui/styles.css. A page without Tailwind imports @botiverse/raft-ui/foundation.css and reads the custom properties: var(--layer-canvas).
How foundation.css is generated
packages/ui/scripts/build-tokens.mjs reads tokens.json and writes foundation.css and tokens.resolved.json. Never edit either by hand.
vp run @botiverse/raft-ui#build:tokens # write src/foundation.css and src/tokens.resolved.json
node packages/ui/scripts/build-tokens.mjs --check # exit 1 if either is out of date- Change a value in
tokens.json, runbuild:tokens, and commit the three files. A test (foundation.generated.test.ts) fails whenfoundation.cssortokens.resolved.jsondoesn't matchtokens.json. - A token's path becomes its property name:
{layer.canvas}is--layer-canvas.$rootnames the group itself:{foreground.$root}is--foreground. A reference ("{palette.cyan.800}") becomesvar(--palette-cyan-800). - The format has no field for modes, so
tokens.jsonadds an extension,build.botiverse.raft:
The generated file has, in order:
- the palette, on
:where(:root); - light mode, on
:where(:root)and.light; - dark mode, on
.dark; - dark mode again under
@media (prefers-color-scheme: dark)for a root without.lightor.dark, so the page has the right colors before the app sets a class; - the aliases declared in every mode, then the deprecated names;
- the values with a fine pointer, under
@media (pointer: fine)(Tailwind'spointer-fine:), on the same selectors as the values they replace; - the desktop values, under
@media (width >= 48rem) and (pointer: fine)(the query of the desktop type instyles.csstoo), on the same selectors as the values they replace. They come after the fine values, so a token'sdesktopwins over itsfine; - the wide touch values, under
@media (width >= 48rem) and (pointer: coarse), on the same selectors as the values they replace. The query never matches with the desktop's, so the order between them doesn't matter.
A .light element inside a dark page is a light island, for a preview or a portal; the dark: variant in styles.css follows the nearest mode class. See Dark mode.
Resolved values
tokens.resolved.json holds every token whose type is a number (dimension, number, fontWeight, duration) resolved to a plain number in each of the four contexts (Component tokens). An app that can't evaluate CSS reads it instead of tokens.json, whose derived sizes are CSS expressions such as calc(var(--control-height-small) + 2 * var(--list-toolbar-air) + 1px).
- It keeps the groups of
tokens.json. A token is an object with its$typeand a$valueholding one number per context:touch(the token's own value),fine(fine, else the token's own value),desktop(desktop, elsefine, else the token's own value) andwideTouch(wideTouch, else the token's own value). - A
dimensionis in px (1rem is 16px), adurationin ms; anumberand afontWeighthave no unit. - The generator evaluates every reference,
var()andcalc()in the context it resolves, as the browser does under the same media query: on a desktop,list-toolbar-heightis the desktop header height, 44. A value it can't evaluate (a function other thanvar()andcalc(), a unit other than px, rem, ms and s, a missing or circular reference) fails the build with the token and the context in the message. - Colors, shadows and easing curves aren't in it; read them from
tokens.jsonorfoundation.css.
{
"list-toolbar": {
"height": {
"$type": "dimension",
"$value": { "touch": 49, "fine": 49, "desktop": 44, "wideTouch": 49 }
}
},
"list-row": {
"min-height": {
"$type": "dimension",
"$value": { "touch": 56, "fine": 0, "desktop": 0, "wideTouch": 56 }
}
},
"header": {
"height": {
"$type": "dimension",
"$value": { "touch": 56, "fine": 56, "desktop": 44, "wideTouch": 48 }
}
}
}The file itself writes every object on its own lines.
Token grammar
Names are built from a few parts, so a name you haven't seen tells you what it is for.
Neutral roles. The role is one of four:
foreground-*: text and icons;layer-*: a surface, in the order things stack (frame, sidebar, canvas, card, popover);line-*: a line;fill-*: a fill laid into or over a surface.
The purpose says where the token is used: frame, sidebar, canvas, card, popover, code, hud, on-frame, on-hud, link, field. Intensity runs from the bare name down to -muted, then -hint for text, and from -hairline through -seam to -strong for lines.
Color roles. The family is one of brand, attention, info, success, warning, danger or inactive. The slot says which shade:
Signals. you and selected are the yellow of what is addressed to you and of the selected sticker. They hold their own value instead of pointing at brand, so no theme grays them (Themes).
Opacity. Every layer token is opaque except the two scrims, layer-backdrop and layer-backdrop-nested, and the cover over something busy, layer-veil (Surfaces). fill-muted and fill-strong are opaque. fill-subtle, fill-medium, fill-frame-medium and sticker-medium are translucent: they are the hover tiers, laid on top of a control or a row, and fill-medium is also the track of a meter or progress bar (Hover overlays).
Utilities. A Tailwind utility is the property's prefix and the token name: bg-layer-card, text-foreground-muted, border-line-strong. Shadows are named apart: shadow-float for elevation-float, shadow-sticker for elevation-sticker, shadow-focus for focus-ring. The numbered palette steps are only custom properties, not utilities; the bare bg-palette-yellow and its siblings are the exception.
Component tokens
A component token is a size that the web and the iOS and Android apps both draw: a row's height, a control's or a toolbar's height, a step of spacing between parts. It lives in tokens.json so that both read one value, and a change reaches every platform at once.
What goes in. Only a decision both the web and the apps must follow: something a person comparing a phone web page with the app's page would see as a difference. A list row's least height, the toolbar over a list, the avatar column of a message and its gap to the text.
What stays out. A pixel the web needs for its own drawing stays in the component's recipe: an optical offset, a hit area the app gets from its platform, a radius that follows a height, a size only a mouse ever sees, and anything an app draws natively, such as the iOS tab bar (Navigation). A value that exists already isn't registered twice: a size equal to another token is written as that token (var(--header-height)), so they move together, and a size that follows from other tokens is derived where it is used, as the timeline's row step is twice timeline-row-inset.
Four contexts. A token's own value ($value) is what a phone shows, and a touch screen at any width unless the token has wideTouch; it is the value an app reads. desktop is the value from 768px with a mouse or a trackpad. fine is the value with a mouse or a trackpad at any width, for a size that follows the input rather than the width: a narrow window with a mouse takes it, and a desktop takes it unless the token has desktop too. wideTouch is the value from 768px by touch (the apps' wide touch layout, from 744pt), for the few sizes a wide touch screen draws differently from a phone: a head and its bar buttons (artin, #wg-mobile-sync:#265, Raft 1.29). Never write a phone's value as an extension: it is the token's own, so an app never has to read one.
A device with no pointer at all takes the token's own value.
Names. A component token is {component}-{property}: the group is the kind of thing it sizes, in the words the docs use (list-row, list-toolbar, avatar-column, mobile-nav), and the property is one of height, min-height, size, width, inset (above and below the content; inset-bottom below it), gap (between two parts) or air (around a control in a bar). A suffix says what kind of bound it is: -min for a least value (mobile-nav-inset-bottom-min). A size of the same kind as a group that exists joins it (control-height-small) instead of starting a group, and one size two components share is one group they both read (avatar-column, for a message row and a list row), never a copy in each.
Descriptions. Every component token's $description says what it sizes, its value on a phone and on a desktop in words, why it is that size, and why it is shared: which screens on the web and in the apps draw it. It names the decision (who, when, where) when there was one. A description that can't say why the apps need the value is a sign the value belongs in a recipe.
Using them. A recipe reads a component token through its utility (h-control-small, min-h-list-row, py-list-row-inset, w-avatar-column, size-avatar-column, gap-avatar-column-gap, min-h-list-toolbar, py-list-toolbar-air, in styles.css) or, where there is none, its custom property (min-h-[calc(var(--mobile-nav-height)+…)]), and adds no breakpoint and no pointer query of its own for that property: the token switches once, in the token layer. Where the web needs a different value on top, such as a mouse's 64px floor on ListRow, the line that adds the breakpoint sits right under a comment saying so, // web-only: <reason>, the one comment a recipe's class list takes, so a check can tell a deliberate refinement from a breakpoint left over from before the token.
const listRow = tv({
base: [
"min-h-list-row py-list-row-inset",
// web-only: with a mouse ListRow keeps its 64px floor and 12px inset, its current values until someone rules on them
"pointer-fine:min-h-16 pointer-fine:py-3",
],
});packages/ui/src/size-tokens.test.ts checks three things: a token's value written by hand (h-8 md:pointer-fine:h-control where h-control-small is meant, also inside a calc()); a breakpoint on a property a token sets in the same class list, unless it is under a web-only comment; and a size that switches with the pointer (py-3 pointer-fine:py-2) where no token is read, unless it is under a web-only comment. The pointer switches written before the third check are listed in the test as sizes still to lift into tokens. The list only shrinks: a new switch fails, and so does an entry that is no longer in the code.
Token groups
Each block below is generated from tokens.json and shows the light and dark values.
Palette
The raw colors the roles point at. The rules for using them directly are in Color.
Text and icons
foreground and its tiers, and the text colors for the frame and the HUD. Usage and contrast: Color, Typography.
Surfaces
Usage: Color.
Fills
Usage: Color and Hover overlays.
Lines
Usage and widths: Color, Shape.
Ink steps
Translucent steps of ink that lines, secondary text and overlays are made from. Use the role tokens; reach for an ink step only for a one-off wash.
Color roles
What each color means: Meanings of color.
Statuses
Task statuses and presence lights: Statuses.
Stickers
Usage: Stickers.
Shadows and the focus ring
Usage: Elevation, Accessibility.
Metrics
The type metrics a field and a card title share with the parts laid out beside them. Usage: Typography.
The control metrics: a default control's height, the small control's (control-height-small), its icon and hit area, and what a control embedded in a frame keeps: control-embedded-inset, its distance from the frame's outer edge and from its sibling, and control-embedded-size, a chip's or a button's height in a field (Spacing, Shape).
The bars and the items in them: a header's height and air, a bar button and its icon (bar-icon-size), a row's icon-only action (row-action-size, Button icon-sm), an item on the frame, the rail, and the switch's track (Spacing, Responsive layout).
The rows: a sidebar row, an option of a popup list, and the inset of a settings row (Spacing).
The page: the gap between two sections of a form, and a page's top and inset (Page structure, Desktop density).
The component tokens shared with the apps (Component tokens): a row with an avatar and a preview (list-row), the toolbar over a list (list-toolbar), the avatar column a message row and a list row start with (avatar-column), and the phone tab bar the Android app draws itself (mobile-nav).
The timeline rhythm: the message step and the section step between the lines of a conversation, and the row inset each row keeps around its text (Spacing).
The fade lengths: fade-content where content is cut across its height, fade-edge at the sides of a strip that scrolls (Edges fade). And the dimmed opacity, for something present but not active (Dimmed).
Tokens defined in styles.css
These are Tailwind theme values in styles.css, not entries in tokens.json, so they have no generated table.
Former names
The names tokens had before the current ones were deprecated aliases up to raft-ui 0.56 and are removed after it. The codemod below still rewrites them, so code written against an older raft-ui can move in one step. The renames follow a few patterns:
primary-* -> brand-*
accent-* -> attention-*
color-brutal-{color}-{n} -> palette-{color}-{n} (purple -> lavender)
secondary-{n} -> palette-stone-{n}
layer-panel -> layer-canvas
layer-canvas-muted -> layer-sidebar
layer-inset -> fill-muted
layer-hud-foreground -> foreground-on-hud
foreground-strong -> foreground
foreground-icon -> foreground-muted
foreground-placeholder -> foreground-hint
line -> line-seam
line-muted -> line-hairline
theme-shadow-float/lg/xl -> elevation-float (utility: shadow-float)
theme-shadow-sticker -> elevation-sticker (utility: shadow-sticker)
theme-focus-ring -> focus-ring (utility: shadow-focus)
theme-shadow-xs/sm/md -> none: controls cast no shadow, drop the classOne former utility name is still declared because an app uses it: bg-fill-row-hover, which paints fill-subtle. Use bg-fill-subtle.
The codemod
raft-ui ships a codemod that rewrites the old names in Tailwind utilities (bg-…, hover:border-…/50) and in CSS custom properties (var(--…)):
node node_modules/@botiverse/raft-ui/codemods/token-names.mjs <dir-or-file>... [--dry]- It rewrites
.ts,.tsx,.js,.jsx,.mjs,.cjs,.cssand.htmlfiles, and skipsnode_modules,distandbuild.--drylists the files it would change. - It renames references and leaves declarations alone, so running it twice is safe.
- Review the result by hand. A guard that forbade an old name (a lint rule, a test, an allowlist) now forbids the new one, and a pattern built from parts, such as a regular expression over class names, keeps the old name.
- The docs never use a deprecated name:
scripts/check-docs.mjsfails a page that names a token in thedeprecatedgroup.
Changing a token
- Add or change a value only in
tokens.json, then regeneratefoundation.cssin the same change. - Give a new token a name that follows the grammar above, and add its utility to
styles.cssif components need one. - Add a component token only if it passes the rule in Component tokens, with a description that says why the web and the apps share it.
- Rename a token by keeping the old name in the
deprecatedgroup, pointing at the new one, and adding the rename to the codemod. Remove aliases only in a release that lists breaking changes (before 1.0, a minor version), once no app uses them. - When a text, surface or tint value changes, recheck the contrast guarantees in Color for both modes.
- Update the foundation page that owns the token in the same pull request (Authoring).
Related
- Color: what each color token is for, and the contrast it guarantees.
- Typography: the type styles and the metric tokens.
- Elevation: shadows and the focus ring.
- Dark mode: what changes between the modes.