Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build React UIs using shadcn/ui components with Tailwind CSS, Radix primitives, and proper accessibility patterns.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/learn.md
1# shadcn/ui Learning Guide23This guide helps you learn shadcn/ui from basics to advanced patterns.45## Learning Path67### 1. Understanding the Philosophy89shadcn/ui is different from traditional component libraries:1011- **Copy-paste components**: Components are copied into your project, not installed as packages12- **Full customization**: You own the code and can modify it freely13- **Built on Radix UI**: Provides accessibility primitives14- **Styled with Tailwind**: Uses utility classes for consistent styling1516### 2. Core Concepts to Master1718#### Class Variance Authority (CVA)19Most components use CVA for variant management:2021```tsx22const buttonVariants = cva(23"base-classes",24{25variants: {26variant: {27default: "variant-classes",28destructive: "destructive-classes",29},30size: {31default: "size-classes",32sm: "small-classes",33},34},35defaultVariants: {36variant: "default",37size: "default",38},39}40)41```4243#### cn Utility Function44The `cn` function combines classes and resolves conflicts:4546```tsx47import { clsx, type ClassValue } from "clsx"48import { twMerge } from "tailwind-merge"4950export function cn(...inputs: ClassValue[]) {51return twMerge(clsx(inputs))52}53```5455### 3. Installation Checklist5657- [ ] Initialize a new project (Next.js, Vite, or Remix)58- [ ] Install Tailwind CSS59- [ ] Run `npx shadcn@latest init`60- [ ] Configure CSS variables61- [ ] Install first component: `npx shadcn@latest add button`6263### 4. Essential Components to Learn First64651. **Button** - Learn variants and sizes662. **Input** - Form inputs with labels673. **Card** - Container components684. **Form** - Form handling with React Hook Form695. **Dialog** - Modal windows706. **Select** - Dropdown selections717. **Toast** - Notifications7273### 5. Common Patterns7475#### Form Pattern76Every form follows this structure:7778```tsx791. Define Zod schema802. Create form with useForm813. Wrap with Form component824. Add FormField for each input835. Handle submission84```8586#### Component Customization Pattern87To customize a component:88891. Copy component to your project902. Modify the variants913. Add new props if needed924. Update types9394### 6. Best Practices9596- Always use TypeScript97- Follow the existing component structure98- Use semantic HTML when possible99- Test with screen readers for accessibility100- Keep components small and focused101102### 7. Advanced Topics103104- Creating custom components from scratch105- Building complex forms with validation106- Implementing dark mode107- Optimizing for performance108- Testing components109110## Practice Exercises111112### Exercise 1: Basic Setup1131. Create a new Next.js project1142. Set up shadcn/ui1153. Install and customize a Button component1164. Add a new variant "gradient"117118### Exercise 2: Form Building1191. Create a contact form with:120- Name input (required)121- Email input (email validation)122- Message textarea (min length)123- Submit button with loading state124125### Exercise 3: Component Combination1261. Build a settings page using:127- Card for layout128- Sheet for mobile menu129- Select for dropdowns130- Switch for toggles131- Toast for notifications132133### Exercise 4: Custom Component1341. Create a custom Badge component1352. Support variants: default, secondary, destructive, outline1363. Support sizes: sm, default, lg1374. Add icon support138139## Resources140141- [Official Documentation](https://ui.shadcn.com)142- [GitHub Repository](https://github.com/shadcn/ui)143- [Examples Gallery](https://ui.shadcn.com/examples)144- [Radix UI Primitives](https://www.radix-ui.com/primitives)145- [Tailwind CSS Documentation](https://tailwindcss.com/docs)