1+ ---
2+ description: This document provides instructions for generating Storybook stories for React components in the Social Bristol project.
3+ globs:
4+ alwaysApply: false
5+ ---
6+ ## File Structure
7+
8+ When generating a Storybook story for a React component, follow these conventions:
9+
10+ 1. The story file should be named `[ComponentName].stories.ts` and placed in the same directory as the component.
11+ 2. If the component uses TypeScript, use `.ts` extension; if it's using JavaScript with JSX, use `.tsx`.
12+
13+ ## Story Template
14+
15+ Use the following template for Storybook stories:
16+
17+ ```typescript
18+ import type { Meta, StoryObj } from '@storybook/react';
19+ import { MOCK_MOCK_DATA_CONSTANT } from '@/stories/mocks'; // Import appropriate mock data
20+ import ComponentName from './ComponentName';
21+
22+ const meta = {
23+ title: 'Components/[Category]/ComponentName',
24+ component: ComponentName,
25+ parameters: {
26+ layout: 'centered', // Use 'padded' for larger components like Maps
27+ },
28+ tags: ['autodocs'],
29+ argTypes: {
30+ // Define controls for each prop
31+ // Examples:
32+ // stringProp: { control: 'text' },
33+ // numberProp: { control: 'number' },
34+ // booleanProp: { control: 'boolean' },
35+ // objectProp: { control: 'object' },
36+ // arrayProp: { control: 'object' },
37+ // enumProp: { control: { type: 'select', options: ['option1', 'option2'] } },
38+ },
39+ args: {
40+ // Default args that apply to all stories
41+ },
42+ } satisfies Meta<typeof ComponentName>;
43+
44+ export default meta;
45+
46+ type Story = StoryObj<typeof meta>;
47+
48+ export const Default: Story = {
49+ args: {
50+ // Default story props, often sourced from mocks
51+ // Example: ...MOCK_DATA[0],
52+ },
53+ };
54+
55+ // Additional stories as needed
56+ export const Variation: Story = {
57+ args: {
58+ // Props for this variation
59+ },
60+ };
61+ ```
62+
63+ ## Categories
64+
65+ Categorize components appropriately in the `title` field:
66+
67+ - UI elements: `Components/UI/[ComponentName]`
68+ - Cards: `Components/Cards/[ComponentName]`
69+ - Layout: `Components/Layout/[ComponentName]`
70+ - Forms: `Components/Forms/[ComponentName]`
71+ - Maps: `Components/Maps/[ComponentName]`
72+ - Icons: `Components/Icons/[ComponentName]`
73+
74+ ## Mock Data
75+
76+ 1. Look for existing mock data in `src/stories/mocks.ts` that matches the component's props.
77+ 2. If appropriate mock data doesn't exist, consider adding new mock constants to the mocks file.
78+ 3. Mock data constants should be named using the pattern `MOCK_[PLURAL_ENTITY_NAME]`.
79+
80+ ## ArgTypes
81+
82+ Define appropriate controls for all component props:
83+
84+ - `string`: Use `{ control: 'text' }`
85+ - `number`: Use `{ control: 'number' }`
86+ - `boolean`: Use `{ control: 'boolean' }`
87+ - `object`: Use `{ control: 'object' }`
88+ - `enum/select`: Use `{ control: { type: 'select', options: [...] } }`
89+ - `date`: Use `{ control: 'date' }`
90+ - `color`: Use `{ control: 'color' }`
91+
92+ ## Story Variations
93+
94+ Create additional stories for different component states or configurations:
95+
96+ - Default state
97+ - Loading state (if applicable)
98+ - Error state (if applicable)
99+ - Different sizes or variants
100+ - With/without certain features enabled
101+
102+ ## Layout Parameter
103+
104+ Choose the appropriate layout parameter based on component size:
105+ - For small to medium components: `layout: 'centered'`
106+ - For larger components (like maps): `layout: 'padded'`
107+ - For full-width components: `layout: 'fullscreen'`
108+
109+ ## Example
110+
111+ Here's an example for an EventCard component:
112+
113+ ```typescript
114+ import type { Meta, StoryObj } from '@storybook/react';
115+ import { MOCK_EVENTS } from '@/stories/mocks';
116+ import EventCard from './EventCard';
117+
118+ const meta = {
119+ title: 'Components/Cards/EventCard',
120+ component: EventCard,
121+ parameters: {
122+ layout: 'centered',
123+ },
124+ tags: ['autodocs'],
125+ argTypes: {
126+ cost: { control: 'object' },
127+ time: { control: 'object' },
128+ location: { control: 'object' },
129+ locationURL: { control: 'text' },
130+ booking: { control: 'object' },
131+ link: { control: 'object' },
132+ gender: { control: 'text' },
133+ },
134+ args: {},
135+ } satisfies Meta<typeof EventCard>;
136+
137+ export default meta;
138+
139+ type Story = StoryObj<typeof meta>;
140+
141+ export const Default: Story = {
142+ args: { ...MOCK_EVENTS[0] },
143+ };
144+ ```
145+
146+ ## Workflow for AI Agent
147+
148+ When asked to create a Storybook story for a React component:
149+
150+ 1. Analyze the component file to understand its props and functionality
151+ 2. Check if appropriate mock data exists in `src/stories/mocks.ts`
152+ 3. Create the story file following the template above
153+ 4. Place the file in the same directory as the component
154+ 5. If needed, suggest adding new mock data to the mocks file
155+
156+ Remember to follow the naming conventions and categorize components appropriately.
0 commit comments