agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/testing/storybook/SKILL.md

storybook

Skill15 starsChanged 43 days agoMITView on GitHub

Expert Storybook component workshop assistance covering CSF 3 stories, args, controls, and visual regression. Use when developing isolated UI components, building design systems, or documenting frontend widgets.

11 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use CSF 3 with args and play function testing:

    line 132
  2. Distinctive:

    Use Mock Service Worker (MSW): Mock API backends to enable stories to render realistic asynchronous states.

    line 165
  3. Distinctive:

    Import application routers or global state in components: Pass callbacks and state down as props to keep components isolated.

    line 169

“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Storybook

Storybook is a frontend workshop for building UI components and pages in isolation. It enables you to develop UI components without running your entire app (and logic/APIs).

When to Use

  • Isolated UI Component Development: Developing React, Vue, Svelte, or Angular components in isolation without launching backends.
  • Interactive Design System Documentation: Publishing living styleguides and component catalogs for designer and developer handoff.
  • Visual Regression Testing: Detecting unexpected visual pixel shifts across browser viewports with Chromatic.
  • Accessibility (a11y) Auditing: Automated component accessibility testing via the @storybook/addon-a11y plugin.

Quick Start

npx storybook@latest init
npm run storybook

Snippet:

// Button.stories.tsx
import type { Meta, StoryObj } from "@storybook/react";
import { Button } from "./Button";

const meta: Meta<typeof Button> = {
  component: Button,
};
export default meta;

type Story = StoryObj<typeof Button>;

export const Primary: Story = {
  args: {
    primary: true,
    label: "Button",
  },
};

Core Concepts

Component Story Format (CSF 3)

Defines component variants using declarative, typed JavaScript exports:

// src/components/Button.stories.tsx
import type { Meta, StoryObj } from "@storybook/react";
import { Button } from "./Button";

const meta: Meta<typeof Button> = {
  title: "Components/Button",
  component: Button,
  tags: ["autodocs"],
  argTypes: {
    variant: { control: "select", options: ["primary", "secondary", "danger"] },
    onClick: { action: "clicked" },
  },
};
export default meta;

type Story = StoryObj<typeof Button>;

export const Primary: Story = {
  args: {
    variant: "primary",
    label: "Confirm Payment",
  },
};

export const Disabled: Story = {
  args: {
    variant: "primary",
    label: "Processing...",
    disabled: true,
  },
};

Component Interaction Testing (play Function)

Simulates user interactions inside the story using Testing Library and asserts on outcomes:

import { within, userEvent, expect } from "@storybook/test";

export const InteractiveLoginForm: Story = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
    await userEvent.type(canvas.getByLabelText(/email/i), "alice@example.com");
    await userEvent.type(canvas.getByLabelText(/password/i), "Secret123!");
    await userEvent.click(canvas.getByRole("button", { name: /log in/i }));

    await expect(canvas.getByText(/dashboard/i)).toBeInTheDocument();
  },
};

Mocking API Calls with MSW Addon

Intercepts component network requests inside the Storybook canvas:

import { http, HttpResponse } from "msw";

export const LoadedUserProfile: Story = {
  parameters: {
    msw: {
      handlers: [
        http.get("/api/user", () =>
          HttpResponse.json({ name: "Alice", role: "Admin" }),
        ),
      ],
    },
  },
};

Common Patterns

Interactive Story with Controls and Play Function

Problem: Static component stories do not verify whether clicks and state transitions function properly.

Solution: Use CSF 3 with args and play function testing:

import type { Meta, StoryObj } from "@storybook/react";
import { userEvent, within, expect } from "@storybook/test";
import { LoginForm } from "./LoginForm";

const meta: Meta<typeof LoginForm> = {
  title: "Components/LoginForm",
  component: LoginForm,
};
export default meta;

type Story = StoryObj<typeof LoginForm>;

export const ValidSubmission: Story = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
    await userEvent.type(canvas.getByLabelText(/email/i), "user@test.com");
    await userEvent.type(canvas.getByLabelText(/password/i), "secret123");
    await userEvent.click(canvas.getByRole("button", { name: /submit/i }));
    await expect(canvas.getByText(/welcome/i)).toBeInTheDocument();
  },
};

Best Practices

Do:

  • Adopt CSF 3 Standard: Use object-based CSF 3 stories for cleaner syntax and reduced boilerplate.
  • Enable @storybook/addon-a11y: Catch WCAG accessibility violations directly inside the component development workflow.
  • Automate Visual Testing with Chromatic: Capture regression snapshots of all stories on every pull request.
  • Use Mock Service Worker (MSW): Mock API backends to enable stories to render realistic asynchronous states.

Don't:

  • Import application routers or global state in components: Pass callbacks and state down as props to keep components isolated.
  • Hardcode static story args: Leverage Storybook controls (args) to allow designers to test edge-case content lengths.
  • Neglect loading and error states: Create dedicated stories for loading skeletons, empty data, and network error states.

Troubleshooting

ErrorCauseSolution
Cannot find module in .storybook/previewPath alias or CSS import not recognized by Storybook builder.Add path aliases to .storybook/main.ts webpackFinal or viteFinal.
No stories foundStories glob pattern in main.ts does not match component file paths.Verify stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'] in config.
Component won't render: hook called outside componentDecorator missing required React context or router provider.Wrap story with appropriate context provider in preview decorators.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.