Skip to Content
Getting startedFoundationsComponentsPackagesTools

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.

@hipuku/tokens6.0.1Source on GitHub

Install

npm install @hipuku/tokens

Import it once, at the root of your app:

import '@hipuku/tokens/index.css'

What is in it

ImportWhat it isFor
@hipuku/tokens/index.cssEvery layer, in order: primitives, semantics, brand and motionStylesheets
@hipuku/tokens/brands/core.css, /brands/vault.cssA second brand's colours and radiiA product's own brand
import { tokens } from '@hipuku/tokens'The same values as typed constantsBuild config, media queries, canvas
@hipuku/tokens/tokens.jsonThe source, as DTCG JSONFigma, 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: light or dark. It follows the system when left out.
  • data-haus-theme: the brand, such as vault.
  • data-haus-motion: expressive or reduced. Subtle is the default, and the reader's prefers-reduced-motion setting 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 defined

Pass the layer files, not index.css: it only imports them, so on its own it defines nothing.

ExportSignatureDescription
findUndefinedTokens(input: TokenGuardInput) => TokenGuardResultWhich 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.

On this page