Design Systems · Lesson 12 / 13
From design to code
How a design system lives in code: the token pipeline, building a component library, matching APIs, theming, packaging and versioning, Storybook, visual and accessibility testing, and keeping Figma and code in sync.
4 min read · 5 quiz questions
Design and code: one system, two places
A design system that exists only in Figma is a UI kit. The real system lives in code too — in a component library that product teams install and use. The challenge is keeping both sides in sync so that what designers place in Figma is exactly what developers can build.
The goal is parity: the same tokens, the same components, the same names, the same options, the same states.
The token pipeline
- 1Source of truth — tokens are defined in one place: Figma variables, a tokens plugin, or JSON in a Git repository.
- 2Export — tokens are exported as JSON, ideally in the W3C Design Tokens format.
- 3Transform — a build tool like Style Dictionary converts JSON into platform formats.
- 4Distribute — outputs are published in a package that apps install.
- 5Consume — components and apps use token names, never raw values.
tokens/*.json ──▶ Style Dictionary ──▶ build/
├── css/variables.css (--color-action-primary)
├── js/tokens.ts (colorActionPrimary)
├── ios/Tokens.swift (Color.actionPrimary)
└── android/colors.xml (@color/action_primary)Building the component library
- Pick the frameworks your products use (e.g. React for web, SwiftUI for iOS, Jetpack Compose for Android). Many systems also offer Web Components to work across frameworks.
- Build components on accessible foundations — native elements, or proven headless libraries (such as Radix UI, React Aria or Headless UI) that handle keyboard and ARIA behaviour.
- Style components only with tokens.
- Support theming through CSS variables or a theme provider.
- Support RTL with logical properties.
- Make components composable and forward refs and native attributes so teams aren't blocked.
Matching component APIs
Figma properties and code props should be a direct translation:
| Figma property | Code prop |
|---|---|
| Variant = Primary / Secondary / Danger | variant="primary" | "secondary" | "danger" |
| Size = SM / MD / LG | size="sm" | "md" | "lg" |
| Show icon = true (boolean) | iconStart={<Icon />} |
| Label = "Continue" (text) | children="Continue" |
| State = Disabled | disabled |
| State = Hover / Focus / Pressed | Handled by CSS (:hover, :focus-visible, :active) — not props |
import { Button } from "@acme/design-system";
import { ArrowRight } from "@acme/icons";
export function CheckoutFooter() {
return (
<Button variant="primary" size="md" iconEnd={<ArrowRight />}>
Continue to payment
</Button>
);
}Interaction states like hover and focus are designed in Figma as variants, but in code they're usually CSS states, not props. Document this so designers don't expect a state prop.
Packaging and versioning
- Publish the library as a package (e.g. on npm, or a private registry) so products install a specific version.
- Use semantic versioning: MAJOR for breaking changes, MINOR for new features, PATCH for fixes.
- Write a changelog for every release, with migration notes for breaking changes.
- Consider codemods — scripts that automatically update product code for breaking API changes.
- Release regularly and predictably so teams can plan upgrades.
Documenting and testing in code
| Practice | What it does |
|---|---|
| Storybook stories | Every component, variant and state rendered in isolation; interactive props |
| Visual regression tests | Screenshots compared on each change to catch unintended visual changes (e.g. Chromatic, Playwright snapshots) |
| Accessibility tests | Automated axe checks in stories and unit tests; manual keyboard and screen reader checks |
| Unit / interaction tests | Behaviour: clicking, typing, keyboard navigation, focus management |
| Type checking | TypeScript types document the API and prevent invalid props |
Keeping Figma and code in sync
- Use the same names for tokens, components and properties in both places.
- Automate token sync so values can't drift.
- Use Figma Dev Mode and Code Connect (where available) so inspecting a component in Figma shows the real code snippet.
- Include designers and developers in each other's reviews: a component is "done" only when it exists, matches, and is documented on both sides.
- Track parity in a simple table: component, Figma status, code status, docs status.
| Component | Figma | Code | Docs |
|---|---|---|---|
| Button | Stable | Stable | Complete |
| Text field | Stable | Stable | Complete |
| Date picker | Beta | In progress | Draft |
| Data table | Planned | — | — |
Common mistake: Designers creating new variants in Figma that don't exist in code. Product designers use them, developers can't find them, and they build one-offs. New variants should be proposed, built and released together.
Key takeaways
- A real design system lives in both design and code, with parity between them.
- Tokens flow from one source of truth through tools like Style Dictionary to every platform.
- Build accessible, token-styled, themeable components with APIs that mirror Figma properties.
- Package with semantic versioning, changelogs and migration notes.
- Test visually, for accessibility and for behaviour, and keep Figma and code in sync on purpose.
Exercise
Mirror a component in code
- Take the Button you built in Figma.
- Write its props as a TypeScript type that mirrors the Figma properties.
- Implement it with CSS variables from your tokens (any framework, or plain HTML/CSS).
- Add hover, focus-visible, active, disabled and loading styles.
- Fill in a parity table comparing the Figma and code versions.
Test yourself
From design to code quiz
5 questions. Score 70% or more to complete the lesson.
