@@ -12,20 +12,17 @@ UI components.
1212
1313## Common Development Commands
1414
15- ### Development and Testing
16-
17- - ` yarn start ` or ` yarn storybook ` - Start Storybook dev server on port 6006
18- - ` yarn test ` - Run unit tests with Vitest
19- - ` yarn test:ci ` - Run tests with coverage for CI
20- - ` yarn test:a11y ` - Run accessibility tests via Storybook
21-
2215### Building and Quality Checks
2316
2417- ` yarn build ` - Build the library for distribution
25- - ` yarn lint ` - Run ESLint and TypeScript checks
26- - ` yarn lint:eslint ` - Run ESLint only
27- - ` yarn lint:tsc ` - Run TypeScript type checking only
2818- ` yarn format ` - Format code with Prettier
19+ - ` yarn lint ` - Run ESLint and TypeScript checks
20+
21+ ### Key Testing Commands
22+
23+ - ` yarn test run ComponentName ` - Run specific component tests
24+ - ` yarn test run ComponentName -u ` - Update snapshots if needed
25+ - ` yarn test:a11y ` - Run accessibility tests via Storybook
2926
3027### Storybook
3128
@@ -41,160 +38,17 @@ Note: The Vitest configuration uses the modern `test.projects` field in
4138` vite.config.ts ` for workspace configuration, replacing the deprecated
4239` vitest.workspace.ts ` file.
4340
44- ## Architecture and Code Structure
45-
46- ### Directory Structure
47-
48- ```
49- lib/
50- ├── components/ # All UI components
51- ├── hooks/ # Reusable React hooks
52- ├── styles/ # Vanilla Extract styling system
53- ├── themes/ # Design tokens and themes
54- ├── utils/ # Utility functions
55- └── types/ # TypeScript type definitions
56- ```
57-
58- ### Component Architecture
59-
60- Components follow a consistent structure:
61-
62- ```
63- lib/components/ComponentName/
64- ├── ComponentName.tsx # Component logic
65- ├── ComponentName.css.ts # Vanilla Extract styles
66- ├── ComponentName.stories.tsx # Storybook stories
67- ├── ComponentName.spec.tsx # Unit tests (for internals only)
68- └── index.ts # Exports
69- ```
41+ ## Architecture, Design System Rules, Testing Strategy and Code Quality Standards
7042
71- ### Styling System
43+ Key requirements:
7244
73- - ** Vanilla Extract** for all styling via CSS-in-TypeScript
74- - ** Sprinkles** utility system for consistent spacing, colors, and responsive
75- design
76- - ** Design tokens** from ` /lib/themes/theme.css.ts ` must be used for all values
77- - State-based styling uses data attributes with the ` dataAttrs ` helper utility
78-
79- ### Component Composition Patterns
80-
81- - Build from primitives: Box, Text, Icon, Stack, etc.
82- - All components extend ` TestId ` to receive ` testId ` prop
83- - Composite components set ` odComponent ` prop to component name on Box
84- - Use React Aria for interactive components to ensure accessibility
85- - Components must have ` displayName ` set
86- - ** Component styles** : ` style ` function properties should always be wrapped in
87- the ` cssLayerComponent ` css layer
88-
89- ## Critical Development Rules
90-
91- 1 . ** NO new dependencies** - use existing dependencies only
92- 2 . ** Always use design tokens** from themes - no hardcoded values
93- 3 . ** Compose from primitives** rather than creating new base elements
94- 4 . ** Style functions preferred** such as ` elementStyles ` /` sprinkles ` or the
95- ` useBox ` hook or in the className, rather than using the <Box > component
96- 5 . ** Fix all linting/TypeScript errors** in modified files before committing
97- 6 . ** Set displayName** on all components
98- 7 . ** Use React Aria** for interactive elements to ensure accessibility
99- 8 . ** State affects UI via data attributes** managed by ` dataAttrs ` helper
100- 9 . ** Storybook play functions** for interaction testings are always organised
101- using ` step ` annotations
102-
103- ## Performance Considerations
104-
105- React 19's compiler handles most memoization automatically. Manual optimization
106- still needed for:
107-
108- - Heavy computational functions inside components
109- - Complex object/array transformations
110- - Event handlers passed to many children
111- - Expensive child component renders with stable props
112-
113- ## Testing Strategy
114-
115- ### When to Create Tests
116-
117- - ** Unit tests (.spec.tsx)** : Only for primitives with complex internal logic,
118- significant state management, or critical accessibility features
119- - ** Storybook stories (.stories.tsx)** : Primary testing method - required for
120- all components
121-
122- ### Testing Commands
123-
124- - ` yarn test ComponentName ` - Run specific component tests
125- - ` yarn test ComponentName -u ` - Update snapshots if needed
126- - ` yarn test:a11y ` - Run accessibility tests via Storybook
45+ - Fix all ESLint and TypeScript errors before committing
46+ - Use JSDoc comments on props and consistent naming conventions
47+ - No hardcoded values - use design tokens only
12748
128- ### Storybook Stories Requirements
129-
130- - Focus on user-facing behavior over implementation details
131- - Aim for ~ 5 stories per component: Standard, Variants, Interactive States, Edge
132- Cases, Accessibility
133- - Use story categories: ` Primitives/ ` , ` Layout/ ` , ` Forms/ ` , ` Navigation/ ` ,
134- ` Feedback/ ` , ` Overlays/ ` , ` Data Display/ `
135- - Include play functions for interactive components, and always query with
136- ` getAllbyRole ` and take first item in array instead of ` getByRole ` or any
137- other variety of get
138- - Use ` composeStories ` in spec files instead of testing components directly
139- - Use ` sprinkles ` function for styling in stories, never ` style ` prop
140- - Use ` valueArrays ` to populate argTypes, don't add custom ` control ` or
141- ` description `
142-
143- ### Story Enhancement Patterns
144-
145- ``` typescript
146- // Stories with play functions
147- import { expect , userEvent , within } from ' storybook/test' ;
148-
149- export const Interactive: Story = {
150- args: {
151- /* story args */
152- },
153- play : async ({ canvasElement }) => {
154- const canvas = within (canvasElement );
155- const user = userEvent .setup ();
156-
157- // Test interaction
158- await user .click (canvas .getByRole (' button' ));
159-
160- // Verify result
161- expect (canvas .getByRole (' button' )).toHaveAttribute (' aria-pressed' , ' true' );
162- },
163- };
164- ```
165-
166- ### Accessibility Testing Requirements
167-
168- - Keyboard navigation (Tab, Enter, Space, Escape, Arrow keys)
169- - Screen reader compatibility (proper ARIA attributes)
170- - Focus management and visual focus indicators
171- - Color contrast requirements
172- - Test using semantic queries (` getAllByRole ` , ` getAllByLabelText ` ) over test
173- IDs
174-
175- ### Testing Patterns
176-
177- - Use ` @testing-library/user-event ` for interactions
178- - Prefer decorators over custom render functions in stories
179- - Test stories first via ` composeStories ` , then component-specific logic
180- - Mock external dependencies appropriately
181- - Use snapshot testing sparingly
182-
183- ## Code Quality Standards
184-
185- All modified files must be free of:
186-
187- - ESLint errors
188- - TypeScript errors
189- - Unused imports
190- - Console statements
191- - Missing displayName on components
192- - Inline styles (use Vanilla Extract)
193- - Magic numbers (use design tokens)
194- - ` any ` types (use ` unknown ` or proper types)
195-
196- Components require JSDoc comments on props and consistent naming conventions
197- following the existing codebase patterns.
49+ ** For complete design system rules, patterns, and best practices, testing
50+ guidelines, accessibility requirements, and Storybook patterns see
51+ [ AGENTS.md] ( ./AGENTS.md ) **
19852
19953## Vanilla Extract Sprinkles Reference
20054
0 commit comments