# Components **Master the shadcn/ui component library**: Learn all variants, composition patterns, and when to use each component. This is your complete reference for building consistent interfaces. --- ## Table of Contents 1. [Overview](#overview) 2. [Core Components](#core-components) 3. [Form Components](#form-components) 4. [Feedback Components](#feedback-components) 5. [Overlay Components](#overlay-components) 6. [Data Display Components](#data-display-components) 7. [Composition Patterns](#composition-patterns) 8. [Quick Reference](#quick-reference) --- ## Overview ### About shadcn/ui We use **[shadcn/ui](https://ui.shadcn.com)**, a collection of accessible, customizable components built on **Radix UI primitives**. **Key features:** - ✅ **Accessible** - WCAG AA compliant, keyboard navigation, screen reader support - ✅ **Customizable** - Components are copied into your project (not npm dependencies) - ✅ **Composable** - Build complex UIs from simple primitives - ✅ **Dark mode** - All components work in light and dark modes - ✅ **Type-safe** - Full TypeScript support ### Installation Method ```bash # Add new components npx shadcn@latest add button card input dialog # List available components npx shadcn@latest add ``` **Installed components** (in `/src/components/ui/`): - alert, avatar, badge, button, card, checkbox, dialog - dropdown-menu, input, label, popover, select, separator - sheet, skeleton, table, tabs, textarea, toast --- ## Core Components ### Button **Purpose**: Trigger actions, navigate, submit forms ```tsx import { Button } from '@/components/ui/button'; // Variants // Sizes // States // As Link (Next.js) ``` **When to use each variant:** | Variant | Use Case | Example | | ------------- | ----------------------- | -------------------------- | | `default` | Primary actions, CTAs | Save, Submit, Create | | `secondary` | Secondary actions | Cancel, Back | | `outline` | Alternative actions | View Details, Edit | | `ghost` | Subtle actions in lists | Icon buttons in table rows | | `link` | In-text actions | Read more, Learn more | | `destructive` | Delete, remove actions | Delete Account, Remove | **Accessibility**: - Always add `aria-label` for icon-only buttons - Use `disabled` for unavailable actions (not hidden) - Loading state prevents double-submission **[See live examples](/dev/components#button)** --- ### Badge **Purpose**: Labels, tags, status indicators ```tsx import { Badge } from '@/components/ui/badge'; // Variants New Draft Pending Critical // Custom colors (use sparingly) Active Warning ``` **Common patterns:** ```tsx // Status badge {user.is_active ? ( Active ) : ( Inactive )} // Count badge {itemCount} // Role badge {user.role} ``` --- ### Avatar **Purpose**: User profile pictures, placeholders ```tsx import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'; // With image JD // Fallback only (initials) AB // Sizes (custom classes) ... ... ... ``` **Pattern: User menu**: ```tsx {user.initials} Profile Settings Logout ``` --- ### Card **Purpose**: Container for related content, groups information ```tsx import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from '@/components/ui/card'; // Basic card Users Manage system users

Card content goes here

// Minimal card (content only)

Quick Stats

1,234

``` **Common patterns:** ```tsx // Card with action button in header
Recent Activity Last 7 days
{/* content */}
// Dashboard metric card Total Revenue
$45,231.89

+20.1% from last month

``` --- ### Separator **Purpose**: Visual divider between content sections ```tsx import { Separator } from '@/components/ui/separator'; // Horizontal (default)
Section 1
Section 2
// Vertical
Left
Right
// Decorative (for screen readers) ``` --- ## Form Components ### Input **Purpose**: Text input, email, password, etc. ```tsx import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; // Basic input
// With error state
{errors.password && (

{errors.password.message}

)}
// Disabled // Read-only ``` **Input types:** - `text` - Default text input - `email` - Email address - `password` - Password field - `number` - Numeric input - `tel` - Telephone number - `url` - URL input - `search` - Search field **See [Forms Guide](./06-forms.md) for complete form patterns** --- ### Textarea **Purpose**: Multi-line text input ```tsx import { Textarea } from '@/components/ui/textarea';