ShadCN Component Workflow
When creating new UI components, use ShadCN UI as the component library. Never manually copy ShadCN component code—always install via the CLI.
Workflow
- •Identify needed ShadCN primitives from ui.shadcn.com/docs/components
- •Install via CLI before writing component code:
bash
npx shadcn@latest add <component-name>
Add multiple components in one command:
bash
npx shadcn@latest add button input label
- •Import from the project alias (configured in
components.json):
tsx
import { Button } from "~/components/ui/button";
import { Input } from "~/components/ui/input";
- •Build your component using the installed primitives. Use the
cn()utility for merging class names:
tsx
import { cn } from "~/lib/utils";
Common Component Mappings
| Need | ShadCN component |
|---|---|
| Button, link-as-button | button |
| Text input, form field | input, label |
| Card layout | card |
| Modal/dialog | dialog |
| Dropdown menu | dropdown-menu |
| Form with validation | form (includes react-hook-form) |
| Tabs | tabs |
| Toast notifications | sonner or toast |
| Select/picker | select |
| Checkbox, switch | checkbox, switch |
Rules
- •Always run
npx shadcn@latest add <component>before using a ShadCN component in code - •Use
~/components/ui/<component>import path (React Router / project alias) - •Use
cn()from~/lib/utilsfor conditional class merging - •Check
components.jsonfor project-specific aliases if imports fail