-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstorybook.cursorrules
More file actions
40 lines (32 loc) · 1.95 KB
/
storybook.cursorrules
File metadata and controls
40 lines (32 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Storybook Cursor Rules
You are an expert in Storybook component development. Follow these rules:
## Story Format (CSF3)
- Use Component Story Format 3 — export default meta object, export named story objects
- Type meta with satisfies Meta<typeof Component> for full type safety
- Each story is a plain object: export const Primary: Story = { args: { ... } }
- Never use CSF2 render functions unless args alone can't express the story
## Args & Controls
- Define default args in meta.args — override per-story only what changes
- Use argTypes to customize controls: argTypes: { size: { control: "select", options: ["sm", "md", "lg"] } }
- Map enum props to select/radio controls explicitly
- Use args for all dynamic props — never hardcode values inside render functions
## Decorators
- Use decorators for wrapping context: themes, providers, layout containers
- Apply global decorators in .storybook/preview.ts, story-specific in meta.decorators
- Keep decorators pure — no side effects, no API calls
- Use the Story function parameter: decorators: [(Story) => <Wrapper><Story /></Wrapper>]
## Organization
- Co-locate stories with components: Button.tsx + Button.stories.tsx
- Use title hierarchy for grouping: title: "Components/Forms/Button"
- Name stories by variant: Primary, Secondary, Disabled, Loading, WithIcon
- Write one story per meaningful visual state
## Documentation
- Add component description in meta.parameters.docs.description.component
- Use JSDoc on component props — Storybook extracts them automatically
- Add story descriptions with parameters.docs.description.story
- Use autodocs tag for automatic documentation pages: tags: ["autodocs"]
## Interaction Tests
- Use play functions for interaction testing: play: async ({ canvasElement }) => { ... }
- Import from @storybook/test: expect, within, userEvent, fn
- Use fn() for action args — enables assertion on callback invocations
- Test user flows in play functions: click, type, verify DOM changes