Component Library - shadcn/ui Architecture
Generate production-ready React components with shadcn/ui patterns, saving 8-10 hours per project.
Quick Start
When generating components:
- Create
/components/ui/ directory structure
- Generate
lib/utils.ts with cn() helper first
- Create requested components with full TypeScript, variants, and accessibility
- Include example usage for each component
Core Setup Files
Always generate these first:
lib/utils.ts - Essential cn() helper:
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
components.json - Component registry:
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "app/globals.css",
"baseColor": "slate",
"cssVariables": true
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
Component Categories
Form Components
- Input - Text input with variants (default, ghost, underline)
- Select - Custom dropdown with search, multi-select options
- Checkbox - With indeterminate state support
- Radio - Radio groups with custom styling
- Switch - Toggle switches with labels
- Textarea - Auto-resize, character count variants
- DatePicker - Calendar integration, range selection
- FileUpload - Drag & drop, preview, progress
- Slider - Range input with marks, tooltips
- Form - React Hook Form wrapper with validation
Display Components
- Card - Container with header/footer slots
- Table - Sortable, filterable, pagination
- Badge - Status indicators with variants
- Avatar - Image/initials with fallback
- Progress - Linear and circular variants
- Skeleton - Loading states
- Separator - Visual dividers
- ScrollArea - Custom scrollbars
Feedback Components
- Alert - Info/warning/error/success states
- Toast - Notifications with actions
- Dialog/Modal - Accessible overlays
- Tooltip - Hover information
- Popover - Positioned content
- AlertDialog - Confirmation dialogs
Navigation Components
- Navigation - Responsive nav with mobile menu
- Tabs - Tab panels with keyboard nav
- Breadcrumb - Path navigation
- Pagination - Page controls
- CommandMenu - Command palette (⌘K)
- ContextMenu - Right-click menus
- DropdownMenu - Action menus
Layout Components
- Accordion - Collapsible sections
- Collapsible - Show/hide content
- ResizablePanels - Draggable split panes
- Sheet - Slide-out panels
- AspectRatio - Maintain ratios
Component Implementation Patterns
Use CVA for all variants:
import { cva, type VariantProps } from "class-variance-authority"
const buttonVariants = cva(
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
Accessibility Requirements:
- ARIA labels and roles on all interactive elements
- Keyboard navigation (Tab, Arrow keys, Enter, Escape)
- Focus management and trapping for modals
- Screen reader announcements
- Semantic HTML elements
Dark Mode Support:
- Use Tailwind dark: modifier
- CSS variables for theme colors
- Smooth transitions between modes
Responsive Design:
- Mobile-first approach
- Container queries where appropriate
- Touch-friendly tap targets (min 44x44px)
- Responsive typography scale
Dependencies
Include in package.json:
{
"dependencies": {
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-progress": "^1.0.3",
"@radix-ui/react-radio-group": "^1.1.3",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slider": "^1.1.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-tooltip": "^1.0.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cmdk": "^0.2.0",
"date-fns": "^2.30.0",
"lucide-react": "^0.263.1",
"react-day-picker": "^8.8.0",
"react-hook-form": "^7.45.4",
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7"
}
}
Implementation Workflow
- Assess Requirements: Identify which components are needed
- Generate Base Files: Create utils.ts and components.json
- Create Components: Generate requested components with all features
- Provide Examples: Include usage examples for each component
- Document Props: Add TypeScript interfaces with JSDoc comments
Advanced Patterns
For complex requirements, see:
- references/form-patterns.md - Advanced form handling
- references/data-tables.md - Complex table implementations
- references/animation-patterns.md - Framer Motion integration
- references/testing-setup.md - Component testing patterns
Performance Optimization
- Use React.memo for expensive components
- Implement virtual scrolling for long lists
- Lazy load heavy components
- Optimize bundle size with tree shaking
- Use CSS containment for layout stability
Component Generation Tips
When generating components:
- Include all variant combinations
- Add proper TypeScript types
- Implement keyboard shortcuts
- Include loading and error states
- Provide Storybook stories structure
- Add comprehensive prop documentation
- Include accessibility attributes
- Test with screen readers
1---2name: component-library3description: Comprehensive React component library with 30+ production-ready components using shadcn/ui architecture, CVA variants, Radix UI primitives, and Tailwind CSS. Use when users need to (1) Create React UI components with modern patterns, (2) Build complete component systems with consistent design, (3) Implement accessible, responsive, dark-mode-ready components, (4) Generate form components with React Hook Form integration, (5) Create data display components like tables, cards, charts, or (6) Build navigation, layout, or feedback components. Provides instant generation of customizable components that would otherwise take 20-45 minutes each to hand-code.4---5
6# Component Library - shadcn/ui Architecture
7
8Generate production-ready React components with shadcn/ui patterns, saving 8-10 hours per project.
9
10## Quick Start
11
12When generating components:
131. Create `/components/ui/` directory structure
142. Generate `lib/utils.ts` with cn() helper first
153. Create requested components with full TypeScript, variants, and accessibility
164. Include example usage for each component
17
18## Core Setup Files
19
20### Always generate these first:
21
22**lib/utils.ts** - Essential cn() helper:
23```typescript
24import { type ClassValue, clsx } from "clsx"
25import { twMerge } from "tailwind-merge"
26
27export function cn(...inputs: ClassValue[]) {
28 return twMerge(clsx(inputs))
29}
30```
31
32**components.json** - Component registry:
33```json
34{
35 "$schema": "https://ui.shadcn.com/schema.json",
36 "style": "default",
37 "rsc": false,
38 "tsx": true,
39 "tailwind": {
40 "config": "tailwind.config.js",
41 "css": "app/globals.css",
42 "baseColor": "slate",
43 "cssVariables": true
44 },
45 "aliases": {
46 "components": "@/components",
47 "utils": "@/lib/utils"
48 }
49}
50```
51
52## Component Categories
53
54### Form Components
55- **Input** - Text input with variants (default, ghost, underline)
56- **Select** - Custom dropdown with search, multi-select options
57- **Checkbox** - With indeterminate state support
58- **Radio** - Radio groups with custom styling
59- **Switch** - Toggle switches with labels
60- **Textarea** - Auto-resize, character count variants
61- **DatePicker** - Calendar integration, range selection
62- **FileUpload** - Drag & drop, preview, progress
63- **Slider** - Range input with marks, tooltips
64- **Form** - React Hook Form wrapper with validation
65
66### Display Components
67- **Card** - Container with header/footer slots
68- **Table** - Sortable, filterable, pagination
69- **Badge** - Status indicators with variants
70- **Avatar** - Image/initials with fallback
71- **Progress** - Linear and circular variants
72- **Skeleton** - Loading states
73- **Separator** - Visual dividers
74- **ScrollArea** - Custom scrollbars
75
76### Feedback Components
77- **Alert** - Info/warning/error/success states
78- **Toast** - Notifications with actions
79- **Dialog/Modal** - Accessible overlays
80- **Tooltip** - Hover information
81- **Popover** - Positioned content
82- **AlertDialog** - Confirmation dialogs
83
84### Navigation Components
85- **Navigation** - Responsive nav with mobile menu
86- **Tabs** - Tab panels with keyboard nav
87- **Breadcrumb** - Path navigation
88- **Pagination** - Page controls
89- **CommandMenu** - Command palette (⌘K)
90- **ContextMenu** - Right-click menus
91- **DropdownMenu** - Action menus
92
93### Layout Components
94- **Accordion** - Collapsible sections
95- **Collapsible** - Show/hide content
96- **ResizablePanels** - Draggable split panes
97- **Sheet** - Slide-out panels
98- **AspectRatio** - Maintain ratios
99
100## Component Implementation Patterns
101
102### Use CVA for all variants:
103```typescript
104import { cva, type VariantProps } from "class-variance-authority"
105
106const buttonVariants = cva(
107 "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
108 {
109 variants: {
110 variant: {
111 default: "bg-primary text-primary-foreground hover:bg-primary/90",
112 destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
113 outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
114 secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
115 ghost: "hover:bg-accent hover:text-accent-foreground",
116 link: "text-primary underline-offset-4 hover:underline",
117 },
118 size: {
119 default: "h-10 px-4 py-2",
120 sm: "h-9 rounded-md px-3",
121 lg: "h-11 rounded-md px-8",
122 icon: "h-10 w-10",
123 },
124 },
125 defaultVariants: {
126 variant: "default",
127 size: "default",
128 },
129 }
130)
131```
132
133### Accessibility Requirements:
134- ARIA labels and roles on all interactive elements
135- Keyboard navigation (Tab, Arrow keys, Enter, Escape)
136- Focus management and trapping for modals
137- Screen reader announcements
138- Semantic HTML elements
139
140### Dark Mode Support:
141- Use Tailwind dark: modifier
142- CSS variables for theme colors
143- Smooth transitions between modes
144
145### Responsive Design:
146- Mobile-first approach
147- Container queries where appropriate
148- Touch-friendly tap targets (min 44x44px)
149- Responsive typography scale
150
151## Dependencies
152
153Include in package.json:
154```json
155{
156 "dependencies": {
157 "@radix-ui/react-accordion": "^1.1.2",
158 "@radix-ui/react-alert-dialog": "^1.0.5",
159 "@radix-ui/react-avatar": "^1.0.4",
160 "@radix-ui/react-checkbox": "^1.0.4",
161 "@radix-ui/react-dialog": "^1.0.5",
162 "@radix-ui/react-dropdown-menu": "^2.0.6",
163 "@radix-ui/react-label": "^2.0.2",
164 "@radix-ui/react-popover": "^1.0.7",
165 "@radix-ui/react-progress": "^1.0.3",
166 "@radix-ui/react-radio-group": "^1.1.3",
167 "@radix-ui/react-select": "^2.0.0",
168 "@radix-ui/react-separator": "^1.0.3",
169 "@radix-ui/react-slider": "^1.1.2",
170 "@radix-ui/react-switch": "^1.0.3",
171 "@radix-ui/react-tabs": "^1.0.4",
172 "@radix-ui/react-toast": "^1.1.5",
173 "@radix-ui/react-tooltip": "^1.0.7",
174 "class-variance-authority": "^0.7.0",
175 "clsx": "^2.0.0",
176 "cmdk": "^0.2.0",
177 "date-fns": "^2.30.0",
178 "lucide-react": "^0.263.1",
179 "react-day-picker": "^8.8.0",
180 "react-hook-form": "^7.45.4",
181 "tailwind-merge": "^1.14.0",
182 "tailwindcss-animate": "^1.0.7"
183 }
184}
185```
186
187## Implementation Workflow
188
1891. **Assess Requirements**: Identify which components are needed
1902. **Generate Base Files**: Create utils.ts and components.json
1913. **Create Components**: Generate requested components with all features
1924. **Provide Examples**: Include usage examples for each component
1935. **Document Props**: Add TypeScript interfaces with JSDoc comments
194
195## Advanced Patterns
196
197For complex requirements, see:
198- **references/form-patterns.md** - Advanced form handling
199- **references/data-tables.md** - Complex table implementations
200- **references/animation-patterns.md** - Framer Motion integration
201- **references/testing-setup.md** - Component testing patterns
202
203## Performance Optimization
204
205- Use React.memo for expensive components
206- Implement virtual scrolling for long lists
207- Lazy load heavy components
208- Optimize bundle size with tree shaking
209- Use CSS containment for layout stability
210
211## Component Generation Tips
212
213When generating components:
214- Include all variant combinations
215- Add proper TypeScript types
216- Implement keyboard shortcuts
217- Include loading and error states
218- Provide Storybook stories structure
219- Add comprehensive prop documentation
220- Include accessibility attributes
221- Test with screen readers