Tokens
Every design decision in haus, as CSS custom properties, typed constants and DTCG JSON, built from one source.
The values every haus component reads, in three forms built from one source, so they cannot differ.
Install
npm install @hipuku/tokensImport it once, at the root of your app:
import '@hipuku/tokens/index.css'What is in it
| Import | What it is | For |
|---|---|---|
@hipuku/tokens/index.css | Every layer, in order: primitives, semantics, brand and motion | Stylesheets |
@hipuku/tokens/brands/core.css, /brands/vault.css | A second brand's colours and radii | A product's own brand |
import { tokens } from '@hipuku/tokens' | The same values as typed constants | Build config, media queries, canvas |
@hipuku/tokens/tokens.json | The source, as DTCG JSON | Figma, Tokens Studio and other tools |
Every custom property starts with --haus-. Components read roles, such as
--haus-color-surface-raised, never the raw scales beneath them, so a brand can change what a role
resolves to without touching a component.
Modes
Set as attributes on the root, not as separate builds:
data-theme:lightordark. It follows the system when left out.data-haus-theme: the brand, such asvault.data-haus-motion:expressiveorreduced. Subtle is the default, and the reader'sprefers-reduced-motionsetting always wins.
The guard
@hipuku/tokens/guard checks your stylesheets against what you load. Its main check,
findUndefinedTokens, reports every --haus-* property your CSS reads that nothing you load
defines, which matters because an undefined var() fails silently: the declaration is dropped and
nothing warns. Run it in a test.
import { readFileSync } from 'node:fs'
import { findUndefinedTokens } from '@hipuku/tokens/guard'
const read = (file: string) => readFileSync(file, 'utf8')
const tokens = ['primitives', 'brand', 'semantics', 'motion'].map(layer =>
read(`node_modules/@hipuku/tokens/dist/${layer}.css`),
)
const { missing } = findUndefinedTokens({ reads: [read('src/app.css')], defines: tokens })
// missing is empty when everything the app reads is definedPass the layer files, not index.css: it only imports them, so on its own it defines nothing.
| Export | Signature | Description |
|---|---|---|
findUndefinedTokens | (input: TokenGuardInput) => TokenGuardResult | Which properties are read but never defined. |
findFallbackTokens | (input: Pick<TokenGuardInput, 'reads' | 'defines'>) => string[] | Which properties are only ever read with a fallback. |
findRestatedTokens | (input: RestatementInput) => Restatement[] | Which of a consumer's declarations this package already ships. |
The full reference is the package README.