← Back to portfolio

DESIGN SYSTEMS

Lutra UI

An accessibility-first React and TypeScript component library, built from an existing Figma design library.

Role
Creator and maintainer
Stack
React, TypeScript, Nx, pnpm, Storybook, Vitest
Distribution
npm, MIT license
Used by
This website

Lutra UI is an accessibility-first React component library, built from an existing Figma design library and designed to be shared across more than one application.

This case study covers how the library is structured, the rules it holds itself to, and the decisions behind it.

Context

Lutra UI began as a Figma design library and became a React and TypeScript package, @lutra-ui-system/react. Accessibility is the point of the library rather than a later pass over it: components are built from native HTML elements, work with a keyboard, keep a visible focus indicator, and stay usable when text wraps or the page is zoomed.

It is built to serve more than one application. The intended consumers are this website (Nx, Next.js App Router, static export) and Lutra personal finance (Nx, React, Vite). The package ships standard ESM with type declarations, avoids browser globals while a module is evaluated, and renders correctly on a server with no DOM.

Challenges

Four constraints shaped most of the work:

  • Keeping Figma, CSS, and any other token representation from becoming separate sources of truth. An early hand-written token set was already drifting from Figma.
  • Serving different applications without special handling, including server rendering and applications with no dark design.
  • Making accessibility enforceable rather than aspirational, when automated checks cover only a small slice of it.
  • Releasing a versioned package whose generated artefacts embed the version.

Responsibilities

The repository covers the whole path from design tokens to a published package, including:

  • The component library: 19 components, each with a written contract and colocated tests
  • The token pipeline from the Figma collections to generated CSS and JSON
  • The accessibility principles and how they are enforced in review and tests
  • Storybook as the reviewable reference for states, themes, and layouts
  • Release automation and package distribution
  • Architecture decision records for the choices that set precedent

Technical approach

Components live one per directory in a package-based Nx workspace. The package root index is the only supported entry point, and each component folder has its own barrel, contract, and tests.

  1. Figma variable collections
  2. source.json: the canonical token source
  3. Generator: generated.css and generated.json
  4. Shipped stylesheet (CSS custom properties) and Storybook Foundations
  5. Applications that import the stylesheet
Figure 1. Tokens flow one way. The Figma collections are mirrored in one source file, and every other artefact is generated from it. A drift test fails if the generated files differ from the generator’s output.

A single hand-maintained source file mirrors the Figma collections name for name and mode for mode. A generator emits the CSS custom properties that the shipped stylesheet declares, and a JSON file that Storybook’s Foundations stories read. A test fails if the committed output differs from what the generator produces now.

Theme and density are separate axes, set with attributes on any element:

<html data-theme="dark" data-density="condensed"></html>

Light is the default, dark is one attribute, and the library does not read prefers-color-scheme. When an application is dark is the application’s decision.

Decisions

One canonical token source, with generated artefacts committed. For a design system the token diff is the reviewable artefact, and the drift test is what makes committing generated files safe. A typed TypeScript token map is deliberately not generated.

Density is a global attribute, not a prop. Density is one decision for a whole subtree, which a prop cannot express, so Field, Select Field, Input, and Select have no density prop.

Native elements first. ARIA supplements native semantics and never replaces them, and a div with a click handler is not a button.

Automated checks report. They do not certify.

Release automation owns version-bearing generated artefacts. The commit that bumps the version updates every checked-in artefact that embeds it, so a release pull request is consistent when it is written. This replaced hand repairs after release pull requests failed the drift check for versions 0.2.0, 0.2.1, and 0.3.0.

Outcomes

  • Published to npm as @lutra-ui-system/react under the MIT license.
  • In use on this website, which consumes the published package.
  • 19 components with written contracts, colocated tests, and Storybook stories for states and themes.
  • Five architecture decision records capture the decisions that set precedent.

Links and resources

More engineering work

Other case studies in design systems, component architecture, and accessible UI engineering.

View portfolio