Systems DesignDocumentationWeb Development

A UI System With Design Tokens, React, Storybook, and Docs

Tokens hold the visual decisions, React components use them, Storybook shows them, and docs keep the team consistent. How the four fit together, with code.

Table of Contents (5)

Design tokens, React and Storybook work well together for building a UI system. Tokens keep the visuals consistent, React components put them to use, Storybook lets the team see and test the components, and documentation tells everyone how to use and extend them.

What do design tokens do?

Tokens standardize visual attributes like colors, typography and spacing, so every component and platform draws from one source of truth and a change can be made globally. For instance:

{
  "colors": {
    "primary": "#0070f3",
    "secondary": "#ff4081"
  },
  "spacing": {
    "small": "8px",
    "medium": "16px",
    "large": "24px"
  }
}

Style Dictionary or Theme UI can bring tokens into a React app, either as CSS variables or as JavaScript objects:

const theme = {
  colors: {
    primary: "var(--colors-primary)",
    secondary: "var(--colors-secondary)",
  },
  spacing: {
    small: "var(--spacing-small)",
  },
};

How do React components use tokens?

React's component-driven architecture lets you encapsulate UI logic and styles, reuse them across projects, break complex interfaces into smaller pieces, and combine small components into larger ones that stay consistent.

Here a button reads its styles from the tokens:

const Button = ({ label, variant }) => {
  const styles = {
    primary: {
      backgroundColor: "var(--colors-primary)",
      color: "white",
      padding: "var(--spacing-medium)",
    },
    secondary: {
      backgroundColor: "var(--colors-secondary)",
      color: "white",
      padding: "var(--spacing-medium)",
    },
  };
  return <button style={styles[variant]}>{label}</button>;
};

Because components are tied directly to tokens, an update to a token propagates through the whole component library.

What does Storybook add?

Storybook lets teams develop, test and document React components in isolation, apart from the main app. It generates documentation from props, usage examples and visual previews, and you can share live previews with designers, developers and stakeholders. It works as a living style guide for the UI library.

It can show components under different token configurations:

export const PrimaryButton = () => <Button label="Click Me" variant="primary" />;
export const SecondaryButton = () => <Button label="Click Me" variant="secondary" />;

Pair that with addon-essentials to document tokens and themes inside Storybook:

import { ThemeProvider } from "styled-components";
import theme from "../path/to/tokens";

export const decorators = [
  (Story) => (
    <ThemeProvider theme={theme}>
      <Story />
    </ThemeProvider>
  ),
];

What should the documentation cover?

Documentation is what lets designers, developers and other stakeholders use and extend the components the same way. It has three parts.

Design tokens. Include a glossary with a description for each token, and usage examples such as buttons styled with specific tokens. Token Studio can visualize tokens and sync them with design tools like Figma.

React components. Storybook Docs can generate the detail: prop tables, component states (hover, disabled) and variants (primary, secondary). Add guidelines for when and how to use each component.

The system itself. Explain the architecture, including how tokens are integrated and how theming works, and write guides for extending it, such as adding new tokens or components.

How does it scale across teams and platforms?

Tokens keep web, mobile and other platforms consistent, and they make it possible to theme dynamically for different brands or user preferences. Hooking the components into CI/CD pipelines lets you test and deploy them automatically.