Skip to content

Commit ce01e7f

Browse files
authored
Merge pull request #24 from jhancock532/utopia-clean-up
Utopia & South Bristol Chess
2 parents 2f98eab + cddbe16 commit ce01e7f

File tree

22 files changed

+524
-1053
lines changed

22 files changed

+524
-1053
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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.

.cursor/rules/NewComponent.mdc

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
description: This rule provides instructions for creating a new React component in the Social Bristol project.
3+
globs:
4+
alwaysApply: false
5+
---
6+
When asked to create a new component, the AI will:
7+
8+
1. Create a new directory for the component at `src/components/[ComponentName]`
9+
2. Create all required files with appropriate boilerplate code
10+
3. Implement any specified functionality or props
11+
4. Add appropriate styling
12+
13+
## Required Information
14+
15+
When requesting a new component, the user should provide:
16+
- Component name (in PascalCase, e.g., "UserCard")
17+
- Component purpose/functionality
18+
- Props the component should accept (if any)
19+
20+
## Standard File Structure
21+
22+
The AI will create these files for each component:
23+
24+
```
25+
src/components/[ComponentName]/
26+
├── [ComponentName].tsx
27+
├── [ComponentName].module.scss
28+
├── [ComponentName].stories.ts
29+
├── index.ts
30+
└── tests/
31+
└── [ComponentName].visual.spec.ts
32+
```
33+
34+
## File Templates
35+
36+
### [ComponentName].tsx
37+
```tsx
38+
import React from 'react';
39+
import styles from './[ComponentName].module.scss';
40+
41+
export const [ComponentName] = () => {
42+
return (
43+
<div className={styles.container}>
44+
{/* Component content goes here */}
45+
</div>
46+
);
47+
};
48+
```
49+
50+
### [ComponentName].module.scss
51+
```scss
52+
.container {
53+
// Component styles go here
54+
}
55+
```
56+
57+
### index.ts
58+
```ts
59+
import { [ComponentName] } from './[ComponentName]';
60+
61+
export default [ComponentName];
62+
```
63+
64+
### [ComponentName].stories.ts
65+
```ts
66+
import type { Meta, StoryObj } from '@storybook/react';
67+
import { [ComponentName] } from './[ComponentName]';
68+
69+
const meta = {
70+
title: 'Components/[ComponentName]',
71+
component: [ComponentName],
72+
parameters: {
73+
layout: 'centered',
74+
},
75+
tags: ['autodocs'],
76+
argTypes: {
77+
// Define prop controls here
78+
},
79+
args: {
80+
// Define default args here
81+
},
82+
} satisfies Meta<typeof [ComponentName]>;
83+
84+
export default meta;
85+
86+
type Story = StoryObj<typeof meta>;
87+
88+
export const Default: Story = {};
89+
```
90+
91+
### tests/[ComponentName].visual.spec.ts
92+
```ts
93+
import { test, expect } from '@playwright/test';
94+
95+
test('visual regression', async ({ page }) => {
96+
await page.goto(
97+
'/iframe.html?args=&id=components-[component-name]--default',
98+
);
99+
100+
await expect(page.locator('#storybook-root')).toHaveScreenshot(
101+
'[component-name].png',
102+
);
103+
});
104+
```

0 commit comments

Comments
 (0)