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.
Agent 可直接安装
这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install 2f0df676-3567-11f1-9bc6-00163e2b0d79 --target codex先 dry-run 确认安装计划,再运行此命令。
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.
常见问题
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.
引用来源 (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
讨论
相关资产
Naive UI — Complete Vue 3 Component Library with TypeScript
Naive UI is a fully tree-shakable Vue 3 component library written in TypeScript. It ships over 90 components with built-in dark mode, customizable theming, and first-class TypeScript support, making it a strong choice for building modern web applications.
GPUI Component — Rust GUI Components for Cross-Platform Desktop Apps
A high-performance Rust UI component library built on the GPUI framework, providing production-ready widgets for building native desktop applications.
PrimeReact — Feature-Complete React UI Component Suite
A rich set of 90+ open-source React UI components including data tables, charts, editors, and form controls with built-in themes and accessibility.
PrimeNG — Complete Angular UI Component Library
PrimeNG is a comprehensive collection of 80+ UI components for Angular, offering rich data tables, charts, form elements, and design themes for enterprise application development.