Storybook — UI Component Workshop for Building & Testing
Storybook is the industry-standard workshop for building, documenting, and testing UI components in isolation. Supports React, Vue, Svelte, Angular, and more — used by Airbnb, Shopify, GitHub, and thousands of teams.
What it is
Storybook is the industry-standard workshop for building, documenting, and testing UI components in isolation. It provides a sandbox where you develop components outside your application, see them in every possible state, and generate documentation automatically. Storybook supports React, Vue, Svelte, Angular, and Web Components.
Storybook targets frontend developers and design system teams who need to develop, review, and maintain UI components independently from application logic. Organizations like Airbnb, Shopify, and GitHub use it for their component libraries.
How it saves time or tokens
Storybook eliminates the need to navigate through your application to reach a specific UI state. Instead of clicking through five screens to test a loading state or error message, you render the component directly with the props you need. Visual regression testing catches unintended style changes before they reach production. Auto-generated documentation reduces the maintenance burden of keeping a style guide in sync with code.
How to use
- Add Storybook to your project:
npx storybook@latest init
npm run storybook
- Write a story for your component:
// Button.stories.tsx
import type { Meta, StoryObj } from '@storybook/react';
import { Button } from './Button';
const meta: Meta<typeof Button> = {
component: Button,
args: { label: 'Click me' },
};
export default meta;
type Story = StoryObj<typeof Button>;
export const Primary: Story = {
args: { variant: 'primary' },
};
export const Disabled: Story = {
args: { variant: 'primary', disabled: true },
};
- Open the Storybook UI to see your component in all defined states.
Example
A complete story with interaction testing:
import { within, userEvent, expect } from '@storybook/test';
export const ClickTest: Story = {
args: { label: 'Submit', onClick: fn() },
play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByRole('button'));
await expect(args.onClick).toHaveBeenCalledOnce();
},
};
The play function runs automated interaction tests inside the story, verifying component behavior visually.
Related on TokRepo
- AI Tools for Design — Design tools for creating and maintaining component libraries
- AI Tools for Testing — Testing tools for visual regression and component testing
Common pitfalls
- Storybook adds build time to your project. Use lazy loading and targeted builds (--filter) to keep development startup fast.
- Stories should cover edge cases (empty data, long text, error states), not just the happy path. Under-specified stories miss bugs.
- Storybook configuration files (.storybook/main.ts) can become complex with addons. Start minimal and add addons only as needed.
Frequently Asked Questions
Storybook supports React, Vue, Svelte, Angular, Web Components, and more. Each framework has a dedicated renderer that integrates with the framework's component model and tooling.
Yes. Storybook's autodocs feature generates documentation pages from your stories and component prop types. JSDoc comments on props appear as descriptions in the generated docs.
Storybook integrates with visual testing tools like Chromatic. It captures screenshots of each story and compares them against baselines. Any visual difference is flagged for review before merging.
Yes. The play function in stories lets you automate user interactions (clicks, typing, navigation) and assert expected outcomes. These tests run in the browser and provide visual feedback.
Yes. Storybook is the standard tool for design system development. It provides component isolation, auto-generated documentation, visual testing, and a shareable UI that designers and developers can review together.
Citations (3)
- Storybook GitHub— Storybook is the industry-standard UI component workshop
- Storybook Documentation— Support for React, Vue, Svelte, Angular and more
- Chromatic— Visual regression testing with Chromatic
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.