haus publishes tokens and components to npm
The system
haus is five npm packages: design tokens with a replaceable brand, twenty React components built on them, and the colour libraries underneath. The form below uses nothing else, installed the way a product installs it. Every component and every token family has a page in the live Storybook, and a test fails if a component has none. The Figma file has the same components under the same names.
The problem
I was building two products, vault, a Mac app, and core, a web app, and both were writing the same token layer: 159 custom properties in one, 56 in the other, under the same role names. Of the 40 values that differed, about thirty were palette swaps. haus is that shared layer, with the brand as its own replaceable file, plus the components more than one product built and the colour maths their tools use. Five products install it.
Design decisions
Roles, not values. A component reads a role such as --haus-color-primary-default, never a palette step, in four layers: primitives hold the values, the brand chooses which primitive each role takes, semantics name what each role means, and motion sits apart. Every surface role has a paired ink role, chosen together, and a test measures each pair against WCAG AA, so a contrast failure is caught where the tokens are defined. The measuring had a bug of its own: it rounded the ratio before comparing it, so 4.4957:1 passed AA. It now compares the exact ratio (haus#137). Colours are authored in OKLCH, where equal steps look equal.
- surface
- color-info-subtle›brand-info-subtle›elderberry-100
- ink
- color-info-on-subtle›brand-info-on-subtle›elderberry-700
A brand is one file. Which primitive each role takes lives in brand.css, 71 entries in three tiers: a required base of surfaces, ink, borders and primary, and optional feedback and form tiers, where form covers radius, shadows and typeface. A brand is scoped by data-haus-theme, so it applies to a subtree. Two products ship their own on the same role names; the demo switches to one of them, vault's.
Type by role. Type is set by role rather than heading level: sixteen roles such as body, label-field and a mono ladder of three, so an author picks what the text is, not the size that looks right. Each role binds all four of size, weight, leading and tracking, because a component that takes the size and guesses the rest drifts from one written by someone else, and the Figma text styles bind the same four. The default faces are Manrope and Fira Code, and a brand can replace either. Spacing works the same way: three roles over one ladder, inset for padding, gap between siblings and stack for margin, so a step means the same thing in every file.
Light only. Every ink is paired with the surface it is safe on, and the contract fixes the polarity: white cards on a subtle page. A dark theme inverts that, so it cannot arrive as a brand; doing it properly would mean reopening the decision and doubling the colour pairs to audit.
The layers, the brand tiers and the type roles are in DESIGN.md.
Components
Joined on evidence. A component joins haus when the products have built it more than once, independently, not because other systems ship it. Reading those builds side by side found an accessibility defect in four of the first six, none flagged by axe, and each fix became a prop. A busy indicator, built three times, became Spinner. vault's drawer and command palette stay out, each one product's answer to one product's problem.
One prop vocabulary. variant is visual weight, tone is meaning, and the words are the same on all twenty, so a product that has learned one component has learned the props of the rest. className always lands on the root.
Accessible, and enforced. Axe runs in all twenty component suites, and keyboard tests cover arrows, Escape and focus return. A raw value in a stylesheet fails Stylelint, and a component that reads a colour primitive, uses a physical property or names a custom property nothing declares fails a test. Behaviour is held the same way: a loading submit button once let Enter submit a one-field form, which the disabled button had blocked, so a loading button now renders a hidden, disabled submit button beside it (haus#128).
The components, the accessibility checks and every enforcing test are in DESIGN.md.
Design and code
Figma checked on every pull request. The Figma file and the code describe the same system, so a script compares them on every pull request: every token resolved to its final value, and each component's variant axes and states. It keeps the pair of values both sides last agreed, which says which side moved. Code ahead of Figma fails the build; a change made in Figma opens an issue to decide. When the check was switched on it found twelve items where Figma had fallen behind the code, and all twelve were drawn in Figma (haus#133).
| What changed | Last agreed | Now |
|---|---|---|
| Code | #7653ab | #5b3c89 |
| Figma | #7653ab | #7653ab |
figma parity · token --haus-color-primary-defaultCode ahead of Figma. Fails the pull request until Figma matches, or the difference is accepted as known drift.
Tokens for design tools. The custom properties are the format products run; tokens.json is the format for tools. It follows the W3C Design Tokens format and ships in the package, so Style Dictionary or any pipeline that reads the format takes haus tokens without haus-specific tooling.
The parity check is in WORKFLOW.md, and the decisions in DESIGN.md.
Engineering
Five packages, on purpose. One pnpm workspace publishes five packages, each versioned on its own, so a project that needs only the tokens does not install React and a tool that measures colour does not load the names. Each ships ESM and CommonJS with its own types. haus-style-probe, the least obvious of the five, reads every element's computed styles in a page and normalises them in Node, the measuring core of a design-drift auditor.
Five packages, one release path, five products. Choose a package or a product.
Generated, and type-checked. A script generates the primitives, the motion layer and the typed constants from tokens.json, and CI fails if a committed file differs from what it would write. It also generates the type of a brand from brand.css, so a product's brand file that misses a required entry fails that product's own typecheck instead of leaving an unresolved colour at runtime.
A guard products run. haus-tokens/guard ships three pure functions a product calls in its own tests: a stylesheet reading a token nothing defines, a token only ever read with a fallback (a hard-coded value in effect), and an override restating the value haus already gives. They read CSS as strings, so they run in a test, a script or a browser.
.card {
padding: var(--haus-space-inset-md);
border-radius: var(--haus-radius-control);
}haus-tokens/guardOne release path. Each package is published by a tag such as components-v3.2.0. One workflow checks the manifest agrees, checks every workspace dependency is already on npm, then builds, tests and publishes with provenance. npm trusts the workflow through OIDC, so no token is stored.
# git tag components-v3.2.0 && git push --tags
dir=components version=3.2.0
packages/components/package.json says 3.2.0 # or stop
haus-components@3.2.0 not on npm yet # or skip
haus-tokens@5.2.0 is on npm # or stop: publish it first
pnpm run build && pnpm --filter haus-components test
pnpm pack # rewrites workspace:^ to ^5.2.0
npm publish # OIDC from GitHub, no stored token, provenance attachedTested at every layer. 731 tests across the five packages. The component suites assert markup, behaviour and accessibility, every component is also rendered on the server, a test holds the rule that keeps ten of them safe as Server Components, and coverage floors are enforced in CI. Chromatic snapshots every story, and a visual change waits for a person to accept it.
Hue families fitted to names. haus-colour-utils sorts a colour into one of eight families. The boundaries were first midpoints between eight namesake colours, which filed most oranges as red. They are now fitted to 4,275 colours whose names end in a family word, which raised mean recall per family from 0.62 to 0.78, and a test rebuilds that set and holds the score. Two products sort with it; the contrast ratio in the tone demo above is the same package.
The package graph, the builds, the guard and the publish workflow are in ARCHITECTURE.md.
Where it stands
All five packages are on npm and five products depend on them. What is open: Badge is the last component still declaring its tone colours directly, and the accessibility checks are automated, with no screen-reader run and no right-to-left visual test yet.
The design notes are in DESIGN.md and the engineering notes in ARCHITECTURE.md.