Design tokens
theme.tokens loads a W3C Design Tokens (DTCG) .json file
or a CSS variables .css file into the theme section of recit.config (.ts, .js, .mjs or
.json). The path is resolved relative to the configuration file: the config loader adds it to the
config's dependencies and the deck dev server reloads it on change; for a film, a webstory or a
book, restart recit dev after changing the file.
tokens.json
recit.config.ts
Precedence and light mode
- Any key written in
themeoverrides the token.theme.colors,theme.darkandtheme.fontswin key by key over the mapped tokens (colors.above replacesprimary color.actionwhilecolor.,background color.inkandcolor.accentstill come fromtokens.jsonortokens.css), andtheme.radiusoverrides a mapped radius token. - Without dark tokens in the token file, set
colorMode:. Stories open in dark mode by default ("light" colorMode:): when"dark" tokens.json(no rootdarkgroup) ortokens.css(no dark selector or media block) carries only light tokens, setcolorMode:beside"light" theme:so decks and other stories open in light mode.
Token mapping (DESIGN_ TOKEN_ MAP)
For each theme key, Récit checks the token paths below in order (DESIGN_ from
@recit/core) and picks the first match whose $type fits:
| Design token path (first match wins) | Key of theme | Expected $type |
|---|---|---|
color., color.action, color.brand | theme. | color |
color., color., color., color., color., color., color., color. | theme. | color |
color.accent, color. | theme. | color |
color., color., color., color., color., color. | theme. | color |
color., color., color.canvas, color.bg | theme. | color |
color., color.text, color.ink | theme. | color |
color.card, color., color. | theme. | color |
color., color., color.onCard, color., color., color. | theme. | color |
color.border, color.stroke, color.line, color. | theme. | color |
color.muted, color.subtle, color. | theme. | color |
color., color., color., color., color., color. | theme. | color |
dark. (dark., dark., dark., dark.…) | theme. | color |
radius.lg, radius., radius, borderRadius.lg, borderRadius., borderRadius | theme.radius | dimension |
font.sans, font.body, font., font., fontFamily.sans, fontFamily.body, font | theme. | fontFamily |
font.heading, font.display, font., font., fontFamily., fontFamily. | theme. | fontFamily |
font.mono, font.code, font., font., fontFamily.mono, fontFamily.code | theme. | fontFamily |
font., font., fontFamily. | theme. | fontFamily |
Nested groups inherit $type, {group. aliases (including chained aliases) are resolved with
cycle detection, dimension tokens accept CSS length strings ("8px", "0.5rem") or
{ value, unit } objects (px or rem), and fontFamily tokens accept a CSS font-family string
or an array of family names.
In TypeScript, designTokensFromCss(css, { file }), themeFromDesignTokens(json, { map }) and
mergeThemeTokens(theme, tokens) are also exported from @recit/core when converting CSS tokens or
using a custom mapping table, and themeFromTokensSource(source, path) reads the text of a
theme.tokens file, CSS or JSON by its extension, as recit and the site framework do.
CSS variables
When theme.tokens ends with .css, Récit parses the stylesheet with designTokensFromCss into
the equivalent DTCG structure and maps it through the same DESIGN_ table:
- Name correspondence. Custom properties declared on
:rootorhtml(including:where(:and rules insideroot) @layer) map hyphenated names toDESIGN_paths and inferTOKEN_ MAP $type(color,dimensionorfontFamily) from the matched row:- Colors:
--color-→primary color.,primary --color-→action color.action,--color-→on- primary color.,onPrimary --color-→primary- foreground color.,primaryForeground --color-→accent color.accent,--color-→on- accent color.,onAccent --color-/background --color-/surface- 0 --color-bg→color./background color./surface.0 color.bg,--color-/foreground --color-text/--color-ink→color./foreground color.text/color.ink,--color-card/--color-/surface --color-→surface- 1 color.card/color./surface color.,surface.1 --color-/on- card --color-→on- surface color.onCard/color.,onSurface --color-/border --color-→stroke color.border/color.stroke,--color-/muted --color-/subtle --color-→surface- 2 color.muted/color.subtle/color.,surface.2 --color-/text- muted --color-→muted- foreground color./textMuted color..mutedForeground - Radius:
--radius-lg→radius.lg,--radius-→default radius.,default --radius→radius,--border-→radius- lg borderRadius.lg,--border-→radius borderRadius. - Fonts:
--font-sans/--font-body/--font-/family- sans --font→font.sans/font.body/font./family.sans font,--font-/heading --font-→display font.heading/font.display,--font-mono/--font-code→font.mono/font.code,--font-→lettering font..lettering
- Colors:
- Dark mode. Custom properties declared inside
[data-(includingmantine- color- scheme= "dark"] :where(:),root[data- mantine- color- scheme= "dark"]) .dark,[data-, ortheme= "dark"] :root/htmlinside@media (prefers-go into the rootcolor- scheme: dark) darkgroup (dark.color.*), fillingtheme.darkjust like DTCG JSON. var()aliases. A valuevar(--x)that points to another custom property in the file (including an unmapped primitive such as--palette-) becomes a DTCGblue: # 2563eb {a.b}alias ({palette.), with chained alias resolution and cycle detection.blue} - Unknown properties and errors. Unmapped custom properties not referenced by a mapped token are
ignored. An empty custom property value or unreadable CSS throws an
Errornaming the file and line number.
tokens.css
recit.config.ts
In a site
theme.tokens also works in a site's recit. (@recit/site). The site config loader
resolves the path relative to the config file, watches it for reloads in dev, and passes the
resolved theme to the client through the site config while stripping tokens so the file path
never enters the client bundle:
- Colors and radius. Mapped light colors fill
theme.lightand the rootdarkgroup fillstheme.darkfor the closed list of site token keys (background,foreground,card,cardForeground,primary,primaryForeground,muted,mutedForeground,border), while a mappedradiustoken fillstheme..light. radius accent(andaccentForeground) from tokens does not go to the site, because--accentin@recit/siteis the pale hover surface rather than a vivid spot color. Any key written directly intheme.lightortheme.darkwins over the token. - Light-only token files. When
tokens.jsonhas nodarkgroup (ortokens.csshas no dark block), setsite:for a light-only site; top-level{ colorMode: "light" } colorModeinrecit.configapplies to stories, not to the site. - Fonts are not copied. A site's
theme.fontsrequires a stylesheeturl(or a predefined Google Fonts name) to load the font files, sofontFamilytokens fromtokens.jsonortokens.cssare ignored by the site loader; configure site fonts intheme.fontsor@importthem instyles.css.
What is not read
- Spot and chart colors. Extra palette entries such as
color.spot.*are validated when typed ascolor, and ignored when mapping totheme: chart role and scale colors live undertheme.chart.shadowtokens and unmapped dimensions (such asradius.sm) are likewise validated and ignored. - Object color values. DTCG structured color objects (
{ colorSpace, components }) are not read; write colors as CSS strings (hex,rgb(),hsl()oroklch()).