Storybook
nhan03bit2026-10-28查看 1463复制 1790
用于隔离构建、测试和文档化组件的 UI 组件开发环境
📘如何使用这个技能
- 1复制技能内容·点击上方「Copy SKILL.md」复制全部内容,或 Download 下载到本地
- 2打开你的 AI 客户端·支持 Claude Code、Trae、Cursor、ChatGPT、DeepSeek、Kimi 等任意 AI 助手
- 3粘贴为系统提示/知识文件·Claude Code:放入 .claude/skills/ 目录;普通对话:作为首条消息发送并说「请严格按这份技能文档执行」
- 4直接提出你的需求·AI 会按技能定义的工作流、格式和约束来处理,无需再解释背景
💡 提示:技能生效后,每次对话只需一句需求,AI 会按 SKILL.md 的流程执行。
SKILL.md2644 chars
---
name: storybook
description: UI component development environment for building, testing, and documenting components in isolation
layer: domain
category: documentation
triggers:
- "storybook"
- "component story"
- "CSF"
- "visual testing"
- "chromatic"
linksTo: [react, design-systems, testing-patterns, tailwindcss]
linkedFrom: [code-writer, code-reviewer]
riskLevel: low
memoryReadPolicy: selective
memoryWritePolicy: none
sideEffects: []
---
# Storybook
UI component development environment for building, testing, and documenting components in isolation. Enables interactive exploration via args/controls, interaction testing with play functions, and visual regression via Chromatic.
## When to Use
- Building/documenting UI components in isolation outside the app
- Running interaction tests on individual components
- Visual regression testing in CI with Chromatic
- Establishing a shared component library across teams
## Key Patterns
**CSF3** — Default export for metadata, named exports for stories:
```tsx
const meta = { component: Button, tags: ['autodocs'] } satisfies Meta<typeof Button>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Primary: Story = { args: { variant: 'primary', children: 'Click me' } };
```
**Args & Controls** — Expose props as interactive knobs via `argTypes`.
**Decorators** — Wrap with providers/theme: `decorators: [(Story) => <Provider><Story /></Provider>]`
**Play Functions** — Interaction tests using `@storybook/test`:
```tsx
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.type(canvas.getByRole('textbox'), 'hello');
await expect(canvas.getByRole('button')).toBeEnabled();
}
```
**Autodocs** — `tags: ['autodocs']` on meta for automatic documentation pages.
**Add-ons** — `addon-a11y`, `addon-viewport`, `addon-backgrounds`, `addon-actions`.
**Chromatic** — Visual regression in CI. Exclude with `chromatic: { disableSnapshot: true }`.
**MSW** — Mock APIs per-story via `parameters.msw.handlers`.
**Composition** — Import from other Storybook instances via `refs` in `.storybook/main.ts`.
## Anti-Patterns
| Anti-Pattern | Fix |
|---|---|
| Implementation details in play functions | Query by role/label, assert visible behavior |
| One mega-story with all variants | One story per meaningful state |
| Skipping autodocs tags | Add `tags: ['autodocs']` by default |
| Hardcoded data without args | Define args and argTypes on meta |
| App-level providers imported globally | Scope decorators per-story or per-meta |
## Related Skills
`react` | `design-systems` | `testing-patterns` | `tailwindcss`