shadcn/ui Knowledge Base
Installation
npx shadcn@latest init
Configuration prompts:
- Style: Default
- Base color: Slate
- CSS variables: Yes
Add Components
# Single component
npx shadcn@latest add button
# Multiple components
npx shadcn@latest add button card dialog form input
# All components
npx shadcn@latest add --all
MCP Server Integration
// .mcp.json
{
"mcpServers": {
"shadcn": {
"command": "npx",
"args": ["shadcn@latest", "mcp"]
}
}
}
MCP Commands:
- "Add button, card, and dialog components"
- "Find a login form from shadcn registry"
- "Install all form components"
Component Categories
Forms
- Button, Input, Textarea, Select, Checkbox, Radio Group
- Switch, Slider, Toggle, Form (with react-hook-form)
- Label, Calendar, Date Picker
Feedback
- Alert, Alert Dialog, Toast, Sonner
- Progress, Skeleton, Badge, Avatar
Layout
- Card, Separator, Accordion, Collapsible
- Tabs, Sheet, Scroll Area, Resizable
Navigation
- Navigation Menu, Menubar, Dropdown Menu
- Context Menu, Command, Breadcrumb, Pagination
Overlay
- Dialog, Drawer, Popover, Tooltip, Hover Card
Data Display
- Table, Data Table, Carousel, Aspect Ratio
Theming with CSS Variables
shadcn/ui uses CSS variables for theming. Configure in globals.css:
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;
/* ... other variables */
}
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
/* ... dark variants */
}
}
cn() Utility (Merge Classes Safely)
// lib/utils.ts
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
Best Practices
- Copy, don't wrap - Own your components, don't create wrappers
- Use cn() - For conditional classes
- Extend variants - With cva() for custom variants
- Accessibility - Built on Radix primitives (ARIA compliant)
- Dark mode - Use CSS variables for theme switching
1---2name: shadcn3description: shadcn/ui knowledge base - installation, components, theming, MCP server integration. Use when building UI components, searching component registry, implementing accessible patterns, or customizing component styles.4---56# shadcn/ui Knowledge Base78## Installation910```bash11npx shadcn@latest init12```1314Configuration prompts:15- Style: Default16- Base color: Slate17- CSS variables: Yes1819## Add Components2021```bash22# Single component23npx shadcn@latest add button2425# Multiple components26npx shadcn@latest add button card dialog form input2728# All components29npx shadcn@latest add --all30```3132## MCP Server Integration3334```json35// .mcp.json36{37 "mcpServers": {38 "shadcn": {39 "command": "npx",40 "args": ["shadcn@latest", "mcp"]41 }42 }43}44```4546**MCP Commands:**47- "Add button, card, and dialog components"48- "Find a login form from shadcn registry"49- "Install all form components"5051## Component Categories5253### Forms54- Button, Input, Textarea, Select, Checkbox, Radio Group55- Switch, Slider, Toggle, Form (with react-hook-form)56- Label, Calendar, Date Picker5758### Feedback59- Alert, Alert Dialog, Toast, Sonner60- Progress, Skeleton, Badge, Avatar6162### Layout63- Card, Separator, Accordion, Collapsible64- Tabs, Sheet, Scroll Area, Resizable6566### Navigation67- Navigation Menu, Menubar, Dropdown Menu68- Context Menu, Command, Breadcrumb, Pagination6970### Overlay71- Dialog, Drawer, Popover, Tooltip, Hover Card7273### Data Display74- Table, Data Table, Carousel, Aspect Ratio7576## Theming with CSS Variables7778shadcn/ui uses CSS variables for theming. Configure in `globals.css`:7980```css81@layer base {82 :root {83 --background: 0 0% 100%;84 --foreground: 222.2 84% 4.9%;85 --primary: 222.2 47.4% 11.2%;86 --primary-foreground: 210 40% 98%;87 /* ... other variables */88 }8990 .dark {91 --background: 222.2 84% 4.9%;92 --foreground: 210 40% 98%;93 /* ... dark variants */94 }95}96```9798## cn() Utility (Merge Classes Safely)99100```typescript101// lib/utils.ts102import { clsx, type ClassValue } from 'clsx';103import { twMerge } from 'tailwind-merge';104105export function cn(...inputs: ClassValue[]) {106 return twMerge(clsx(inputs));107}108```109110## Best Practices1111121. **Copy, don't wrap** - Own your components, don't create wrappers1132. **Use cn()** - For conditional classes1143. **Extend variants** - With cva() for custom variants1154. **Accessibility** - Built on Radix primitives (ARIA compliant)1165. **Dark mode** - Use CSS variables for theme switching