agentleFS
zeroasteriskzeroasterisk/skills/storybook/SKILL.md

storybook

Skill1 starsChanged 3 months agoApache-2.0View on GitHub

Write and test Storybook stories for React components. Use for component isolation, visual testing, and documentation.

8 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

7 rules. 0 are common, 4 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Create, test, and capture Storybook stories for React components.

    line 8
  2. Distinctive:

    Use Playwright to capture story screenshots:

    line 85
  3. Very specific:

    autodocs tag: Add tags: ['autodocs'] for auto-generated docs

    line 300
  4. Very specific:

    Args vs render: Use args for simple prop changes, render for complex setups

    line 301
  5. Very specific:

    Naming: Use ComponentName--VariantName format for story IDs

    line 302
  6. Distinctive:

    Mock API: Use MSW addon for mocking API calls in stories

    line 303
  7. Distinctive:

    Backgrounds: Add background switcher for light/dark mode testing

    line 305

“Common” is measured: kept by at least 6 in 10 of the 5 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 Skill

Create, test, and capture Storybook stories for React components.

When to Use This

  • Creating new React components that need isolation testing
  • Documenting component variants and states
  • Capturing visual snapshots for documentation
  • Testing responsive behavior across viewport sizes

Quick Start

1. Install Storybook (if not present)

cd frontend
npx storybook@latest init

2. Create a Story

For a component at src/components/Button.tsx:

// 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'],
    },
  },
};

export default meta;
type Story = StoryObj<typeof Button>;

export const Primary: Story = {
  args: {
    variant: 'primary',
    children: 'Click me',
  },
};

export const Secondary: Story = {
  args: {
    variant: 'secondary',
    children: 'Click me',
  },
};

export const Disabled: Story = {
  args: {
    variant: 'primary',
    children: 'Disabled',
    disabled: true,
  },
};

3. Run Storybook

npm run storybook
# or
bun storybook

Default: http://localhost:6006

4. Capture Screenshots

Use Playwright to capture story screenshots:

import asyncio
from playwright.async_api import async_playwright

async def capture_stories():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page(viewport={"width": 1280, "height": 720})
        
        # Navigate to specific story
        await page.goto("http://localhost:6006/iframe.html?id=components-button--primary")
        await page.wait_for_timeout(1000)
        await page.screenshot(path="button-primary.png")
        
        await browser.close()

asyncio.run(capture_stories())

Story Patterns

With Decorators (Providers, Theme)

const meta: Meta<typeof MyComponent> = {
  title: 'Components/MyComponent',
  component: MyComponent,
  decorators: [
    (Story) => (
      <ThemeProvider theme={lightTheme}>
        <Story />
      </ThemeProvider>
    ),
  ],
};

With Mock Data

export const WithData: Story = {
  args: {
    items: [
      { id: 1, name: 'Item 1' },
      { id: 2, name: 'Item 2' },
    ],
  },
};

export const Empty: Story = {
  args: {
    items: [],
  },
};

export const Loading: Story = {
  args: {
    loading: true,
  },
};

Responsive Stories

export const Mobile: Story = {
  args: { /* ... */ },
  parameters: {
    viewport: {
      defaultViewport: 'mobile1',
    },
  },
};

export const Tablet: Story = {
  args: { /* ... */ },
  parameters: {
    viewport: {
      defaultViewport: 'tablet',
    },
  },
};

With Actions

import { action } from '@storybook/addon-actions';

export const Interactive: Story = {
  args: {
    onClick: action('clicked'),
    onSubmit: action('submitted'),
  },
};

Play Functions (Interaction Testing)

import { within, userEvent } from '@storybook/testing-library';
import { expect } from '@storybook/jest';

export const Filled: Story = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
    
    await userEvent.type(
      canvas.getByRole('textbox', { name: /email/i }),
      'test@example.com'
    );
    
    await userEvent.click(canvas.getByRole('button', { name: /submit/i }));
    
    await expect(canvas.getByText('Success')).toBeInTheDocument();
  },
};

Storybook Configuration

.storybook/main.ts

import type { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
  stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/addon-interactions',
  ],
  framework: {
    name: '@storybook/react-vite',
    options: {},
  },
  docs: {
    autodocs: 'tag',
  },
};

export default config;

.storybook/preview.ts

import type { Preview } from '@storybook/react';
import '../src/index.css'; // Global styles

const preview: Preview = {
  parameters: {
    actions: { argTypesRegex: '^on[A-Z].*' },
    controls: {
      matchers: {
        color: /(background|color)$/i,
        date: /Date$/,
      },
    },
  },
};

export default preview;

Batch Screenshot Capture

#!/usr/bin/env python3
"""Capture all Storybook stories as screenshots."""

import asyncio
import json
from playwright.async_api import async_playwright

STORYBOOK_URL = "http://localhost:6006"

async def get_stories(page):
    """Fetch story list from Storybook."""
    await page.goto(f"{STORYBOOK_URL}/index.json")
    content = await page.content()
    # Parse JSON from page
    data = json.loads(await page.evaluate("() => document.body.innerText"))
    return [
        story_id for story_id, story in data.get("entries", {}).items()
        if story.get("type") == "story"
    ]

async def capture_all():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page(viewport={"width": 1280, "height": 720})
        
        stories = await get_stories(page)
        
        for story_id in stories:
            url = f"{STORYBOOK_URL}/iframe.html?id={story_id}&viewMode=story"
            await page.goto(url)
            await page.wait_for_timeout(500)
            
            filename = story_id.replace("--", "-").replace("/", "-")
            await page.screenshot(path=f"screenshots/{filename}.png")
            print(f"Captured: {story_id}")
        
        await browser.close()

if __name__ == "__main__":
    asyncio.run(capture_all())

Tips

  • autodocs tag: Add tags: ['autodocs'] for auto-generated docs
  • Args vs render: Use args for simple prop changes, render for complex setups
  • Naming: Use ComponentName--VariantName format for story IDs
  • Mock API: Use MSW addon for mocking API calls in stories
  • Viewport addon: Configure common viewports in preview.ts
  • Backgrounds: Add background switcher for light/dark mode testing

Integration with CUJ Screenshots

Storybook stories can be captured as part of CUJ workflows:

# In your CUJ script
await page.goto("http://localhost:6006/iframe.html?id=components-taskcard--default")
await page.screenshot(path="docs/screenshots/taskcard.png")

This gives you both isolated component shots and full-app journey shots.

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.