Skills2026年4月11日·1 分钟阅读

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 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
step-1.md
直接安装命令
npx -y tokrepo@latest install 2f0df676-3567-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

TL;DR
Industry-standard workshop for developing UI components in isolation. Supports React, Vue, Svelte, Angular, and more.
§01

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.

§02

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.

§03

How to use

  1. Add Storybook to your project:
npx storybook@latest init
npm run storybook
  1. 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 },
};
  1. Open the Storybook UI to see your component in all defined states.
§04

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.

§05

Related on TokRepo

§06

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.

常见问题

What frameworks does Storybook support?+

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.

Can Storybook generate documentation automatically?+

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.

How does visual regression testing work in Storybook?+

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.

Can I test component interactions in Storybook?+

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.

Is Storybook suitable for design system teams?+

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)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产