Create Component
Create a new Spark UI component following the project's standards and file structure.
When to Use
- •User wants to create a new component
- •User mentions "new component", "add component", or "create component"
- •User is implementing a component from a design
Instructions
- •
Determine component location: Components go in
packages/components/src/<component-name>/ - •
Create the file structure:
codecomponent-name/ ├── ComponentName.tsx # Main component ├── ComponentName.styles.tsx # Styling with CVA ├── ComponentName.test.tsx # Unit tests ├── ComponentName.stories.tsx # Storybook stories ├── ComponentName.doc.mdx # Documentation ├── index.ts # Exports └── variants/ # Style variants (if applicable)
- •
Component Implementation:
- •Use TypeScript with strict typing
- •Implement polymorphic behavior with
asChildprop if needed - •Use CVA (Class Variance Authority) for styling variants
- •Include
data-spark-componentattribute - •Ensure WCAG 2.1 AA compliance
- •Use proper ARIA attributes
- •
Styling:
- •Create
ComponentName.styles.tsxwith CVA - •Define variants (size, variant, etc.)
- •Use TailwindCSS classes
- •Create
- •
Tests:
- •Create
ComponentName.test.tsxwith Vitest + React Testing Library - •Test rendering, props, variants, and accessibility
- •Test user interactions
- •Create
- •
Stories:
- •Create
ComponentName.stories.tsxfollowing Storybook CSF format - •Use
Components/*meta structure - •Create stories for: Default, Uncontrolled, Controlled, and other variants
- •One story per prop/feature
- •Create
- •
Documentation:
- •Create
ComponentName.doc.mdxwith sections in this order:- •Title (H1)
- •Meta (link to stories)
- •Install
- •Import
- •Props table (using ArgTypes component)
- •Usage (Default, Uncontrolled, Controlled, others alphabetically)
- •Advanced Usage
- •Accessibility
- •Create
- •
Exports:
- •Create
index.tswith named exports - •Export component, types, and sub-components if compound
- •Create
- •
For Compound Components:
- •Use Object.assign pattern
- •Set display names for all sub-components
- •Document sub-components in ArgTypes
- •
Verify:
- •Run
npm run lintto check code quality - •Run
npm run typecheckto verify types - •Run tests to ensure they pass
- •Check Storybook renders correctly
- •Run
Examples
Reference existing components in packages/components/src/ for patterns:
- •Simple component:
badge/,button/ - •Compound component:
card/,input/,accordion/ - •Complex component:
combobox/,select/