ARTICLE - Dev Stack & Tools

Building a Design System and Component Library

A design system connects visual decisions, component behavior and usage rules. Start with one real component, agree on its tokens and states, then expand as needs emerge.

2026-08-06 16IDC Original 58 views
Advertisement

Buttons can look alike across pages while differing in color, disabled behavior and naming. Copying styles alone will not make them reusable. A design system defines visual values, component behavior and usage; a component library implements them, and Storybook can show states without automatically testing them or synchronizing design files.

Start with a button needed on a real page, agree on tokens and its interface, then inspect its normal and disabled stories. This example assumes an existing React, Vite and npm project; other frameworks require a different component and Storybook adapter.

From Tokens to Component Responsibilities

The diagram shows code-side dependencies. Keeping design files aligned with code still requires an agreed source, review and synchronization process.

Token to component dependency flow Base values Semantic tokens Button component Page and story Named by purpose; themes can override Stories show states; tests need setup Source: example dependencies, not an automatic sync
Figure 1: Token to component dependency flow (Source: example dependencies, not an automatic sync)
Deliverable Agreement Check
Tokens Base colors and purpose-named semantic colors Inspect computed styles and contrast after theme overrides
Component Props, defaults, disabled state and keyboard behavior Exercise it in the application and in stories
Docs and tests Appropriate use, states and configured checks Inspect stories; run tests separately and inspect results

For example, --color-action names an action background whose base value may come from a brand color. CSS custom properties follow the cascade and normally inherit; a theme override must apply to an ancestor of the component. See MDN's custom properties guide, accessed 2026-11-28.

Create a Checkable Button

Put the following two files in the same directory of an existing React project. Create Button.js first; the colors and dimensions are examples, so check contrast against the actual foreground, background and focus styles before use.

import React from 'react';
import './button.css';

export function Button({ label, disabled = false, onClick }) {
  return React.createElement(
    'button',
    { type: 'button', className: 'button', disabled, onClick },
    label
  );
}

The component uses a native button instead of simulating keyboard semantics. Render it in a page and inspect the element: it should contain type="button" and the label. A disabled button should not invoke its click handler; the caller supplies the real business callback.

Create button.css alongside it:

:root {
  --blue-700: #1d4ed8;
  --color-action: var(--blue-700);
  --color-action-text: #ffffff;
  --space-control: 0.75rem;
}
.button {
  padding: var(--space-control);
  color: var(--color-action-text);
  background: var(--color-action);
}
.button:focus-visible { outline: 3px solid #111111; outline-offset: 2px; }
.button:disabled { opacity: 0.6; }

Select the button in browser developer tools and inspect Computed styles for the resolved background and padding. If missing, check the CSS import, selector and variable scope. Use Tab to focus and Enter or Space to exercise the handler; verify disabled and focus states with the actual browser, assistive technology and page background. See the WAI-ARIA button pattern.

Record States in Storybook

As checked on 2026-11-28, the current Storybook installation guide lists Node.js 20+, npm 10+ and Vite 5+; its React Vite adapter requires React 16.8+. These are requirements for that documentation version, not guarantees for every future version; check your project and its dependencies too.

At the root of an existing React/Vite project, commit or back up your work and confirm that dependencies and configuration may be changed. Then run the interactive setup:

npm create storybook@latest
npm run storybook

Initialization installs dependencies and changes project files; latest changes over time. Select the needed features, then open the local address printed by the server. If the script is absent or startup fails, inspect the setup output, Node version and project framework. Use git diff to review changes before and after setup rather than overwriting existing configuration. Skip initialization if the project already has Storybook.

Create Button.stories.js next to Button.js and ensure the stories pattern in .storybook/main includes that directory:

import { Button } from './Button';

export default {
  title: 'Core/Button',
  component: Button,
};

export const Default = { args: { label: 'Save' } };
export const Disabled = { args: { label: 'Save', disabled: true } };

Restart or refresh Storybook and select the two stories under Core/Button: one should be enabled and the other disabled. If they are missing, check the story glob and import path; if styles are missing, check the CSS import. The CSF guide explains the default export and named stories.

A story is a reusable state, not a test. Configure interaction or accessibility checks separately, define assertions and run them locally or in CI. Manual keyboard and screen-reader checks remain valuable because automated checks cannot cover every accessibility issue.

Maintain the System

Document the button's purpose, props, defaults and exclusions; use a link for navigation rather than a button. Include actual consumers in reviews: a new variant needs a concrete use case, and breaking interface changes need migration instructions. When publishing a package, check its dependency compatibility ranges as well.

Tokens can initially live in code. If a design tool exports JSON for conversion to CSS, agree on the format, converter version, build command and sync owner. Generation follows its input; it does not automatically keep design files, code and deployed pages in agreement.

Limitations

  • The example covers basic button states, not loading, icon labeling, complete theming or cross-browser accessibility acceptance.
  • Initialization changes project files. Review dependencies and configuration in a branch or backup before retaining changes; restore selectively from the saved version without overwriting others' work.

FAQ

Does an existing component library need design tokens?

It does not necessarily need a separate token build pipeline. If several components reuse a semantic color or spacing value, start with CSS variables and document the override scope. Evaluate a shared format and generator when there is an actual multi-platform or design-file synchronization need.

Does a working story prove the application works?

No. The application can add different global styles, fonts, container sizes or business state. Check the component in the real application as well as in stories, including cascade, focus and interaction. If server rendering is involved, verify that environment separately.

When should a component get another variant?

Add one when multiple real uses need the same clearly named behavior. Keep a one-off decoration local to the page. A proposed variant should document its default, accessible states and any migration needed by existing consumers.

Related Providers

  • Storybook: inspect component states independently and organize stories.
  • Figma: collaborate on design files and visual decisions; code synchronization needs separate setup.
  • npm: distribute a versioned component package to multiple projects.

Community & Resources

Original source: 16IDC Original ↗