storybook

v2026.09.24

Use whenever creating, configuring, or extending Storybook for a TS/React component library — covers main.ts/preview.ts setup, CSF3 story authoring, args/argTypes/controls, decorators and providers, MSW and module mocking, play-function interaction tests via the Vitest addon, the @storybook/addon-a11y workflow (axe-core), autodocs vs MDX docs, design tokens, Figma linking, Chromatic deployment, and on-demand build performance. Triggers on tasks like "write a story", "set up Storybook", "configure addon-a11y", "fix this play function", "deploy Storybook", "test Storybook in CI" — even when the user doesn't say "storybook" but is editing `*.stories.tsx`, `.storybook/main.ts`, or `.storybook/preview.ts`. Targets Storybook 9+/10 (modern `storybook/test` import, Vitest addon, CSF3 + `satisfies Meta`). Does NOT cover generic React patterns (use the `react` skill), generic Testing Library queries (use `react-testing-library`), or WCAG primer (points at addon-a11y + axe rule config).

GitHub
安装命令
npx skhub add pproenca/storybook
Markdown
SKILL.md

dot-skills Storybook Best Practices

Comprehensive guide for using Storybook 9+ as the workshop and test bench for a TypeScript/React component library. 52 rules across 8 categories, ordered by the lifecycle of a component in your design system: a wrong .storybook/main.ts cascades into every story; a malformed CSF Meta blocks autodocs, controls, tests, and the a11y panel for that file.

What this skill covers

  1. Setup — main.ts, preview.ts, framework selection (Vite vs Webpack, Next.js vs React-only), addon installation via the CLI, staticDirs.
  2. Story authoring (CSF3) — satisfies Meta<typeof Component>, named exports = stories, tags: ['autodocs'] placement, when render is appropriate, story naming conventions.
  3. Args, argTypes, controls — when to rely on inference, when to declare control: 'select', fn() from storybook/test for callbacks, args vs parameters vs globals.
  4. Decorators & composition — global providers in preview.ts, MSW for network mocks, subpath-import module mocking (Storybook 9+), decorator signature pitfalls.
  5. Interaction testing — play functions, the storybook/test import path (NOT @storybook/test), destructured canvas/userEvent, findBy* over waitFor, addon-vitest for CI, portable stories.
  6. Accessibility (axe-core via @storybook/addon-a11y) — parameters.a11y.test = 'error' as a real gate, per-rule disables, runOnly scoped to your WCAG target, portal context, globals.a11y.manual for intentional-violation fixtures.
  7. Documentation & design system — autodocs vs MDX, MDX referencing stories with <Canvas of={...} />, status tags, design tokens as stories, Figma links via parameters.design.
  8. Build & deployment — Vite over Webpack, on-demand bundling for large libraries, deploy to Chromatic/Vercel for designer review, CI cache configuration.

When to Apply

Reach for this skill when:

  • Editing or creating a *.stories.tsx, *.mdx, .storybook/main.ts, .storybook/preview.ts, or vitest.config.ts that loads storybookTest.
  • Setting up Storybook on a new project (framework choice, npx storybook init follow-up).
  • Adding or upgrading an addon (a11y, vitest, designs, msw).
  • Wiring component tests through play functions and the Vitest addon.
  • Investigating "Storybook is slow", "controls show text instead of select", "a11y panel shows nothing for my dialog", "play function is flaky in CI".

Skip this skill and use:

  • react-optimise / clean-code-ts-react for the underlying component design.
  • react-testing-library for render/screen/userEvent semantics outside Storybook.
  • WCAG/ARIA reference docs for the spec itself; this skill assumes you know what aria-labelledby does and tells you how addon-a11y checks it.

Rule Categories by Priority

Order reflects the component lifecycle (configure → author → wire → decorate → test → audit → document → ship). Earlier stages cascade.

PriorityCategoryImpactPrefixRules
1Setup & ConfigurationCRITICALconfig-8
2Story Authoring (CSF3)CRITICALcsf-8
3Args, ArgTypes & ControlsHIGHargs-5
4Decorators & CompositionHIGHdeco-7
5Interaction TestingHIGHtest-7
6Accessibility (axe)HIGHaxe-5
7Documentation & Design SystemMEDIUM-HIGHdocs-5
8Build, Performance & DeploymentMEDIUMbuild-7

Quick Reference

1. Setup & Configuration (CRITICAL)

2. Story Authoring — CSF3 (CRITICAL)

3. Args, ArgTypes & Controls (HIGH)

4. Decorators & Composition (HIGH)

5. Interaction Testing (HIGH)

6. Accessibility — axe (HIGH)

7. Documentation & Design System (MEDIUM-HIGH)

8. Build, Performance & Deployment (MEDIUM)

How to use

  • Start with references/_sections.md for the category structure and impact rationale.
  • For "I'm setting up Storybook," read all config- rules then csf-.
  • For "I'm writing a new story," read csf- and args-.
  • For "I want tests on my stories," read test- and deco-msw-for-network-mocks.
  • For "I want a11y to fail CI on violations," read all axe- rules.
  • For "I'm building a design system from scratch," read in this order: config-tokens-css-vars-in-preview, config-story-sort-for-large-libraries, csf-title-hierarchy-for-design-systems, deco-themes-addon-for-multi-brand, build-manager-brand, build-chromatic-modes-multi-theme. Then docs-component-status-tags and docs-design-tokens-as-stories for the governance + token-display layer.
  • For "I have a multi-package monorepo design system," read build-storybook-composition-refs first, then the design-system path above.
  • For "I need RTL / multi-direction coverage," read deco-rtl-direction-toggle then build-chromatic-modes-multi-theme to wire RTL into visual regression.
  • For gotchas.md: failure modes discovered over time; always check before debugging an obscure issue.
  • Add new rules using assets/templates/_template.md.

Reference files

FileDescription
references/_sections.mdCategory definitions and ordering
assets/templates/_template.mdTemplate for adding new rules
gotchas.mdFailure modes accumulated over time
metadata.jsonVersion, references, abstract

Related skills

  • clean-code-ts-react — Underlying component design quality (naming, function shape, abstraction).
  • react-testing-library — RTL queries and patterns when used outside Storybook.
  • web-interface-guidelines — Vercel Web Interface Guidelines for the components you're documenting.
发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

Sep 24, 2026

分类

未分类

许可证

MIT

源路径

skills/.experimental/storybook

默认分支

master

最新提交

cf93c57

Tree SHA

afbb575