--- name: shadcn-best-practices description: Best practices for working with shadcn/ui components, imports, theming, and forms. Use when building UI with shadcn, adding components, configuring theming, or creating forms. version: 1.0.0 --- # shadcn/ui Best Practices This skill covers best practices for working with shadcn/ui — component imports, className utilities, form building, theming, and data tables. ## Use-When This skill activates when: - Agent works with shadcn/ui components - Agent adds or imports shadcn components - Agent builds forms with validation - Agent configures theming or dark mode - Agent creates data tables ## Core Rules - ALWAYS import shadcn components from `@/components/ui/{component-name}` - ALWAYS use the `cn()` utility for className merging - ALWAYS use Zod + React Hook Form for form validation - ALWAYS use CSS variables for theming (not hardcoded colors) - ALWAYS use TanStack Table for data tables - ALWAYS check components.json to identify the primitive library (Radix vs Base UI) - ALWAYS use migration commands when upgrading between styles (`migrate radix`, `migrate rtl`) ## Common Agent Mistakes - Using relative paths instead of alias paths - Forgetting to import `cn()` utility - Hardcoding colors instead of using CSS variables - Building table logic manually instead of using TanStack Table - Assuming all shadcn projects use Radix UI (Base UI is now available) - Using Radix-specific imports in Base UI projects (or vice versa) ## Examples ### ✅ Correct ```tsx import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { cn } from "@/lib/utils" function MyComponent({ className }) { return ( ) } ``` ### ❌ Wrong ```tsx // Using relative paths import { Button } from "../../components/ui/button" // Hardcoding colors // Building table manually data.map(item =>