agentleFS
MindrallyMindrally/skills/storybook/SKILL.md

storybook

Skill275 starsChanged 35 days agoApache-2.0View on GitHub

Best practices for building and documenting component libraries with Storybook

11 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

29 rules. 0 are common, 28 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 9 edited versions we read keep these.

  • 28

    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:

    Place stories alongside component files (Component.stories.tsx)

    line 17
  2. Distinctive:

    Use consistent naming conventions for story files

    line 18
  3. Distinctive:

    Use PascalCase for component story files

    line 24
  4. Distinctive:

    Use descriptive story names that explain the variant

    line 27
  5. Distinctive:

    Create a Default story showing primary usage

    line 67
  6. Distinctive:

    Add stories for each significant variant

    line 68
  7. Distinctive:

    Document interactive states (hover, focus, disabled)

    line 70
  8. Distinctive:

    Write clear JSDoc comments for components and props

    line 78
  9. Distinctive:

    Document prop types, defaults, and requirements

    line 79
  10. Distinctive:

    Add MDX files for complex documentation needs

    line 84
  11. Distinctive:

    Use meaningful default values

    line 118
  12. Distinctive:

    Use decorators for consistent story wrappers

    line 137
  13. Distinctive:

    Add layout containers when needed

    line 139
  14. Distinctive:

    Keep decorators simple and reusable

    line 140
  15. Distinctive:

    Test theme variations (light/dark mode)

    line 183
  16. Distinctive:

    Document visual test coverage

    line 184
  17. Distinctive:

    Test keyboard navigation in stories

    line 190
  18. Distinctive:

    Import design tokens from your token system

    line 226
  19. Distinctive:

    Document token usage in component docs

    line 228
  20. Distinctive:

    Create stories for each theme variant

    line 234
  21. Distinctive:

    Test components across all supported themes

    line 235
  22. Distinctive:

    Use lazy loading for large story collections

    line 242
  23. Distinctive:

    Avoid heavy computations in stories

    line 249
  24. Distinctive:

    Use mock data efficiently

    line 250
  25. Distinctive:

    Write stories that serve as living documentation

    line 256
  26. Distinctive:

    Test components in isolation before integration

    line 257
  27. Distinctive:

    Keep stories simple and focused

    line 258
  28. Distinctive:

    Update stories when components change

    line 260
  29. Distinctive:

    Use stories for design review and QA

    line 261

“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 Best Practices

You are an expert in building and documenting component libraries with Storybook. Apply these guidelines when creating stories, organizing components, and maintaining design systems.

Project Structure

Directory Organization

  • Place stories alongside component files (Component.stories.tsx)
  • Use consistent naming conventions for story files
  • Organize stories by feature or component type
  • Maintain a clear hierarchy matching your component library

File Naming

  • Use PascalCase for component story files
  • Follow pattern: ComponentName.stories.tsx
  • Group related stories in the same file
  • Use descriptive story names that explain the variant

Writing Stories

Story Structure

import type { Meta, StoryObj } from '@storybook/react';
import { Component } from './Component';

const meta: Meta<typeof Component> = {
  title: 'Category/Component',
  component: Component,
  parameters: {
    layout: 'centered',
  },
  tags: ['autodocs'],
  argTypes: {
    // Define arg types here
  },
};

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

export const Default: Story = {
  args: {
    // Default props
  },
};

export const Variant: Story = {
  args: {
    variant: 'secondary',
  },
};

Story Best Practices

  • Create a Default story showing primary usage
  • Add stories for each significant variant
  • Include edge cases and error states
  • Document interactive states (hover, focus, disabled)
  • Show responsive behavior when relevant

Component Documentation

Autodocs

  • Enable autodocs for automatic documentation generation
  • Write clear JSDoc comments for components and props
  • Document prop types, defaults, and requirements
  • Include usage examples in component comments

Custom Documentation

  • Add MDX files for complex documentation needs
  • Include design rationale and usage guidelines
  • Document accessibility considerations
  • Provide code examples for common use cases

Args and Controls

ArgTypes Configuration

argTypes: {
  variant: {
    control: 'select',
    options: ['primary', 'secondary', 'tertiary'],
    description: 'Visual style variant',
    table: {
      defaultValue: { summary: 'primary' },
    },
  },
  size: {
    control: 'radio',
    options: ['sm', 'md', 'lg'],
  },
  disabled: {
    control: 'boolean',
  },
  onClick: {
    action: 'clicked',
  },
}

Args Best Practices

  • Use meaningful default values
  • Group related args logically
  • Provide descriptions for complex props
  • Set up actions for callback props

Decorators and Parameters

Decorators

decorators: [
  (Story) => (
    <ThemeProvider theme={defaultTheme}>
      <Story />
    </ThemeProvider>
  ),
],
  • Use decorators for consistent story wrappers
  • Apply theme providers at the appropriate level
  • Add layout containers when needed
  • Keep decorators simple and reusable

Parameters

parameters: {
  layout: 'centered', // or 'fullscreen', 'padded'
  backgrounds: {
    default: 'light',
    values: [
      { name: 'light', value: '#ffffff' },
      { name: 'dark', value: '#1a1a1a' },
    ],
  },
  viewport: {
    defaultViewport: 'responsive',
  },
},

Testing with Storybook

Interaction Testing

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

export const Clickable: Story = {
  play: async ({ canvasElement }) => {
    const canvas = within(canvasElement);
    const button = canvas.getByRole('button');

    await userEvent.click(button);
    await expect(button).toHaveFocus();
  },
};

Visual Testing

  • Configure visual regression testing
  • Capture stories at multiple viewports
  • Test theme variations (light/dark mode)
  • Document visual test coverage

Accessibility Testing

  • Enable a11y addon for accessibility checks
  • Address all accessibility violations
  • Test keyboard navigation in stories
  • Document ARIA requirements

Addons and Configuration

Essential Addons

  • @storybook/addon-essentials (docs, controls, actions, viewport)
  • @storybook/addon-a11y for accessibility testing
  • @storybook/addon-interactions for interaction testing
  • @storybook/addon-designs for design spec integration

Configuration

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

export default config;

Design System Integration

Design Tokens

  • Import design tokens from your token system
  • Apply tokens consistently in stories
  • Document token usage in component docs
  • Show token variations in dedicated stories

Theme Support

  • Configure theme provider in preview.js
  • Create stories for each theme variant
  • Test components across all supported themes
  • Document theme-specific behavior

Performance

Build Optimization

  • Use lazy loading for large story collections
  • Optimize static assets
  • Configure proper caching
  • Monitor and improve build times

Story Performance

  • Avoid heavy computations in stories
  • Use mock data efficiently
  • Lazy load complex dependencies
  • Profile and optimize slow stories

Best Practices Summary

  • Write stories that serve as living documentation
  • Test components in isolation before integration
  • Keep stories simple and focused
  • Maintain consistency across all stories
  • Update stories when components change
  • Use stories for design review and QA
  • Make accessibility testing part of the workflow
  • Integrate with your CI/CD pipeline

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.