createTheme
stablefunction createTheme<T extends TokenMap>(def: {
readonly name: string;
readonly tokens: T;
readonly fonts?: readonly FontFace[];
readonly root?: ThemeRootStyles;
readonly reducedMotion?: ReducedMotionMode;
}): Theme & { readonly tokens: T }Theme name. Used as the data-theme attribute value on web. Must be unique among themes registered with a single ThemeProvider.
Full token tree (primitives interleaved with semantics). Top-level keys are scale names — colors, space, radii, fontSizes, etc. Leaves are literal values or $-prefixed token references.
Web-only. @font-face declarations ThemeProvider emits into the document. No effect on native.
Web-only. Base styles applied to the document root — body resets and the like — emitted by ThemeProvider.
Web-only. The prefers-reduced-motion policy for this theme. No effect on native.
Description
A thin factory. The returned object is exactly the input — createTheme does no transformation
at runtime. The type parameter T extends TokenMap narrows the resulting Theme.tokens so
$-references against this theme autocomplete in your editor.
Pass the result to ThemeProvider's themes array. The provider emits the CSS variables and
sets data-theme to one of the theme names.
fonts, root, and reducedMotion are optional web-only emission hints — <ThemeProvider>
picks them up to emit @font-face rules, document-root styles, and the reduced-motion policy.
They have no effect on native, where there is no stylesheet to emit into.
Examples
Both primitive and semantic tokens live in the same tree. Semantic tokens reference primitives by
$colors.<path>; the resolver walks the dotted path until it reaches a literal value.
Related
- Tokens — the token model, primitive vs semantic layers.
- Theming — how a theme becomes active at runtime.
ThemeProvider—<ThemeProvider>and<Theme>boundary.