1.8 KiB
1.8 KiB
description
| description |
|---|
| Add a shadcn/ui component to the project |
Add shadcn/ui Component
Install and configure a shadcn/ui component in your React + Vite project.
Instructions
- Ask which shadcn/ui component to add (button, card, dialog, form, etc.)
- Check if shadcn/ui is initialized (look for
components.json) - If not initialized, run:
bunx shadcn@latest init - Add the requested component:
bunx shadcn@latest add [component-name] - Show the component location (
components/ui/[component].tsx) - Provide usage example with TypeScript
- Suggest related components that work well together
- Check if Tailwind CSS is properly configured
- Verify that required dependencies are installed (check package.json)
Popular Components
- button - Button component with variants
- card - Card container with header/footer
- dialog - Modal dialog/popup
- form - Form components (use with TanStack Form)
- input - Input field with variants
- select - Select dropdown
- table - Data table component
- toast - Toast notifications
- dropdown-menu - Dropdown menu
- tabs - Tab navigation
Usage Example
After adding a button component:
import { Button } from "@/components/ui/button";
export function MyComponent() {
return (
<Button variant="default" size="lg">
Click me
</Button>
);
}
Framework-Specific Notes
- React + Vite: All components are client-side by default. No need for
'use client'directive. - TanStack Router: Components can be used in route components, loaders, and layout files seamlessly.
- Component State: Use React hooks (useState, useEffect, etc.) freely in any component without special directives.
Provide component-specific examples and customization tips.