--- name: shadcn-component-review description: Review custom components and layouts against shadcn design patterns, theme styles (Maia, Vega, Lyra, Nova, Mira), component structure, composability, and Radix UI best practices. Use when planning new components, reviewing existing components, auditing spacing, checking component structure, or verifying shadcn best practices alignment. --- # shadcn Component Review Systematic review process for ensuring custom components and layouts align with shadcn design patterns, official theme styles, and Radix UI best practices. ## Quick Start ### Planning Phase (Preventive) Before building a component: 1. **Check existing patterns**: Review similar components in `src/ui/` and `src/components/` 2. **Reference your theme style**: See [references/theme-styles.md](references/theme-styles.md) for spacing/shape patterns 3. **Use shadcn MCP** (if available): Query components via shadcn MCP server 4. **Review checklist**: Use [references/review-checklist.md](references/review-checklist.md) as planning guide ### Review Phase (Post-Build) After building a component: 1. **Run spacing audit**: Check against your theme's spacing patterns 2. **Verify structure**: Ensure proper use of `data-slot` attributes and composition 3. **Check design tokens**: Verify semantic tokens only (no hardcoded colors) 4. **Test composability**: Ensure component can be reused and customized via props 5. **Validate responsive**: Test mobile-first approach and breakpoints ## Core Review Areas ### 1. Spacing (Theme-Dependent) Use `gap-*` for flex/grid containers. Spacing varies by theme style: | Theme | Spacing | Shape | |-------|---------|-------| | **Vega** | Standard | Classic shadcn | | **Nova** | Compact | Reduced padding/margins | | **Maia** | Generous | Soft, rounded | | **Lyra** | Standard | Boxy, sharp | | **Mira** | Dense | Compact interfaces | See [references/theme-styles.md](references/theme-styles.md) for theme-specific patterns. ### 2. Component Structure - Use `data-slot` attributes: `data-slot="component-name"` - Sub-components: `ComponentName.Header`, `ComponentName.Content` - Composition over modification (never edit `src/ui/*` directly) ### 3. Design Tokens Semantic tokens only - **never** hardcoded colors: ```tsx // ✅ text-muted-foreground, bg-muted, hover:bg-accent // ❌ text-neutral-500, bg-gray-100, hover:bg-neutral-50 ``` ### 4. Composability - Prop-based customization (variants, sizes) - Slot-based composition (children, content blocks) - Single responsibility, clear interface ### 5. Responsive Design - Mobile-first (< 768px base) - Breakpoints: `md:` (768px+), `lg:` (1024px+) - Touch targets: min 44px - Flex children: `min-w-0` to prevent overflow See [references/review-checklist.md](references/review-checklist.md) for detailed checklists. ## Foundational Patterns ### CVA (Class Variance Authority) shadcn components use CVA for type-safe, declarative variants: ```tsx import { cva, type VariantProps } from "class-variance-authority" const buttonVariants = cva( "inline-flex items-center justify-center font-medium transition-colors", { variants: { variant: { default: "bg-primary text-primary-foreground hover:bg-primary/90", outline: "border border-input bg-background hover:bg-accent", }, size: { default: "h-9 px-4 py-2", sm: "h-8 px-3 text-sm", }, }, defaultVariants: { variant: "default", size: "default" }, } ) interface ButtonProps extends VariantProps {} ``` **Key points:** - Base styles in first argument (always applied) - Variants as declarative object - Type-safe props via `VariantProps` - Extend with new variants, don't modify base ### cn() Utility Always use `cn()` for conditional and override classes: ```tsx import { cn } from "@/lib/utils" // Combines clsx (conditionals) + tailwind-merge (conflict resolution)
``` **Why it matters:** - Prevents CSS cascade conflicts - Enables prop-based class overrides - Handles conditional classes cleanly ### Theme-Aware Styling shadcn themes use CSS variables for consistent styling across components. **Border radius** is theme-defined via `--radius`: ```tsx // ✅ Uses theme radius (adapts to Maia rounded vs Lyra sharp)