
Shadcn Ui
- 19.3k installs
- 311 repo stars
- Updated June 22, 2026
- giuseppe-trisciuoglio/developer-kit
shadcn-ui is a React component library providing copy-paste accessible UI templates built with Tailwind CSS and Radix UI.
About
shadcn-ui is a collection of accessible React components built with Tailwind CSS and Radix UI primitives. It provides copy-paste component templates that developers customize for their projects rather than a traditional dependency. Developers use it to accelerate UI development with production-ready, accessible components.
- Pre-built accessible React component library
- Customizable with Tailwind CSS theming
- Works across multiple frontend frameworks and environments
Shadcn Ui by the numbers
- 19,315 all-time installs (skills.sh)
- +147 installs in the week ending Jul 28, 2026 (Skillselion tracking)
- Ranked #31 of 2,277 Frontend Development skills by installs in the Skillselion catalog
- Security screen: MEDIUM risk (skills.sh audit)
- Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill shadcn-uiAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 19.3k |
|---|---|
| repo stars | ★ 311 |
| Security audit | 2 / 3 scanners passed |
| Last updated | June 22, 2026 |
| Repository | giuseppe-trisciuoglio/developer-kit ↗ |
How do you set up shadcn/ui components in React?
Build accessible React user interfaces with pre-built shadcn-ui components.
Who is it for?
React developers adopting shadcn/ui who need accessible components, theming, and validated form patterns in-repo.
Skip if: Vue, Svelte, or Angular teams, or projects that require a hosted component CDN instead of copied source files.
When should I use this skill?
A developer asks to install shadcn/ui, build accessible forms with React Hook Form and Zod, or customize Tailwind themes for UI components.
What you get
Copied shadcn/ui component files, Tailwind theme config, and accessible form layouts with React Hook Form and Zod schemas.
- shadcn/ui component files
- theme configuration
- validated form components
Files
shadcn/ui Component Patterns
Build accessible, customizable UI components with shadcn/ui, Radix UI, and Tailwind CSS.
Overview
- Components are copied into your project — you own and customize the code
- Built on Radix UI primitives for full accessibility
- Styled with Tailwind CSS and CSS variables for theming
- CLI-based installation:
npx shadcn@latest add <component>
When to Use
Activate when user requests involve:
- "Set up shadcn/ui", "initialize shadcn", "add shadcn components"
- "Install button/input/form/dialog/card/select/toast/table/chart"
- "React Hook Form", "Zod validation", "form with validation"
- "accessible components", "Radix UI", "Tailwind theme"
- "shadcn button", "shadcn dialog", "shadcn sheet", "shadcn table"
- "dark mode", "CSS variables", "custom theme"
- "charts with Recharts", "bar chart", "line chart", "pie chart"
Quick Reference
Available Components
| Component | Install Command | Description |
|---|---|---|
button | npx shadcn@latest add button | Variants: default, destructive, outline, secondary, ghost, link |
input | npx shadcn@latest add input | Text input field |
form | npx shadcn@latest add form | React Hook Form integration with validation |
card | npx shadcn@latest add card | Container with header, content, footer |
dialog | npx shadcn@latest add dialog | Modal overlay |
sheet | npx shadcn@latest add sheet | Slide-over panel (top/right/bottom/left) |
select | npx shadcn@latest add select | Dropdown select |
toast | npx shadcn@latest add toast | Notification toasts |
table | npx shadcn@latest add table | Data table |
menubar | npx shadcn@latest add menubar | Desktop-style menubar |
chart | npx shadcn@latest add chart | Recharts wrapper with theming |
textarea | npx shadcn@latest add textarea | Multi-line text input |
checkbox | npx shadcn@latest add checkbox | Checkbox input |
label | npx shadcn@latest add label | Accessible form label |
Instructions
Initialize Project
# New Next.js project
npx create-next-app@latest my-app --typescript --tailwind --eslint --app
cd my-app
npx shadcn@latest init
# Existing project
npm install tailwindcss-animate class-variance-authority clsx tailwind-merge lucide-react
npx shadcn@latest init
# Install components
npx shadcn@latest add button input form card dialog select toastBasic Component Usage
// Button with variants and sizes
import { Button } from "@/components/ui/button"
<Button variant="default">Default</Button>
<Button variant="destructive" size="sm">Delete</Button>
<Button variant="outline" disabled>Loading...</Button>Form with Zod Validation
"use client"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { z } from "zod"
import { Button } from "@/components/ui/button"
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
const formSchema = z.object({
email: z.string().email("Invalid email"),
password: z.string().min(8, "Password must be at least 8 characters"),
})
export function LoginForm() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: { email: "", password: "" },
})
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(console.log)} className="space-y-4">
<FormField name="email" control={form.control} render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl><Input type="email" {...field} /></FormControl>
<FormMessage />
</FormItem>
)} />
<FormField name="password" control={form.control} render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl><Input type="password" {...field} /></FormControl>
<FormMessage />
</FormItem>
)} />
<Button type="submit">Login</Button>
</form>
</Form>
)
}See references/forms-and-validation.md for advanced multi-field forms, contact forms with API submission, and login card patterns.
Dialog (Modal)
import { Button } from "@/components/ui/button"
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Open</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit Profile</DialogTitle>
</DialogHeader>
{/* content */}
</DialogContent>
</Dialog>Toast Notification
// 1. Add <Toaster /> to app/layout.tsx
import { Toaster } from "@/components/ui/toaster"
// 2. Use in components
import { useToast } from "@/components/ui/use-toast"
const { toast } = useToast()
toast({ title: "Success", description: "Changes saved." })
toast({ variant: "destructive", title: "Error", description: "Something went wrong." })Bar Chart
import { Bar, BarChart, CartesianGrid, XAxis } from "recharts"
import { ChartContainer, ChartTooltipContent } from "@/components/ui/chart"
const chartConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
} satisfies import("@/components/ui/chart").ChartConfig
<ChartContainer config={chartConfig} className="min-h-[200px] w-full">
<BarChart data={data}>
<CartesianGrid vertical={false} />
<XAxis dataKey="month" />
<Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
<ChartTooltip content={<ChartTooltipContent />} />
</BarChart>
</ChartContainer>See references/charts-components.md for Line, Area, and Pie chart examples.
Examples
Login Form with Validation
"use client"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { z } from "zod"
import { Button } from "@/components/ui/button"
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
const formSchema = z.object({
email: z.string().email("Invalid email"),
password: z.string().min(8, "Min 8 characters"),
})
export function LoginForm() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: { email: "", password: "" },
})
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(console.log)} className="space-y-4">
<FormField name="email" control={form.control} render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl><Input type="email" {...field} /></FormControl>
<FormMessage />
</FormItem>
)} />
<FormField name="password" control={form.control} render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl><Input type="password" {...field} /></FormControl>
<FormMessage />
</FormItem>
)} />
<Button type="submit">Login</Button>
</form>
</Form>
)
}Data Table with Actions
import { ColumnDef } from "@tanstack/react-table"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import { DataTable } from "@/components/ui/data-table"
const columns: ColumnDef<User>[] = [
{ id: "select", header: ({ table }) => (
<Checkbox checked={table.getIsAllPageRowsSelected()} />
), cell: ({ row }) => (
<Checkbox checked={row.getIsSelected()} />
)},
{ accessorKey: "name", header: "Name" },
{ accessorKey: "email", header: "Email" },
{ id: "actions", cell: ({ row }) => (
<Button variant="ghost" size="sm">Edit</Button>
)},
]Dialog with Form
import { Button } from "@/components/ui/button"
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Add User</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Add New User</DialogTitle>
</DialogHeader>
{/* <LoginForm /> */}
</DialogContent>
</Dialog>Toast Notifications
import { useToast } from "@/components/ui/use-toast"
import { Button } from "@/components/ui/button"
const { toast } = useToast()
toast({ title: "Saved", description: "Changes saved successfully." })
toast({ variant: "destructive", title: "Error", description: "Failed to save." })Best Practices
- Accessibility: Use Radix UI primitives — ARIA attributes are built in
- Client Components: Add
"use client"for interactive components (hooks, events) - Type Safety: Use TypeScript and Zod schemas for form validation
- Theming: Configure CSS variables in
globals.cssfor consistent design - Customization: Modify component files directly — you own the code
- Path Aliases: Ensure
@alias is configured intsconfig.json - Registry Security: Only install components from trusted registries; review generated code before production use
- Dark Mode: Set up with CSS variables strategy and
next-themes - Forms: Always use
Form,FormField,FormItem,FormLabel,FormMessagetogether - Toaster: Add
<Toaster />once to root layout
Constraints and Warnings
- Not an NPM Package: Components are copied to your project; they are not a versioned dependency
- Registry Security: Components from
npx shadcn@latest addare fetched remotely; always verify the registry source is trusted before installation - Client Components: Most interactive components require
"use client"directive - Radix Dependencies: Ensure all
@radix-uipackages are installed - Tailwind Required: Components rely on Tailwind CSS utilities
- Path Aliases: Configure
@alias intsconfig.jsonfor imports
References
Consult these files for detailed patterns and code examples:
- [references/setup-and-configuration.md](references/setup-and-configuration.md) — Full installation, tsconfig, tailwind config, CSS variables
- [references/ui-components.md](references/ui-components.md) — Button, Input, Card, Dialog, Sheet, Select, Toast, Table, Menubar
- [references/forms-and-validation.md](references/forms-and-validation.md) — React Hook Form + Zod, advanced forms, login card, contact form
- [references/charts-components.md](references/charts-components.md) — Bar, Line, Area, Pie charts with ChartContainer and theming
- [references/nextjs-integration.md](references/nextjs-integration.md) — App Router, Server/Client Components, dark mode, metadata
- [references/customization.md](references/customization.md) — Custom variants, CSS variables, cn() utility, extending components
shadcn/ui Chart Component - Installation
Source: https://ui.shadcn.com/docs/components/chart
The chart component in shadcn/ui is built on Recharts, providing direct access to all Recharts capabilities with consistent theming.
npx shadcn@latest add chart--------------------------------
shadcn/ui Chart Component - Basic Usage
Source: https://ui.shadcn.com/docs/components/chart
The ChartContainer wraps your Recharts component and accepts a config prop for theming. Requires min-h-[value] for responsiveness.
import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts"
import { ChartContainer, ChartTooltipContent } from "@/components/ui/chart"
const chartConfig = {
desktop: {
label: "Desktop",
color: "var(--chart-1)",
},
mobile: {
label: "Mobile",
color: "var(--chart-2)",
},
} satisfies import("@/components/ui/chart").ChartConfig
const chartData = [
{ month: "January", desktop: 186, mobile: 80 },
{ month: "February", desktop: 305, mobile: 200 },
{ month: "March", desktop: 237, mobile: 120 },
]
export function BarChartDemo() {
return (
<ChartContainer config={chartConfig} className="min-h-[200px] w-full">
<BarChart data={chartData}>
<CartesianGrid vertical={false} />
<XAxis dataKey="month" tickLine={false} axisLine={false} />
<Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
<Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
<ChartTooltip content={<ChartTooltipContent />} />
</BarChart>
</ChartContainer>
)
}--------------------------------
shadcn/ui Chart Component - ChartConfig with Custom Colors
Source: https://ui.shadcn.com/docs/components/chart
You can define custom colors directly in the configuration using hex values or CSS variables.
const chartConfig = {
desktop: {
label: "Desktop",
color: "#2563eb",
theme: {
light: "#2563eb",
dark: "#60a5fa",
},
},
mobile: {
label: "Mobile",
color: "var(--chart-2)",
},
} satisfies import("@/components/ui/chart").ChartConfig--------------------------------
shadcn/ui Chart Component - CSS Variables
Source: https://ui.shadcn.com/docs/components/chart
Add chart color variables to your globals.css for consistent theming.
:root {
/* Chart colors */
--chart-1: oklch(0.646 0.222 41.116);
--chart-2: oklch(0.6 0.118 184.704);
--chart-3: oklch(0.546 0.198 38.228);
--chart-4: oklch(0.596 0.151 343.253);
--chart-5: oklch(0.546 0.158 49.157);
}
.dark {
--chart-1: oklch(0.488 0.243 264.376);
--chart-2: oklch(0.696 0.17 162.48);
--chart-3: oklch(0.698 0.141 24.311);
--chart-4: oklch(0.676 0.172 171.196);
--chart-5: oklch(0.578 0.192 302.85);
}--------------------------------
shadcn/ui Chart Component - Line Chart Example
Source: https://ui.shadcn.com/docs/components/chart
Creating a line chart with shadcn/ui charts component.
import { Line, LineChart, CartesianGrid, XAxis, YAxis } from "recharts"
import { ChartContainer, ChartTooltipContent } from "@/components/ui/chart"
const chartConfig = {
price: {
label: "Price",
color: "var(--chart-1)",
},
} satisfies import("@/components/ui/chart").ChartConfig
const chartData = [
{ month: "January", price: 186 },
{ month: "February", price: 305 },
{ month: "March", price: 237 },
{ month: "April", price: 203 },
{ month: "May", price: 276 },
]
export function LineChartDemo() {
return (
<ChartContainer config={chartConfig} className="min-h-[200px]">
<LineChart data={chartData}>
<CartesianGrid vertical={false} />
<XAxis dataKey="month" tickLine={false} axisLine={false} />
<YAxis tickLine={false} axisLine={false} tickFormatter={(value) => `$${value}`} />
<Line
dataKey="price"
stroke="var(--color-price)"
strokeWidth={2}
dot={false}
/>
<ChartTooltip content={<ChartTooltipContent />} />
</LineChart>
</ChartContainer>
)
}--------------------------------
shadcn/ui Chart Component - Area Chart Example
Source: https://ui.shadcn.com/docs/components/chart
Creating an area chart with gradient fill and legend.
import { Area, AreaChart, XAxis, YAxis } from "recharts"
import {
ChartContainer,
ChartLegend,
ChartLegendContent,
ChartTooltipContent,
} from "@/components/ui/chart"
const chartConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies import("@/components/ui/chart").ChartConfig
export function AreaChartDemo() {
return (
<ChartContainer config={chartConfig} className="min-h-[200px]">
<AreaChart data={chartData}>
<XAxis dataKey="month" tickLine={false} axisLine={false} />
<YAxis tickLine={false} axisLine={false} />
<Area
dataKey="desktop"
fill="var(--color-desktop)"
stroke="var(--color-desktop)"
fillOpacity={0.3}
/>
<Area
dataKey="mobile"
fill="var(--color-mobile)"
stroke="var(--color-mobile)"
fillOpacity={0.3}
/>
<ChartTooltip content={<ChartTooltipContent />} />
<ChartLegend content={<ChartLegendContent />} />
</AreaChart>
</ChartContainer>
)
}--------------------------------
shadcn/ui Chart Component - Pie Chart Example
Source: https://ui.shadcn.com/docs/components/chart
Creating a pie/donut chart with shadcn/ui.
import { Pie, PieChart } from "recharts"
import {
ChartContainer,
ChartLegend,
ChartLegendContent,
ChartTooltipContent,
} from "@/components/ui/chart"
const chartConfig = {
chrome: { label: "Chrome", color: "var(--chart-1)" },
safari: { label: "Safari", color: "var(--chart-2)" },
firefox: { label: "Firefox", color: "var(--chart-3)" },
} satisfies import("@/components/ui/chart").ChartConfig
const pieData = [
{ browser: "Chrome", visitors: 275, fill: "var(--color-chrome)" },
{ browser: "Safari", visitors: 200, fill: "var(--color-safari)" },
{ browser: "Firefox", visitors: 187, fill: "var(--color-firefox)" },
]
export function PieChartDemo() {
return (
<ChartContainer config={chartConfig} className="min-h-[200px]">
<PieChart>
<Pie
data={pieData}
dataKey="visitors"
nameKey="browser"
cx="50%"
cy="50%"
outerRadius={80}
/>
<ChartTooltip content={<ChartTooltipContent />} />
<ChartLegend content={<ChartLegendContent />} />
</PieChart>
</ChartContainer>
)
}--------------------------------
shadcn/ui ChartTooltipContent Props
Source: https://ui.shadcn.com/docs/components/chart
The ChartTooltipContent component accepts these props for customizing tooltip behavior.
| Prop | Type | Default | Description |
|---|---|---|---|
labelKey | string | "label" | Key for tooltip label |
nameKey | string | "name" | Key for tooltip name |
indicator | "dot" \ | "line" \ | "dashed" |
hideLabel | boolean | false | Hide label |
hideIndicator | boolean | false | Hide indicator |
--------------------------------
shadcn/ui Chart Component - Accessibility
Source: https://ui.shadcn.com/docs/components/chart
Enable keyboard navigation and screen reader support by adding the accessibilityLayer prop.
<BarChart accessibilityLayer data={chartData}>
<CartesianGrid vertical={false} />
<XAxis dataKey="month" />
<Bar dataKey="desktop" fill="var(--color-desktop)" />
<ChartTooltip content={<ChartTooltipContent />} />
</BarChart>This adds:
- Keyboard arrow key navigation
- ARIA labels for chart elements
- Screen reader announcements for data values
--------------------------------
shadcn/ui Chart Component - Recharts Dependencies
Source: https://ui.shadcn.com/docs/components/chart
The chart component requires the following Recharts dependencies to be installed.
pnpm add recharts
npm install recharts
yarn add rechartsRecharts provides the following chart types:
- Area, Bar, Line, Pie, Composed
- Radar, RadialBar, Scatter
- Funnel, Treemap
shadcn/ui - Charts Component Reference
Built on Recharts with consistent theming and styling.
Installation
npx shadcn@latest add chartCSS Variables for Charts
Add to globals.css:
@layer base {
:root {
--chart-1: oklch(0.646 0.222 41.116);
--chart-2: oklch(0.6 0.118 184.704);
--chart-3: oklch(0.546 0.198 38.228);
--chart-4: oklch(0.596 0.151 343.253);
--chart-5: oklch(0.546 0.158 49.157);
}
.dark {
--chart-1: oklch(0.488 0.243 264.376);
--chart-2: oklch(0.696 0.17 162.48);
--chart-3: oklch(0.698 0.141 24.311);
--chart-4: oklch(0.676 0.172 171.196);
--chart-5: oklch(0.578 0.192 302.85);
}
}ChartConfig and ChartContainer
ChartContainer wraps your Recharts component and accepts a config prop for theming.
import { Bar, BarChart, CartesianGrid, XAxis } from "recharts"
import { ChartContainer, ChartTooltipContent } from "@/components/ui/chart"
const chartConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies import("@/components/ui/chart").ChartConfig
const chartData = [
{ month: "January", desktop: 186, mobile: 80 },
{ month: "February", desktop: 305, mobile: 200 },
{ month: "March", desktop: 237, mobile: 120 },
]
export function BarChartDemo() {
return (
<ChartContainer config={chartConfig} className="min-h-[200px] w-full">
<BarChart data={chartData}>
<CartesianGrid vertical={false} />
<XAxis dataKey="month" tickLine={false} axisLine={false}
tickFormatter={(value) => value.slice(0, 3)} />
<Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
<Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />
<ChartTooltip content={<ChartTooltipContent />} />
</BarChart>
</ChartContainer>
)
}Custom Colors in ChartConfig
const chartConfig = {
visitors: {
label: "Visitors",
color: "#2563eb",
theme: {
light: "#2563eb",
dark: "#60a5fa",
},
},
sales: {
label: "Sales",
color: "var(--chart-1)",
theme: {
light: "oklch(0.646 0.222 41.116)",
dark: "oklch(0.696 0.182 281.41)",
},
},
} satisfies import("@/components/ui/chart").ChartConfigLine Chart
import { Line, LineChart, CartesianGrid, XAxis, YAxis } from "recharts"
import { ChartContainer, ChartTooltipContent } from "@/components/ui/chart"
const chartConfig = {
price: { label: "Price", color: "var(--chart-1)" },
} satisfies import("@/components/ui/chart").ChartConfig
export function LineChartDemo() {
return (
<ChartContainer config={chartConfig} className="min-h-[200px]">
<LineChart data={chartData}>
<CartesianGrid vertical={false} />
<XAxis dataKey="month" tickLine={false} axisLine={false} />
<YAxis tickLine={false} axisLine={false} tickFormatter={(v) => `$${v}`} />
<Line dataKey="price" stroke="var(--color-price)" strokeWidth={2} dot={false} />
<ChartTooltip content={<ChartTooltipContent />} />
</LineChart>
</ChartContainer>
)
}Area Chart
import { Area, AreaChart, XAxis, YAxis } from "recharts"
import {
ChartContainer, ChartLegend, ChartLegendContent, ChartTooltipContent,
} from "@/components/ui/chart"
const chartConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
mobile: { label: "Mobile", color: "var(--chart-2)" },
} satisfies import("@/components/ui/chart").ChartConfig
export function AreaChartDemo() {
return (
<ChartContainer config={chartConfig} className="min-h-[200px]">
<AreaChart data={chartData}>
<XAxis dataKey="month" tickLine={false} axisLine={false} />
<YAxis tickLine={false} axisLine={false} />
<Area dataKey="desktop" fill="var(--color-desktop)" stroke="var(--color-desktop)" fillOpacity={0.3} />
<Area dataKey="mobile" fill="var(--color-mobile)" stroke="var(--color-mobile)" fillOpacity={0.3} />
<ChartTooltip content={<ChartTooltipContent />} />
<ChartLegend content={<ChartLegendContent />} />
</AreaChart>
</ChartContainer>
)
}Pie Chart
import { Pie, PieChart } from "recharts"
import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltipContent } from "@/components/ui/chart"
const chartConfig = {
chrome: { label: "Chrome", color: "var(--chart-1)" },
safari: { label: "Safari", color: "var(--chart-2)" },
firefox: { label: "Firefox", color: "var(--chart-3)" },
} satisfies import("@/components/ui/chart").ChartConfig
const pieData = [
{ browser: "Chrome", visitors: 275, fill: "var(--color-chrome)" },
{ browser: "Safari", visitors: 200, fill: "var(--color-safari)" },
{ browser: "Firefox", visitors: 187, fill: "var(--color-firefox)" },
]
export function PieChartDemo() {
return (
<ChartContainer config={chartConfig} className="min-h-[200px]">
<PieChart>
<Pie data={pieData} dataKey="visitors" nameKey="browser" cx="50%" cy="50%" outerRadius={80} />
<ChartTooltip content={<ChartTooltipContent />} />
<ChartLegend content={<ChartLegendContent />} />
</PieChart>
</ChartContainer>
)
}ChartTooltipContent Props
| Prop | Type | Default | Description |
|---|---|---|---|
labelKey | string | "label" | Key for tooltip label |
nameKey | string | "name" | Key for tooltip name |
indicator | "dot" \ | "line" \ | "dashed" |
hideLabel | boolean | false | Hide label |
hideIndicator | boolean | false | Hide indicator |
Accessibility
Enable keyboard navigation and screen reader support:
<BarChart accessibilityLayer data={chartData}>...</BarChart>This adds keyboard arrow key navigation, ARIA labels, and screen reader announcements.
shadcn/ui - Customization
Theming with CSS Variables
shadcn/ui uses CSS variables for theming. Customize in globals.css:
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;
--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;
--muted: 210 40% 96.1%;
--muted-foreground: 215.4 16.3% 46.9%;
--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% 11.2%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 210 40% 98%;
--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;
--ring: 222.2 84% 4.9%;
--radius: 0.5rem;
}
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 11.2%;
/* ... other dark mode variables */
}
}Adding Custom Variants to Button
Since you own the code, extend components directly:
// components/ui/button.tsx
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline: "border border-input bg-background hover:bg-accent",
// Add custom variant
custom: "bg-gradient-to-r from-purple-500 to-pink-500 text-white",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
// Add custom size
xl: "h-14 rounded-md px-10 text-lg",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button"
return (
<Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
)
}
)
Button.displayName = "Button"
export { Button, buttonVariants }Custom Color Themes
To use a custom brand color as primary:
@layer base {
:root {
/* Custom brand color (blue) */
--primary: 217 91% 60%;
--primary-foreground: 0 0% 100%;
/* Custom accent (purple) */
--accent: 270 67% 47%;
--accent-foreground: 0 0% 100%;
}
}cn() Utility Function
The cn() utility combines clsx and tailwind-merge for conditional class names:
// lib/utils.ts
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
// Usage examples
cn("px-4 py-2", isActive && "bg-primary text-white")
cn("text-sm", size === "lg" && "text-lg", className)Extending a Component
Create wrapper components to add functionality without modifying the base:
// components/ui/loading-button.tsx
"use client"
import { Button, ButtonProps } from "@/components/ui/button"
import { Loader2 } from "lucide-react"
interface LoadingButtonProps extends ButtonProps {
loading?: boolean
}
export function LoadingButton({ loading, children, disabled, ...props }: LoadingButtonProps) {
return (
<Button disabled={loading || disabled} {...props}>
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
{children}
</Button>
)
}
// Usage
<LoadingButton loading={isSubmitting} type="submit">
Save Changes
</LoadingButton>components.json Configuration
The components.json file controls CLI behavior:
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "app/globals.css",
"baseColor": "slate",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
}
}Security: Only use trusted registry URLs in components.json. Never point to untrusted third-party registry endpoints.shadcn/ui - Forms and Validation
Installation
npx shadcn@latest add form input textarea select checkbox
npm install react-hook-form @hookform/resolvers zodBasic Form with Zod Validation
"use client"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import * as z from "zod"
import { Button } from "@/components/ui/button"
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form"
import { Input } from "@/components/ui/input"
const formSchema = z.object({
username: z.string().min(2, { message: "Username must be at least 2 characters." }),
email: z.string().email({ message: "Please enter a valid email address." }),
})
export function ProfileForm() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: { username: "", email: "" },
})
function onSubmit(values: z.infer<typeof formSchema>) {
console.log(values)
}
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
<FormField
control={form.control}
name="username"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<Input placeholder="shadcn" {...field} />
</FormControl>
<FormDescription>This is your public display name.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl>
<Input type="email" placeholder="you@example.com" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
)
}Advanced Form with Multiple Field Types
const formSchema = z.object({
username: z.string().min(2).max(50),
email: z.string().email(),
bio: z.string().max(160).min(4),
role: z.enum(["admin", "user", "guest"]),
notifications: z.boolean().default(false),
})
export function AdvancedForm() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
username: "",
email: "",
bio: "",
role: "user",
notifications: false,
},
})
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(console.log)} className="space-y-8">
{/* Text input */}
<FormField
control={form.control}
name="username"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl><Input placeholder="johndoe" {...field} /></FormControl>
<FormMessage />
</FormItem>
)}
/>
{/* Textarea */}
<FormField
control={form.control}
name="bio"
render={({ field }) => (
<FormItem>
<FormLabel>Bio</FormLabel>
<FormControl>
<Textarea placeholder="Tell us about yourself" className="resize-none" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{/* Select */}
<FormField
control={form.control}
name="role"
render={({ field }) => (
<FormItem>
<FormLabel>Role</FormLabel>
<Select onValueChange={field.onChange} defaultValue={field.value}>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select a role" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="admin">Admin</SelectItem>
<SelectItem value="user">User</SelectItem>
<SelectItem value="guest">Guest</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
{/* Checkbox */}
<FormField
control={form.control}
name="notifications"
render={({ field }) => (
<FormItem className="flex flex-row items-start space-x-3 space-y-0">
<FormControl>
<Checkbox checked={field.value} onCheckedChange={field.onChange} />
</FormControl>
<div className="space-y-1 leading-none">
<FormLabel>Email notifications</FormLabel>
<FormDescription>Receive emails about your account activity.</FormDescription>
</div>
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
)
}Login Form Pattern (Card + Form)
<Card className="w-[350px]">
<CardHeader>
<CardTitle>Login</CardTitle>
<CardDescription>Enter your credentials to continue</CardDescription>
</CardHeader>
<CardContent>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl>
<Input type="email" placeholder="you@example.com" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="password"
render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl>
<Input type="password" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit" className="w-full">Login</Button>
</form>
</Form>
</CardContent>
</Card>Contact Form with API Submission
"use client"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import * as z from "zod"
import { Button } from "@/components/ui/button"
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import { toast } from "@/components/ui/use-toast"
const formSchema = z.object({
name: z.string().min(2),
email: z.string().email(),
message: z.string().min(10),
})
async function onSubmit(values: z.infer<typeof formSchema>) {
try {
const response = await fetch("/api/contact", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(values),
})
if (!response.ok) throw new Error("Failed to submit")
toast({ title: "Success!", description: "Your message has been sent." })
} catch {
toast({ variant: "destructive", title: "Error", description: "Failed to send message." })
}
}
export default function ContactPage() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
})
return (
<div className="container mx-auto max-w-2xl py-8">
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
<FormField control={form.control} name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl><Input placeholder="Your name" {...field} /></FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField control={form.control} name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl><Input type="email" placeholder="your@email.com" {...field} /></FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField control={form.control} name="message"
render={({ field }) => (
<FormItem>
<FormLabel>Message</FormLabel>
<FormControl>
<Textarea placeholder="Your message..." className="resize-none" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit" className="w-full">Send Message</Button>
</form>
</Form>
</div>
)
}Route Handler for Form Validation (API)
// app/api/contact/route.ts
import { NextRequest, NextResponse } from "next/server"
import { z } from "zod"
const contactSchema = z.object({
name: z.string().min(2),
email: z.string().email(),
message: z.string().min(10),
})
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const validated = contactSchema.parse(body)
console.log("Form submission:", validated)
return NextResponse.json({ success: true })
} catch (error) {
if (error instanceof z.ZodError) {
return NextResponse.json({ errors: error.errors }, { status: 400 })
}
return NextResponse.json({ error: "Internal server error" }, { status: 500 })
}
}shadcn/ui Learning Guide
This guide helps you learn shadcn/ui from basics to advanced patterns.
Learning Path
1. Understanding the Philosophy
shadcn/ui is different from traditional component libraries:
- Copy-paste components: Components are copied into your project, not installed as packages
- Full customization: You own the code and can modify it freely
- Built on Radix UI: Provides accessibility primitives
- Styled with Tailwind: Uses utility classes for consistent styling
2. Core Concepts to Master
Class Variance Authority (CVA)
Most components use CVA for variant management:
const buttonVariants = cva(
"base-classes",
{
variants: {
variant: {
default: "variant-classes",
destructive: "destructive-classes",
},
size: {
default: "size-classes",
sm: "small-classes",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)cn Utility Function
The cn function combines classes and resolves conflicts:
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}3. Installation Checklist
- [ ] Initialize a new project (Next.js, Vite, or Remix)
- [ ] Install Tailwind CSS
- [ ] Run
npx shadcn@latest init - [ ] Configure CSS variables
- [ ] Install first component:
npx shadcn@latest add button
4. Essential Components to Learn First
1. Button - Learn variants and sizes 2. Input - Form inputs with labels 3. Card - Container components 4. Form - Form handling with React Hook Form 5. Dialog - Modal windows 6. Select - Dropdown selections 7. Toast - Notifications
5. Common Patterns
Form Pattern
Every form follows this structure:
1. Define Zod schema
2. Create form with useForm
3. Wrap with Form component
4. Add FormField for each input
5. Handle submissionComponent Customization Pattern
To customize a component:
1. Copy component to your project 2. Modify the variants 3. Add new props if needed 4. Update types
6. Best Practices
- Always use TypeScript
- Follow the existing component structure
- Use semantic HTML when possible
- Test with screen readers for accessibility
- Keep components small and focused
7. Advanced Topics
- Creating custom components from scratch
- Building complex forms with validation
- Implementing dark mode
- Optimizing for performance
- Testing components
Practice Exercises
Exercise 1: Basic Setup
1. Create a new Next.js project 2. Set up shadcn/ui 3. Install and customize a Button component 4. Add a new variant "gradient"
Exercise 2: Form Building
1. Create a contact form with:
- Name input (required)
- Email input (email validation)
- Message textarea (min length)
- Submit button with loading state
Exercise 3: Component Combination
1. Build a settings page using:
- Card for layout
- Sheet for mobile menu
- Select for dropdowns
- Switch for toggles
- Toast for notifications
Exercise 4: Custom Component
1. Create a custom Badge component 2. Support variants: default, secondary, destructive, outline 3. Support sizes: sm, default, lg 4. Add icon support
Resources
shadcn/ui - Next.js Integration
App Router Setup
Most shadcn/ui components require "use client" directive when used with App Router. Static display components (Card, Table) can work in Server Components without the directive.
// src/components/ui/button.tsx — already includes "use client" after npx shadcn@latest add button
"use client"
import * as React from "react"
// ... rest of componentRoot Layout with Toaster
// app/layout.tsx
import { Inter } from "next/font/google"
import { Toaster } from "@/components/ui/toaster"
import { cn } from "@/lib/utils"
import "./globals.css"
const inter = Inter({ subsets: ["latin"] })
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<body className={cn("min-h-screen bg-background font-sans antialiased", inter.className)}>
{children}
<Toaster />
</body>
</html>
)
}Server Components with Interactive Elements
When using interactive shadcn/ui components in Server Components, wrap them in a Client Component:
// app/dashboard/page.tsx — Server Component
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { ButtonClient } from "@/components/button-client"
export default function DashboardPage() {
return (
<div className="container mx-auto p-6">
<Card>
<CardHeader>
<CardTitle>Dashboard</CardTitle>
</CardHeader>
<CardContent>
<ButtonClient>Interactive Button</ButtonClient>
</CardContent>
</Card>
</div>
)
}// src/components/button-client.tsx — Client Component wrapper
"use client"
import { Button } from "@/components/ui/button"
export function ButtonClient(props: React.ComponentProps<typeof Button>) {
return <Button {...props} />
}Metadata with shadcn/ui Pages
// app/layout.tsx
import { Metadata } from "next"
export const metadata: Metadata = {
title: { default: "My App", template: "%s | My App" },
description: "Built with shadcn/ui and Next.js",
}// app/about/page.tsx
import { Metadata } from "next"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
export const metadata: Metadata = {
title: "About Us",
description: "Learn more about our company",
}
export default function AboutPage() {
return (
<div className="container mx-auto py-8">
<Card>
<CardHeader><CardTitle>About Our Company</CardTitle></CardHeader>
<CardContent>
<p>We build amazing products with modern web technologies.</p>
</CardContent>
</Card>
</div>
)
}Dark Mode Setup
With next-themes
npm install next-themes// components/theme-provider.tsx
"use client"
import { ThemeProvider as NextThemesProvider } from "next-themes"
export function ThemeProvider({ children, ...props }) {
return <NextThemesProvider {...props}>{children}</NextThemesProvider>
}// app/layout.tsx
import { ThemeProvider } from "@/components/theme-provider"
export default function RootLayout({ children }) {
return (
<html lang="en" suppressHydrationWarning>
<body>
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
{children}
</ThemeProvider>
</body>
</html>
)
}Theme Toggle Component
"use client"
import { useTheme } from "next-themes"
import { Button } from "@/components/ui/button"
import { Moon, Sun } from "lucide-react"
export function ThemeToggle() {
const { theme, setTheme } = useTheme()
return (
<Button variant="ghost" size="icon"
onClick={() => setTheme(theme === "dark" ? "light" : "dark")}>
<Sun className="h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<Moon className="absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
</Button>
)
}shadcn/ui Official Reference
Security Note: Components installed vianpx shadcn@latest addare fetched from the official shadcn registry (ui.shadcn.com). When configuring custom registries, only use trusted registry URLs. Always review component source code after installation. Registry URLs in examples below (e.g.,example.com) are placeholders — replace with your verified private registry URLs.
Create TanStack Start Project with shadcn/ui
Source: https://ui.shadcn.com/docs/installation/tanstack
Initialize a new TanStack Start project with Tailwind CSS and shadcn/ui add-ons pre-configured. This command sets up the project structure and installs necessary dependencies in one command.
npm create @tanstack/start@latest --tailwind --add-ons shadcn--------------------------------
Install All shadcn/ui Components
Source: https://ui.shadcn.com/docs/installation/tanstack
Bulk install all available shadcn/ui components into your project at once. This is useful when you want access to the entire component library without adding components individually.
npx shadcn@latest add --all--------------------------------
Manually Install Radix UI Select Dependency
Source: https://ui.shadcn.com/docs/components/select
This command shows how to install the core @radix-ui/react-select primitive package. This manual installation is necessary if you prefer not to use the Shadcn UI CLI for component setup.
npm install @radix-ui/react-select--------------------------------
Install Progress Component Dependencies
Source: https://ui.shadcn.com/docs/components/progress
This section provides instructions for installing the Progress component and its core dependencies. It covers both using the Shadcn UI CLI for automated setup and manual installation via npm for the underlying Radix UI component.
npx shadcn@latest add progressnpm install @radix-ui/react-progress--------------------------------
Serve shadcn Registry with Next.js Development Server
Source: https://ui.shadcn.com/docs/registry/getting-started
This command starts the Next.js development server, which will serve your shadcn registry files if your project is configured with Next.js. The registry items will be accessible via specific URLs under /r/ after the build process.
npm run dev--------------------------------
Install shadcn CLI via npm
Source: https://ui.shadcn.com/docs/registry/getting-started
This command installs the latest version of the shadcn command-line interface (CLI) globally or as a dev dependency in your project. The CLI is essential for building and managing shadcn component registries and components.
npm install shadcn@latest--------------------------------
Create New Laravel Project with React
Source: https://ui.shadcn.com/docs/installation/laravel
Initialize a new Laravel project with Inertia and React using the Laravel installer. This command creates a fresh Laravel application with React pre-configured for use with Inertia.js.
laravel new my-app --react--------------------------------
Install Shadcn UI Input OTP Component (CLI & Manual)
Source: https://ui.shadcn.com/docs/components/input-otp
Provides instructions for adding the Input OTP component to a project. Users can choose between the Shadcn UI CLI for automated setup or manual installation by adding the core input-otp dependency via npm and then integrating the component files.
npx shadcn@latest add input-otpnpm install input-otp--------------------------------
Install Aspect Ratio Component via CLI
Source: https://ui.shadcn.com/docs/components/aspect-ratio
Installs the aspect-ratio component and its dependencies using the shadcn CLI. This is the quickest installation method that automatically handles dependency installation and file setup.
npx shadcn@latest add aspect-ratio--------------------------------
Install Dropdown Menu Component with NPM
Source: https://ui.shadcn.com/docs/components/dropdown-menu
Installation command for adding the dropdown menu component to a project using shadcn/ui CLI tool. This is the recommended method for quick setup with automatic dependency management.
npx shadcn@latest add dropdown-menu--------------------------------
Define Universal Registry Item for Multi-File Template (shadcn/ui)
Source: https://ui.shadcn.com/docs/registry/examples
This JSON configuration defines a shadcn/ui registry item named 'my-custom-start-template' that installs multiple files. It includes two files, each with an explicit target path, demonstrating how to create a universal starter template that can be installed without framework detection or components.json.
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "my-custom-start-template",
"type": "registry:item",
"dependencies": ["better-auth"],
"files": [
{
"path": "/path/to/file-01.json",
"type": "registry:file",
"target": "~/file-01.json",
"content": "..."
},
{
"path": "/path/to/file-02.vue",
"type": "registry:file",
"target": "~/pages/file-02.vue",
"content": "..."
}
]
}--------------------------------
Add shadcn/ui Button Component
Source: https://ui.shadcn.com/docs/installation/tanstack
Install the Button component from shadcn/ui into your TanStack Start project. This command downloads and configures the component in your project's component directory.
npx shadcn@latest add button--------------------------------
Install Form Component via Shadcn CLI
Source: https://ui.shadcn.com/docs/components/form
This command provides the recommended method for installing the Shadcn UI form component using its command-line interface. Executing this command automates the addition of the form component and its dependencies to your project, simplifying the setup process.
npx shadcn@latest add form--------------------------------
Basic Navigation Menu Setup - React TSX
Source: https://ui.shadcn.com/docs/components/navigation-menu
Minimal example demonstrating the basic structure of a Navigation Menu with one menu item, trigger, and content link. Serves as a foundation for more complex navigation patterns.
Item OneLink--------------------------------
Multiple Registry Setup with Mixed Authentication
Source: https://ui.shadcn.com/docs/components-json
Complete example showing how to configure multiple registries with different authentication methods and parameters. Demonstrates public registries, private registries with bearer tokens, and team registries with versioning and environment variables.
{
"registries": {
"@shadcn": "https://ui.shadcn.com/r/{name}.json",
"@company-ui": {
"url": "https://registry.company.com/ui/{name}.json",
"headers": {
"Authorization": "Bearer ${COMPANY_TOKEN}"
}
},
"@team": {
"url": "https://team.company.com/{name}.json",
"params": {
"team": "frontend",
"version": "${REGISTRY_VERSION}"
}
}
}
}--------------------------------
Add Component Definition to shadcn registry.json
Source: https://ui.shadcn.com/docs/registry/getting-started
This JSON snippet shows how to register a component, like hello-world, within the registry.json file. It includes metadata such as name, type, title, description, and defines the component's file path and type, ensuring it conforms to the registry item schema.
{
"$schema": "https://ui.shadcn.com/schema/registry.json",
"name": "acme",
"homepage": "https://acme.com",
"items": [
{
"name": "hello-world",
"type": "registry:block",
"title": "Hello World",
"description": "A simple hello world component.",
"files": [
{
"path": "registry/new-york/hello-world/hello-world.tsx",
"type": "registry:component"
}
]
}
]
}--------------------------------
Install Project Dependencies using npm
Source: https://ui.shadcn.com/docs/installation/manual
This bash command installs a set of essential npm packages for the project. These dependencies include utilities for styling (class-variance-authority, clsx, tailwind-merge), icon library (lucide-react), and animation effects (tw-animate-css).
npm install class-variance-authority clsx tailwind-merge lucide-react tw-animate-css--------------------------------
Install React Resizable Panels Dependency Manually
Source: https://ui.shadcn.com/docs/components/resizable
This npm command installs the core react-resizable-panels library, which the Resizable component is built upon. It is a prerequisite for manual setup and provides the underlying functionality for resizable UI elements.
npm install react-resizable-panels--------------------------------
Install Shadcn UI Skeleton component using CLI
Source: https://ui.shadcn.com/docs/components/skeleton
Provides the command-line instruction to add the Skeleton component to your project if you are using Shadcn UI's CLI. This automates the setup process for the component.
npx shadcn@latest add skeleton--------------------------------
Install Dependencies with pnpm
Source: https://ui.shadcn.com/docs/blocks
Installs project dependencies using pnpm package manager. Required before starting development on the block.
pnpm install--------------------------------
Install Pagination Component - Bash CLI
Source: https://ui.shadcn.com/docs/components/pagination
Command-line installation of the pagination component using the shadcn CLI tool. This is the recommended installation method for projects using shadcn/ui.
npx shadcn@latest add pagination--------------------------------
Install Sonner Dependencies Manually
Source: https://ui.shadcn.com/docs/components/sonner
Manual installation command that installs Sonner and next-themes packages required for manual setup. Use this approach when you prefer to manually configure the component instead of using the CLI.
npm install sonner next-themes--------------------------------
Install Radix UI Separator Dependency via npm
Source: https://ui.shadcn.com/docs/components/separator
Install the core Radix UI React Separator dependency required for manual setup. Use this command when manually installing the component instead of using the CLI.
npm install @radix-ui/react-separator--------------------------------
Install Checkbox Component via CLI - Bash
Source: https://ui.shadcn.com/docs/components/checkbox
Command-line installation method for adding the checkbox component to a shadcn/ui project. Automatically handles component setup and dependency installation.
npx shadcn@latest add checkbox--------------------------------
Install Aspect Ratio Dependencies Manually
Source: https://ui.shadcn.com/docs/components/aspect-ratio
Manually installs the required Radix UI aspect-ratio dependency. Use this approach when you prefer manual setup or when the CLI method is not suitable for your project.
npm install @radix-ui/react-aspect-ratio--------------------------------
Install Input Component via CLI
Source: https://ui.shadcn.com/docs/components/input
Install the Input component using the shadcn CLI tool. This command downloads and sets up the component in your project's components directory with all necessary dependencies.
npx shadcn@latest add input--------------------------------
Create Remix Project with create-remix
Source: https://ui.shadcn.com/docs/installation/remix
Initialize a new Remix project using the create-remix command-line tool. This sets up the basic Remix application structure and dependencies.
npx create-remix@latest my-app--------------------------------
Install Shadcn UI Context Menu component via CLI (Bash)
Source: https://ui.shadcn.com/docs/components/context-menu
This command demonstrates how to easily add the Shadcn UI Context Menu component to your project using the npx shadcn@latest add command-line utility. This method automates the setup and configuration of the component.
npx shadcn@latest add context-menu--------------------------------
Install Vaul Dependency for Manual Setup
Source: https://ui.shadcn.com/docs/components/drawer
Manually install the Vaul package as a dependency when setting up the Drawer component without the CLI. Vaul is the underlying library that powers the Drawer functionality.
npm install vaul--------------------------------
Install Recharts Dependency via npm
Source: https://ui.shadcn.com/docs/components/chart
Installs the Recharts library as a project dependency for manual setup. Required when not using the CLI installation method.
npm install recharts--------------------------------
Install Shadcn UI Command Component
Source: https://ui.shadcn.com/docs/components/command
This section provides instructions for installing the Command menu component, offering both an automated CLI approach and a manual method. The CLI command automatically adds the component, while the manual installation requires installing the 'cmdk' package and then copying the component source code separately.
npx shadcn@latest add commandnpm install cmdk--------------------------------
Install Components from Multiple Namespaced Registries
Source: https://ui.shadcn.com/docs/changelog
Use the @registry/name format to install components from different namespaced registries in a single command. Components are automatically resolved and installed from the correct registry sources.
npx shadcn add @acme/button @internal/auth-system--------------------------------
Install Block and Override Primitives in shadcn/ui
Source: https://ui.shadcn.com/docs/registry/examples
Configure a registry item to install a block from shadcn/ui and override default primitives with custom implementations from remote registries. This enables centralized dependency management for component hierarchies.
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "custom-login",
"type": "registry:block",
"registryDependencies": [
"login-01",
"https://example.com/r/button.json",
"https://example.com/r/input.json",
"https://example.com/r/label.json"
]
}--------------------------------
Define Initial shadcn registry.json Structure
Source: https://ui.shadcn.com/docs/registry/getting-started
This JSON snippet illustrates the basic structure for a registry.json file, which serves as the entry point for a shadcn component registry. It includes the schema reference, registry name, homepage URL, and an empty array for registry items, conforming to the specified registry schema.
{
"$schema": "https://ui.shadcn.com/schema/registry.json",
"name": "acme",
"homepage": "https://acme.com",
"items": [
// ...
]
}--------------------------------
List All Components from a Registry
Source: https://ui.shadcn.com/docs/changelog
Display all available components from a specified namespaced registry. Useful for discovering available components before installation.
npx shadcn list @acme--------------------------------
Execute shadcn Registry Build Script
Source: https://ui.shadcn.com/docs/registry/getting-started
This command runs the registry:build script defined in package.json. Executing this script triggers the shadcn CLI to generate the registry JSON files, typically placed in a public/r directory by default.
npm run registry:build--------------------------------
Install Shadcn UI Select Component via CLI
Source: https://ui.shadcn.com/docs/components/select
This command illustrates the quickest way to add the Shadcn UI Select component to your project. It utilizes the npx shadcn@latest add utility to automatically install dependencies and configure the component.
npx shadcn@latest add select--------------------------------
Configure shadcn Build Script in package.json
Source: https://ui.shadcn.com/docs/registry/getting-started
This JSON snippet updates the package.json file by adding a registry:build script. This script executes the shadcn build command, which is used to generate the necessary JSON files for the component registry.
{
"scripts": {
"registry:build": "shadcn build"
}
}--------------------------------
Install Resources from Namespaced Registries
Source: https://ui.shadcn.com/docs/components-json
Install components and resources using the namespace syntax after configuring registries. Supports installing from public registries, private authenticated registries, and multiple resources in a single command.
# Install from a configured registry
npx shadcn@latest add @v0/dashboard
# Install from private registry
npx shadcn@latest add @private/button
# Install multiple resources
npx shadcn@latest add @acme/header @internal/auth-utils--------------------------------
Install Kbd Component via CLI (shadcn/ui)
Source: https://ui.shadcn.com/docs/components/kbd
Provides the command-line interface instruction to add the Kbd component to a project using shadcn@latest. This is the recommended and easiest method for integrating the component.
npx shadcn@latest add kbd--------------------------------
Handle shadcn/ui Initialization with React 19 Peer Dependency Prompt (npm)
Source: https://ui.shadcn.com/docs/react-19
This bash snippet illustrates the interactive prompt from the shadcn/ui CLI when initializing a project (npx shadcn@latest init -d) while using React 19 with npm. It guides users to select a resolution strategy, either --force or --legacy-peer-deps, to address potential peer dependency conflicts during the shadcn/ui installation process.
It looks like you are using React 19.
Some packages may fail to install due to peer dependency issues (see https://ui.shadcn.com/react-19).
? How would you like to proceed? › - Use arrow-keys. Return to submit.
❯ Use --force
Use --legacy-peer-deps--------------------------------
Install shadcn/ui Label Component via CLI
Source: https://ui.shadcn.com/docs/components/label
This bash command uses the shadcn/ui CLI to quickly add the Label component to your project. It automates the process of fetching and integrating the component's files and dependencies, streamlining setup.
npx shadcn@latest add label--------------------------------
Add Components to Monorepo Workspace
Source: https://ui.shadcn.com/docs/monorepo
Add shadcn/ui components to your monorepo application by navigating to the app directory and running the add command. The CLI automatically determines component type and installs files to correct paths with proper import handling.
cd apps/web
npx shadcn@latest add [COMPONENT]--------------------------------
Install Shadcn UI Spinner Component via CLI (Bash)
Source: https://ui.shadcn.com/docs/components/spinner
Provides the command-line interface (CLI) instruction to add the Shadcn UI Spinner component to your project. This command automates the setup, including creating the component file and configuring necessary dependencies. Ensure you have the Shadcn UI CLI installed globally or locally before running this command.
npx shadcn@latest add spinner--------------------------------
Install Drawer Component via CLI
Source: https://ui.shadcn.com/docs/components/drawer
Install the shadcn Drawer component using the CLI tool. This is the recommended installation method that automatically sets up all dependencies and copies necessary files to your project.
npx shadcn@latest add drawer--------------------------------
Install Navigation Menu via CLI - shadcn/ui
Source: https://ui.shadcn.com/docs/components/navigation-menu
Quick installation command for adding the navigation-menu component to a shadcn/ui project using the CLI tool. Requires Node.js and npm to be installed.
npx shadcn@latest add navigation-menu--------------------------------
View Registry Component Before Installation
Source: https://ui.shadcn.com/docs/changelog
Preview a component from a namespaced registry without installing it. Displays component code and all dependencies upfront for review.
npx shadcn view @acme/auth-system--------------------------------
Install Shadcn Hover Card Component via CLI
Source: https://ui.shadcn.com/docs/components/hover-card
This command-line interface (CLI) snippet demonstrates how to add the Shadcn UI Hover Card component to your project using npx shadcn@latest add. This method automates the installation and setup process for the component, including copying necessary files and updating configurations.
npx shadcn@latest add hover-card--------------------------------
Install Toggle Group Dependencies via npm
Source: https://ui.shadcn.com/docs/components/toggle-group
Install the required Radix UI toggle group dependency manually using npm. Required for projects that prefer manual component setup.
npm install @radix-ui/react-toggle-group--------------------------------
Import and Use Button Component in TanStack Start
Source: https://ui.shadcn.com/docs/installation/tanstack
Import the Button component from the components/ui directory and render it in your application. This example shows basic usage within a React functional component in the app/routes/index.tsx file.
import { Button } from "@/components/ui/button"
function App() {
return (
Click me
)
}--------------------------------
Install Carousel Component via CLI
Source: https://ui.shadcn.com/docs/components/carousel
shadcn/ui CLI command to automatically install and configure the carousel component with all dependencies and file setup. Simplest method for adding the carousel to your project.
npx shadcn@latest add carousel--------------------------------
Install Resizable Component using Shadcn CLI
Source: https://ui.shadcn.com/docs/components/resizable
This command-line interface (CLI) snippet shows how to add the resizable component to a project using the shadcn utility. It simplifies the installation process by automatically configuring the component and its dependencies.
npx shadcn@latest add resizable--------------------------------
Install Menubar via CLI - Bash
Source: https://ui.shadcn.com/docs/components/menubar
Command to install the menubar component using the shadcn package manager CLI. This is the quickest installation method that automatically downloads and configures the component for your project.
npx shadcn@latest add menubar--------------------------------
Install Radio Group via CLI - Bash
Source: https://ui.shadcn.com/docs/components/radio-group
Command-line interface installation method for adding the radio-group component to a shadcn/ui project. This is the recommended approach as it automatically handles file copying and setup.
npx shadcn@latest add radio-group--------------------------------
Define reusable registry block with components
Source: https://ui.shadcn.com/docs/registry/examples
Create a registry block item that bundles multiple related files (pages and components) with their dependencies. This block specifies registry dependencies on other components and defines file paths with content references for installation into target locations in the project structure.
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "login-01",
"type": "registry:block",
"description": "A simple login form.",
"registryDependencies": ["button", "card", "input", "label"],
"files": [
{
"path": "blocks/login-01/page.tsx",
"content": "import { LoginForm } ...",
"type": "registry:page",
"target": "app/login/page.tsx"
},
{
"path": "blocks/login-01/components/login-form.tsx",
"content": "...",
"type": "registry:component"
}
]
}--------------------------------
Install Radix UI Context Menu dependency manually (Bash)
Source: https://ui.shadcn.com/docs/components/context-menu
This command is part of the manual installation process, showing how to install the core @radix-ui/react-context-menu dependency using npm. This dependency provides the fundamental building blocks for the Shadcn UI Context Menu.
npm install @radix-ui/react-context-menu--------------------------------
Install Native Select component via CLI
Source: https://ui.shadcn.com/docs/components/native-select
Use the shadcn CLI to easily add the Native Select component to your project. This command will scaffold the necessary files and update dependencies automatically, streamlining the setup process.
npx shadcn@latest add native-select--------------------------------
Install Empty Component via CLI
Source: https://ui.shadcn.com/docs/components/empty
Command to install the Empty component using the shadcn package manager. Automatically adds the component and its dependencies to the project.
npx shadcn@latest add empty--------------------------------
Install shadcn Table component and TanStack React Table
Source: https://ui.shadcn.com/docs/components/data-table
Installation commands to add the Table component from shadcn and the TanStack React Table dependency to your project. These are prerequisites for building data tables with this guide.
npx shadcn@latest add tablenpm install @tanstack/react-table--------------------------------
Install Switch Component via CLI
Source: https://ui.shadcn.com/docs/components/switch
Command-line installation method for adding the Switch component to a shadcn/ui project. Uses the official CLI tool to automatically download and configure the component with all required dependencies.
npx shadcn@latest add switch--------------------------------
Start Development Server with pnpm
Source: https://ui.shadcn.com/docs/blocks
Starts the development server for the www application at http://localhost:3333. Enables live preview of blocks during development.
pnpm www:dev--------------------------------
Install Shadcn UI Badge component via CLI (Bash)
Source: https://ui.shadcn.com/docs/components/badge
This command line interface snippet demonstrates how to add the Shadcn UI Badge component to a project using the npx shadcn utility. It simplifies the setup process by automating the component file generation.
npx shadcn@latest add badge--------------------------------
Interactive Configuration Questions for shadcn init
Source: https://ui.shadcn.com/docs/changelog
Configuration prompts displayed during the shadcn init setup process. Users answer questions about style, base color, CSS file location, CSS variables usage, Tailwind config path, component/utils import aliases, and React Server Components support.
Which style would you like to use? › Default
Which color would you like to use as base color? › Slate
Where is your global CSS file? › › app/globals.css
Do you want to use CSS variables for colors? › no / yes
Where is your tailwind.config.js located? › tailwind.config.js
Configure the import alias for components: › @/components
Configure the import alias for utils: › @/lib/utils
Are you using React Server Components? › no / yes--------------------------------
Item Component Installation - Bash
Source: https://ui.shadcn.com/docs/components/item
CLI command to install the Item component from shadcn. Requires Node.js and npm/pnpm package manager.
npx shadcn@latest add item--------------------------------
CLI Command: Initialize Project from Local File
Source: https://ui.shadcn.com/docs/changelog
The shadcn CLI now supports initializing projects from local JSON files. This command allows users to set up a project using a local template.json, enabling zero-setup development and local testing of registry items.
npx shadcn init ./template.json--------------------------------
Install Tailwind CSS and Autoprefixer
Source: https://ui.shadcn.com/docs/installation/remix
Install Tailwind CSS and Autoprefixer as development dependencies to enable styling support for shadcn/ui components in your Remix project.
npm install -D tailwindcss@latest autoprefixer@latest--------------------------------
Install Tooltip Dependencies via npm
Source: https://ui.shadcn.com/docs/components/tooltip
Manual installation of the Radix UI tooltip dependency. Required when not using the shadcn CLI installation method. Install this package before copying the tooltip component source.
npm install @radix-ui/react-tooltip--------------------------------
Install Shadcn UI Dialog component using CLI or npm
Source: https://ui.shadcn.com/docs/components/dialog
Instructions for installing the Shadcn UI Dialog component. Provides options for using the Shadcn CLI to add the component or manually installing the underlying Radix UI dependency.
npx shadcn@latest add dialognpm install @radix-ui/react-dialog--------------------------------
Install Toggle Component via CLI
Source: https://ui.shadcn.com/docs/components/toggle
Install the Toggle component using the shadcn CLI tool. This command downloads and sets up the component with all dependencies in your project.
npx shadcn@latest add toggle--------------------------------
Install Sheet Component via CLI
Source: https://ui.shadcn.com/docs/components/sheet
Command to install the Sheet component and its dependencies using the shadcn CLI. This is the recommended installation method for projects using shadcn/ui.
npx shadcn@latest add sheet--------------------------------
Install Shadcn UI Popover component
Source: https://ui.shadcn.com/docs/components/popover
These commands provide two methods for installing the Popover component into your project. The CLI method uses npx shadcn to add the component automatically, while the manual method involves installing the core Radix UI dependency via npm and then copying the component source code. Ensure your project is set up to use shadcn/ui before installing components.
npx shadcn@latest add popovernpm install @radix-ui/react-popover--------------------------------
Install Sonner via CLI
Source: https://ui.shadcn.com/docs/components/sonner
Command-line installation method using shadcn-cli to add the Sonner component to a project. This is the quickest way to set up Sonner with all necessary dependencies.
npx shadcn@latest add sonner--------------------------------
Complete Bar Chart with XAxis Implementation
Source: https://ui.shadcn.com/docs/components/chart
Full React component example using the 'use client' directive for client-side rendering. Demonstrates a complete bar chart setup with sample data for desktop and mobile metrics across six months, including XAxis configuration with custom tick formatting.
"use client"
import { Bar, BarChart, CartesianGrid, XAxis } from "recharts"
import { ChartConfig, ChartContainer } from "@/components/ui/chart"
const chartData = [
{ month: "January", desktop: 186, mobile: 80 },
{ month: "February", desktop: 305, mobile: 200 },
{ month: "March", desktop: 237, mobile: 120 },
{ month: "April", desktop: 73, mobile: 190 },
{ month: "May", desktop: 209, mobile: 130 },
{ month: "June", desktop: 214, mobile: 140 },
]
const chartConfig = {
desktop: {
label: "Desktop",
color: "#2563eb",
},
mobile: {
label: "Mobile",
color: "#60a5fa",
},
} satisfies ChartConfig
export function Component() {
return (
value.slice(0, 3)}
/>
)
}--------------------------------
Environment Variables Setup
Source: https://ui.shadcn.com/docs/registry/authentication
Set registry authentication token in .env.local file. This stores the secret token that will be used for Bearer authentication when accessing private component registries.
REGISTRY_TOKEN=your_secret_token_here--------------------------------
Install Table Component via CLI
Source: https://ui.shadcn.com/docs/components/table
CLI command to install the shadcn/ui Table component using npx. This automatically adds the component to your project.
npx shadcn@latest add table--------------------------------
Install next-themes package
Source: https://ui.shadcn.com/docs/dark-mode/next
This command installs the next-themes package, a crucial dependency for implementing dark mode functionality in Next.js applications.
npm install next-themes--------------------------------
Install Separator Component via CLI
Source: https://ui.shadcn.com/docs/components/separator
Install the Separator component using the shadcn CLI tool. This command automatically downloads and sets up the component in your project with all required dependencies.
npx shadcn@latest add separator--------------------------------
Install Menubar Dependencies - Bash
Source: https://ui.shadcn.com/docs/components/menubar
Manual installation command for the Radix UI menubar dependency. Use this when manually setting up the component instead of using the CLI. Requires Node.js package manager (npm).
npm install @radix-ui/react-menubar--------------------------------
Install Tooltip via shadcn CLI
Source: https://ui.shadcn.com/docs/components/tooltip
Command-line installation method for adding the Tooltip component to a shadcn/ui project. This is the recommended approach for quickly adding pre-configured component files.
npx shadcn@latest add tooltip--------------------------------
Install Slider Component via CLI
Source: https://ui.shadcn.com/docs/components/slider
Command-line installation method for adding the Slider component to a shadcn/ui project. This is the quickest way to install the component and its dependencies.
npx shadcn@latest add slider--------------------------------
Install Shadcn Alert component via CLI
Source: https://ui.shadcn.com/docs/components/alert
This command provides a quick way to add the Shadcn Alert component to your project using the command-line interface. It leverages npx to execute the shadcn utility for component installation.
npx shadcn@latest add alert--------------------------------
Create a Basic shadcn Component in TSX
Source: https://ui.shadcn.com/docs/registry/getting-started
This TypeScript React (TSX) code defines a simple HelloWorld component that renders a button with 'Hello World' text. It imports the Button component from a local UI library, demonstrating how to structure a component intended for the shadcn registry.
import { Button } from "@/components/ui/button"
export function HelloWorld() {
return Hello World
}--------------------------------
Install Radix UI Switch Dependency
Source: https://ui.shadcn.com/docs/components/switch
NPM installation command for the Radix UI switch primitive dependency. Required when manually installing the Switch component without using the shadcn CLI tool.
npm install @radix-ui/react-switch--------------------------------
Button Size Variants Example
Source: https://ui.shadcn.com/docs/components/button
Comprehensive example showing all Button size options: sm, icon-sm, default, icon, lg, and icon-lg. Demonstrates text and icon buttons at different sizes.
import { ArrowUpRightIcon } from "lucide-react"
import { Button } from "@/components/ui/button"
export function ButtonSize() {
return (
Small
Default
Large
)
}--------------------------------
Create custom style extending shadcn/ui
Source: https://ui.shadcn.com/docs/registry/examples
Define a custom registry style that extends shadcn/ui by installing dependencies, adding registry dependencies (components and remote blocks), and configuring CSS variables for fonts and brand colors in light and dark modes. This configuration is applied when running npx shadcn init.
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "example-style",
"type": "registry:style",
"dependencies": ["@tabler/icons-react"],
"registryDependencies": [
"login-01",
"calendar",
"https://example.com/r/editor.json"
],
"cssVars": {
"theme": {
"font-sans": "Inter, sans-serif"
},
"light": {
"brand": "20 14.3% 4.1%"
},
"dark": {
"brand": "20 14.3% 4.1%"
}
}
}--------------------------------
Example Shadcn UI Registry Configuration (JSON)
Source: https://ui.shadcn.com/docs/registry/registry-index
This JSON configuration demonstrates a valid structure for a Shadcn UI registry. It includes a schema reference, the registry's name and homepage, and an array of items, each representing a component or example with its type, title, description, and associated file paths. This structure adheres to the specified registry schema requirements.
{
"$schema": "https://ui.shadcn.com/schema/registry.json",
"name": "acme",
"homepage": "https://acme.com",
"items": [
{
"name": "login-form",
"type": "registry:component",
"title": "Login Form",
"description": "A login form component.",
"files": [
{
"path": "registry/new-york/auth/login-form.tsx",
"type": "registry:component"
}
]
},
{
"name": "example-login-form",
"type": "registry:component",
"title": "Example Login Form",
"description": "An example showing how to use the login form component.",
"files": [
{
"path": "registry/new-york/examples/example-login-form.tsx",
"type": "registry:component"
}
]
}
]
}--------------------------------
Manually install Radix UI Alert Dialog dependency with npm
Source: https://ui.shadcn.com/docs/components/alert-dialog
This bash command is used for manual installation of the Shadcn UI Alert Dialog component, specifically for installing its underlying Radix UI primitive. It adds the @radix-ui/react-alert-dialog package as a dependency to your project. This step is required before copying the component source code.
npm install @radix-ui/react-alert-dialog--------------------------------
Component Diff Output Example
Source: https://ui.shadcn.com/docs/changelog
Example output showing differences in a component's code. The diff displays additions and removals, showing what has changed in the upstream repository.
const alertVariants = cva(
- "relative w-full rounded-lg border",
+ "relative w-full pl-12 rounded-lg border"
)--------------------------------
Install Button Dependencies via npm
Source: https://ui.shadcn.com/docs/components/button
Manual installation of required dependencies for the Button component. Install the @radix-ui/react-slot package which provides slot composition functionality.
npm install @radix-ui/react-slot--------------------------------
CLI Error: Missing Registry Environment Variables
Source: https://ui.shadcn.com/docs/changelog
This example demonstrates the CLI's helpful error for missing environment variables required by a registry. It explicitly lists the necessary variables, like REGISTRY_TOKEN, and instructs users to set them in .env or .env.local files.
Registry "@private" requires the following environment variables:
• REGISTRY_TOKEN
Set the required environment variables to your .env or .env.local file.--------------------------------
Install Multiple Resources from Different Namespaces
Source: https://ui.shadcn.com/docs/registry/namespace
Install multiple resources from different namespaced registries in a single command. Supports combining resources from UI components, libraries, and AI prompts across various registries.
npx shadcn@latest add @acme/header @lib/auth-utils @ai/chatbot-rules--------------------------------
Define Universal Registry Item for ESLint Configuration (shadcn/ui)
Source: https://ui.shadcn.com/docs/registry/examples
This JSON configuration defines a shadcn/ui registry item named 'my-eslint-config' for a custom ESLint configuration. It specifies a single file with an explicit target path (~/.eslintrc.json), enabling universal installation of the ESLint config file without framework dependencies.
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "my-eslint-config",
"type": "registry:item",
"files": [
{
"path": "/path/to/your/registry/default/custom-eslint.json",
"type": "registry:file",
"target": "~/.eslintrc.json",
"content": "..."
}
]
}--------------------------------
Configure Plugin with NPM Dependencies in shadcn UI
Source: https://ui.shadcn.com/docs/registry/examples
Shows how to include external npm packages as dependencies when using Tailwind CSS plugins. The dependencies array declares required packages, while the css object configures both the plugin and custom CSS layers. This pattern ensures all required packages are installed before the component is used.
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "typography-component",
"type": "registry:item",
"dependencies": ["@tailwindcss/typography"],
"css": {
"@plugin "@tailwindcss/typography"": {},
"@layer components": {
".prose": {
"max-width": "65ch"
}
}
}
}--------------------------------
Install Shadcn Accordion Component (bash)
Source: https://ui.shadcn.com/docs/components/accordion
This snippet provides two methods for installing the Shadcn UI Accordion component. Users can either add the component directly using the Shadcn CLI or manually install the underlying Radix UI dependency via npm. Both methods prepare the project for using the Accordion component by adding necessary files and packages.
npx shadcn@latest add accordionnpm install @radix-ui/react-accordion--------------------------------
Install Navigation Menu Dependencies - npm
Source: https://ui.shadcn.com/docs/components/navigation-menu
Manual installation of required Radix UI navigation menu dependency. Use this approach when manually setting up the component instead of using the CLI.
npm install @radix-ui/react-navigation-menu--------------------------------
Configure Secure Custom Registry with Authorization Headers (JSON)
Source: https://ui.shadcn.com/docs/registry/namespace
Provides an example of configuring a custom company registry in components.json, including a URL and authorization headers with an environment variable. This setup demonstrates best practices for securely connecting to private registries, requiring explicit authentication.
{
"@company": {
"url": "https://registry.company.com/v1/{name}.json",
"headers": {
"Authorization": "Bearer ${COMPANY_TOKEN}",
"X-Registry-Version": "1.0"
}
}
}--------------------------------
Create components.json Configuration File for shadcn/ui
Source: https://ui.shadcn.com/docs/installation/manual
This JSON configuration file sets up the shadcn/ui component library with New York style, TypeScript/TSX support, Tailwind CSS styling with CSS variables, and path aliases for easier imports. Place this file in the root of your project directory to enable component scaffolding and configuration.
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "",
"css": "src/styles/globals.css",
"baseColor": "neutral",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"iconLibrary": "lucide"
}--------------------------------
Install Button Component via CLI
Source: https://ui.shadcn.com/docs/components/button
Quick installation of the Button component using the shadcn CLI tool. Automatically adds the button component and its dependencies to your project.
npx shadcn@latest add button--------------------------------
Install Tabs Dependencies via NPM - Bash
Source: https://ui.shadcn.com/docs/components/tabs
Manual npm installation of the Radix UI Tabs dependency. Use this method when manually adding the tabs component instead of using the CLI installer.
npm install @radix-ui/react-tabs--------------------------------
Install Checkbox Dependencies - Bash
Source: https://ui.shadcn.com/docs/components/checkbox
Manual installation command for the Radix UI checkbox dependency. Required when manually setting up the checkbox component without using the CLI.
npm install @radix-ui/react-checkbox--------------------------------
Add Components with add Command
Source: https://ui.shadcn.com/docs/cli
The add command installs specific components and their dependencies into your project. It supports single or multiple component installation, file overwriting, and path customization.
npx shadcn@latest add [component]Usage: shadcn add [options] [components...]
add a component to your project
Arguments:
components name, url or local path to component
Options:
-y, --yes skip confirmation prompt. (default: false)
-o, --overwrite overwrite existing files. (default: false)
-c, --cwd the working directory. defaults to the current directory.
-a, --all add all available components (default: false)
-p, --path the path to add the component to.
-s, --silent mute output. (default: false)
--src-dir use the src directory when creating a new project. (default: false)
--no-src-dir do not use the src directory when creating a new project.
--css-variables use css variables for theming. (default: true)
--no-css-variables do not use css variables for theming.
-h, --help display help for command--------------------------------
Create new React project with Vite
Source: https://ui.shadcn.com/docs/installation/vite
Initializes a new React project using Vite. This command uses the latest version of Vite and allows selecting the 'React + TypeScript' template during the interactive setup process.
npm create vite@latest--------------------------------
Manually Install Radix UI Label npm Dependency
Source: https://ui.shadcn.com/docs/components/label
For manual installation of the shadcn/ui Label component, this npm command installs its core dependency, @radix-ui/react-label. This step is followed by copying the component's source code into your project and updating import paths.
npm install @radix-ui/react-label--------------------------------
Install Single Resource from Namespaced Registry
Source: https://ui.shadcn.com/docs/registry/namespace
Install a single resource from a configured namespace using the shadcn CLI. The syntax uses @namespace/resource-name format to specify which registry and resource to install.
npx shadcn@latest add @v0/dashboard--------------------------------
Add UI Components with add Command
Source: https://ui.shadcn.com/docs/changelog
Use the add command to install UI components from shadcn into your project. The CLI automatically resolves dependencies, formats components based on your components.json configuration, and installs them with correct import paths and styling methods.
npx shadcn@latest add--------------------------------
Install Button Group via CLI - Bash
Source: https://ui.shadcn.com/docs/components/button-group
Command-line installation script for the Button Group component using the shadcn package manager. This is the recommended installation method that automatically sets up the component with dependencies.
npx shadcn@latest add button-group--------------------------------
Radix UI Migration: Import Path Update Example
Source: https://ui.shadcn.com/docs/changelog
This diff example illustrates the effect of the radix migration command on component files. It shows how an import for AlertDialogPrimitive is changed from @radix-ui/react-dialog to the new radix-ui package.
- import * as AlertDialogPrimitive from "@radix-ui/react-dialog"
+ import { AlertDialog as AlertDialogPrimitive } from "radix-ui"--------------------------------
Initialize shadcn Project with init Command
Source: https://ui.shadcn.com/docs/cli
The init command sets up a new shadcn project by installing dependencies, adding the cn utility, and configuring CSS variables. It supports template selection, base color configuration, and directory structure options.
npx shadcn@latest initUsage: shadcn init [options] [components...]
initialize your project and install dependencies
Arguments:
components name, url or local path to component
Options:
-t, --template the template to use. (next, next-monorepo)
-b, --base-color the base color to use. (neutral, gray, zinc, stone, slate)
-y, --yes skip confirmation prompt. (default: true)
-f, --force force overwrite of existing configuration. (default: false)
-c, --cwd the working directory. defaults to the current directory.
-s, --silent mute output. (default: false)
--src-dir use the src directory when creating a new project. (default: false)
--no-src-dir do not use the src directory when creating a new project.
--css-variables use css variables for theming. (default: true)
--no-css-variables do not use css variables for theming.
--no-base-style do not install the base shadcn style
-h, --help display help for command--------------------------------
Install Dropdown Menu Dependencies
Source: https://ui.shadcn.com/docs/components/dropdown-menu
NPM installation command for the Radix UI dropdown menu primitive dependency. Required when manually adding the component without using the shadcn/ui CLI tool.
npm install @radix-ui/react-dropdown-menu--------------------------------
Install Toggle Component Dependencies Manually
Source: https://ui.shadcn.com/docs/components/toggle
Install the required Radix UI toggle dependency manually for projects that don't use the shadcn CLI. This is the first step when manually setting up the Toggle component.
npm install @radix-ui/react-toggle--------------------------------
Add Components with Shadcn CLI
Source: https://ui.shadcn.com/docs/changelog
This command demonstrates how to use the Shadcn CLI to add a specific component from a registry to your project. It automatically handles installation and updates the project's 'components.json' file.
npx shadcn add @ai-elements/prompt-input--------------------------------
Initialize MCP Server for shadcn Registries
Source: https://ui.shadcn.com/docs/changelog
Set up MCP (Model Context Protocol) server for all configured registries with zero configuration. Enables integration with MCP clients for AI-assisted component discovery and installation.
npx shadcn@latest mcp init--------------------------------
Install Chart Component via CLI
Source: https://ui.shadcn.com/docs/components/chart
Installs the chart.tsx component using shadcn's CLI tool. This command automatically sets up the chart component file in the project structure.
npx shadcn@latest add chart--------------------------------
Install Card Component via CLI - shadcn
Source: https://ui.shadcn.com/docs/components/card
Install the Card component using the shadcn CLI tool. This command downloads and integrates the Card component into your project's components directory.
npx shadcn@latest add cardshadcn.io Component Library
shadcn.io is a comprehensive React UI component library built on shadcn/ui principles, providing developers with production-ready, composable components for modern web applications. The library serves as a centralized resource for React developers who need high-quality UI components with TypeScript support, ranging from basic interactive elements to advanced AI-powered integrations. Unlike traditional component libraries that require package installations, shadcn.io components are designed to be copied directly into your project, giving you full control and customization capabilities.
The library encompasses four major categories: composable UI components (terminal, dock, credit cards, QR codes, color pickers), chart components built with Recharts, animation components with Tailwind CSS integration, and custom React hooks for state management and lifecycle operations. Each component follows best practices for accessibility, performance, and developer experience, with comprehensive TypeScript definitions and Next.js compatibility. The platform emphasizes flexibility and customization, allowing developers to modify components at the source level rather than being constrained by package APIs.
Core Components
Terminal Component
Interactive terminal emulator with typing animations and command execution simulation for developer-focused interfaces.
import { Terminal } from "@/components/ui/terminal"
export default function DemoTerminal() {
return (
npm install @repo/terminalInstalling dependencies...npm start
)
}Dock Component
macOS-style application dock with smooth magnification effects on hover, perfect for navigation menus.
import { Dock, DockIcon } from "@/components/ui/dock"
import { Home, Settings, User, Mail } from "lucide-react"
export default function AppDock() {
return (
)
}Credit Card Component
Interactive 3D credit card component with flip animations for payment forms and card displays.
import { CreditCard } from "@/components/ui/credit-card"
import { useState } from "react"
export default function PaymentForm() {
const [cardData, setCardData] = useState({
number: "4532 1234 5678 9010",
holder: "JOHN DOE",
expiry: "12/28",
cvv: "123"
})
return (
console.log("Card flipped:", flipped)}
/>
)
}Image Zoom Component
Zoomable image component with smooth modal transitions for image galleries and product displays.
import { ImageZoom } from "@/components/ui/image-zoom"
export default function ProductGallery() {
return (
)
}QR Code Component
Generate and display customizable QR codes with styling options for links, contact information, and authentication.
import { QRCode } from "@/components/ui/qr-code"
export default function ShareDialog() {
const shareUrl = "https://shadcn.io"
return (
Scan to visit shadcn.io
)
}Color Picker Component
Advanced color selection component supporting multiple color formats (HEX, RGB, HSL) with preview.
import { ColorPicker } from "@/components/ui/color-picker"
import { useState } from "react"
export default function ThemeCustomizer() {
const [color, setColor] = useState("#3b82f6")
return (
Selected: {color}
)
}Chart Components
Bar Chart Component
Clean bar chart component for data comparison and categorical analysis using Recharts.
import { BarChart } from "@/components/ui/bar-chart"
export default function SalesChart() {
const data = [
{ month: "Jan", sales: 4000, revenue: 2400 },
{ month: "Feb", sales: 3000, revenue: 1398 },
{ month: "Mar", sales: 2000, revenue: 9800 },
{ month: "Apr", sales: 2780, revenue: 3908 },
{ month: "May", sales: 1890, revenue: 4800 },
{ month: "Jun", sales: 2390, revenue: 3800 }
]
return (
`$${value.toLocaleString()}`}
yAxisWidth={60}
/>
)
}Line Chart Component
Smooth line chart for visualizing trends and time-series data with multiple data series support.
import { LineChart } from "@/components/ui/line-chart"
export default function MetricsChart() {
const data = [
{ date: "2024-01", users: 1200, sessions: 3400 },
{ date: "2024-02", users: 1800, sessions: 4200 },
{ date: "2024-03", users: 2400, sessions: 5800 },
{ date: "2024-04", users: 3100, sessions: 7200 },
{ date: "2024-05", users: 3800, sessions: 8900 }
]
return (
)
}Pie Chart Component
Donut chart component for displaying proportional data and percentage distributions.
import { PieChart } from "@/components/ui/pie-chart"
export default function MarketShareChart() {
const data = [
{ name: "Product A", value: 400, fill: "#3b82f6" },
{ name: "Product B", value: 300, fill: "#10b981" },
{ name: "Product C", value: 300, fill: "#f59e0b" },
{ name: "Product D", value: 200, fill: "#ef4444" }
]
return (
`${entry.name}: ${entry.value}`}
/>
)
}Area Chart Component
Stacked area chart for visualizing volume changes over time with multiple data series.
import { AreaChart } from "@/components/ui/area-chart"
export default function TrafficChart() {
const data = [
{ month: "Jan", mobile: 2000, desktop: 3000, tablet: 1000 },
{ month: "Feb", mobile: 2200, desktop: 3200, tablet: 1100 },
{ month: "Mar", mobile: 2800, desktop: 3800, tablet: 1300 },
{ month: "Apr", mobile: 3200, desktop: 4200, tablet: 1500 },
{ month: "May", mobile: 3800, desktop: 4800, tablet: 1800 }
]
return (
)
}Radar Chart Component
Multi-axis chart for comparing multiple variables across different categories simultaneously.
import { RadarChart } from "@/components/ui/radar-chart"
export default function SkillsChart() {
const data = [
{ skill: "JavaScript", score: 85, industry: 75 },
{ skill: "TypeScript", score: 80, industry: 70 },
{ skill: "React", score: 90, industry: 80 },
{ skill: "Node.js", score: 75, industry: 72 },
{ skill: "CSS", score: 88, industry: 78 }
]
return (
)
}Mixed Chart Component
Combined bar and line chart for displaying multiple data types with different visualization methods.
import { MixedChart } from "@/components/ui/mixed-chart"
export default function PerformanceChart() {
const data = [
{ month: "Jan", revenue: 4000, growth: 5.2 },
{ month: "Feb", revenue: 4200, growth: 5.0 },
{ month: "Mar", revenue: 4800, growth: 14.3 },
{ month: "Apr", revenue: 5200, growth: 8.3 },
{ month: "May", revenue: 5800, growth: 11.5 }
]
return (
)
}Animation Components
Magnetic Effect Component
Magnetic hover effect that smoothly follows cursor movement for interactive buttons and cards.
import { Magnetic } from "@/components/ui/magnetic"
export default function InteractiveButton() {
return (
Hover me
)
}Animated Cursor Component
Custom animated cursor with interactive effects and particle trails for immersive experiences.
import { AnimatedCursor } from "@/components/ui/animated-cursor"
export default function Layout({ children }) {
return (
<>
{children}
)
}Apple Hello Effect Component
Recreation of Apple's iconic "hello" animation with multi-language text transitions.
import { AppleHello } from "@/components/ui/apple-hello"
export default function WelcomeScreen() {
const greetings = [
{ text: "Hello", lang: "en" },
{ text: "Bonjour", lang: "fr" },
{ text: "こんにちは", lang: "ja" },
{ text: "Hola", lang: "es" },
{ text: "你好", lang: "zh" }
]
return (
)
}Liquid Button Component
Button with fluid liquid animation effect on hover for engaging call-to-action elements.
import { LiquidButton } from "@/components/ui/liquid-button"
export default function CTASection() {
return (
console.log("CTA clicked")}
>
Get Started
)
}Rolling Text Component
Text animation that creates a rolling effect with smooth character transitions.
import { RollingText } from "@/components/ui/rolling-text"
export default function AnimatedHeading() {
return (
)
}Shimmering Text Component
Text with animated shimmer effect for attention-grabbing headings and highlights.
import { ShimmeringText } from "@/components/ui/shimmering-text"
export default function Hero() {
return (
)
}React Hooks
useBoolean Hook
Enhanced boolean state management with toggle, enable, and disable methods for cleaner component logic.
import { useBoolean } from "@/hooks/use-boolean"
export default function TogglePanel() {
const modal = useBoolean(false)
const loading = useBoolean(false)
const handleSubmit = async () => {
loading.setTrue()
try {
await submitForm()
modal.setFalse()
} finally {
loading.setFalse()
}
}
return (
<>
Toggle Modal
{modal.value && (
Status: {loading.value ? "Saving..." : "Ready"}
Submit
)}
)
}useCounter Hook
Counter hook with increment, decrement, reset, and set functionality for numeric state management.
import { useCounter } from "@/hooks/use-counter"
export default function CartCounter() {
const quantity = useCounter(0, { min: 0, max: 99 })
return (
-
{quantity.value}
+
Reset
)
}useLocalStorage Hook
Persist state in browser localStorage with automatic serialization and deserialization.
import { useLocalStorage } from "@/hooks/use-local-storage"
export default function UserPreferences() {
const [theme, setTheme] = useLocalStorage("theme", "light")
const [settings, setSettings] = useLocalStorage("settings", {
notifications: true,
emailUpdates: false
})
return (
setTheme(e.target.value)}>
LightDark setSettings({
...settings,
notifications: e.target.checked
})}
/>
Enable Notifications
)
}useDebounceValue Hook
Debounce values to prevent excessive updates and API calls during rapid user input.
import { useDebounceValue } from "@/hooks/use-debounce-value"
import { useState, useEffect } from "react"
export default function SearchBox() {
const [search, setSearch] = useState("")
const debouncedSearch = useDebounceValue(search, 500)
const [results, setResults] = useState([])
const [apiCalls, setApiCalls] = useState(0)
useEffect(() => {
if (debouncedSearch) {
setApiCalls(prev => prev + 1)
fetch(`/api/search?q=${debouncedSearch}`)
.then(res => res.json())
.then(setResults)
}
}, [debouncedSearch])
return (
setSearch(e.target.value)}
placeholder="Search..."
/>
API calls: {apiCalls}
)
}useHover Hook
Track hover state on elements with customizable enter and leave delays for tooltip and preview functionality.
import { useHover } from "@/hooks/use-hover"
import { useRef } from "react"
export default function ImagePreview() {
const hoverRef = useRef(null)
const isHovering = useHover(hoverRef, {
enterDelay: 200,
leaveDelay: 100
})
return (

{isHovering && (

)}
)
}useCountdown Hook
Countdown timer with play, pause, reset controls and completion callbacks for time-limited features.
import { useCountdown } from "@/hooks/use-countdown"
export default function OTPTimer() {
const countdown = useCountdown({
initialSeconds: 60,
onComplete: () => alert("OTP expired! Request a new code.")
})
return (
{countdown.seconds}s
{!countdown.isRunning ? (
Start
) : (
Pause
)}
Reset
Status: {countdown.isComplete ? "Expired" : countdown.isRunning ? "Active" : "Paused"}
)
}Installation and Usage
CLI Installation
Install components directly into your project using the shadcn CLI for instant integration.
# Initialize shadcn in your project
npx shadcn@latest init
# Add individual components
npx shadcn@latest add terminal
npx shadcn@latest add dock
npx shadcn@latest add credit-card
# Add multiple components at once
npx shadcn@latest add bar-chart line-chart pie-chart
# Add hooks
npx shadcn@latest add use-boolean use-counter use-local-storageProject Configuration
Configure your project to work with shadcn.io components using TypeScript and Tailwind CSS.
// tailwind.config.ts
import type { Config } from "tailwindcss"
const config: Config = {
darkMode: ["class"],
content: [
"./pages/**/*.{ts,tsx}",
"./components/**/*.{ts,tsx}",
"./app/**/*.{ts,tsx}",
],
theme: {
extend: {
colors: {
border: "hsl(var(--border))",
input: "hsl(var(--input))",
ring: "hsl(var(--ring))",
background: "hsl(var(--background))",
foreground: "hsl(var(--foreground))",
primary: {
DEFAULT: "hsl(var(--primary))",
foreground: "hsl(var(--primary-foreground))",
},
},
},
},
plugins: [require("tailwindcss-animate")],
}
export default configSummary
The shadcn.io component library serves as a comprehensive toolkit for React developers building modern web applications with Next.js and TypeScript. The library's primary use cases include rapid prototyping of user interfaces, building data-rich dashboards with interactive charts, creating engaging user experiences with animations and effects, and implementing common UI patterns without writing boilerplate code. The copy-paste approach gives developers complete ownership of their components, allowing for deep customization while maintaining consistency with shadcn/ui design principles. Components are particularly well-suited for SaaS applications, admin panels, marketing websites, and e-commerce platforms that require professional, accessible UI elements.
Integration patterns center around composability and customization rather than rigid package dependencies. Developers can cherry-pick individual components using the CLI, modify them at the source level to match their design system, and combine them with existing shadcn/ui components for a cohesive interface. The library supports both light and dark themes through CSS variables, integrates seamlessly with Tailwind CSS utility classes, and follows React best practices for performance and accessibility. Custom hooks provide reusable logic patterns that complement the visual components, creating a complete ecosystem for building feature-rich applications. The TypeScript-first approach ensures type safety throughout the development process, while the Recharts integration for data visualization provides powerful charting capabilities without additional configuration overhead.
shadcn/ui - Setup and Configuration
What is shadcn/ui?
shadcn/ui is not a traditional component library or npm package. Instead:
- It's a collection of reusable components that you copy into your project
- Components are yours to customize — you own the code
- Built with Radix UI primitives for accessibility
- Styled with Tailwind CSS utilities
- Includes CLI tool for easy component installation
Installation
New Project
npx create-next-app@latest my-app --typescript --tailwind --eslint --app
cd my-app
npx shadcn@latest init
# Install essential components
npx shadcn@latest add button input form card dialog selectExisting Project
npm install tailwindcss-animate class-variance-authority clsx tailwind-merge lucide-react
npx shadcn@latest initInstalling Components
npx shadcn@latest add button # single component
npx shadcn@latest add button input form # multiple components
npx shadcn@latest add --all # all componentsRequired Dependencies
{
"dependencies": {
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.5",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"lucide-react": "^0.294.0",
"tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7"
}
}TSConfig Configuration
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "es6"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"baseUrl": ".",
"paths": {
"@/components/*": ["./src/components/*"],
"@/lib/*": ["./src/lib/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}Tailwind Configuration
// tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: ["class"],
content: [
'./pages/**/*.{ts,tsx}',
'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
'./src/**/*.{ts,tsx}',
],
prefix: "",
theme: {
container: {
center: true,
padding: "2rem",
screens: { "2xl": "1400px" },
},
extend: {
colors: {
border: "hsl(var(--border))",
input: "hsl(var(--input))",
ring: "hsl(var(--ring))",
background: "hsl(var(--background))",
foreground: "hsl(var(--foreground))",
primary: {
DEFAULT: "hsl(var(--primary))",
foreground: "hsl(var(--primary-foreground))",
},
secondary: {
DEFAULT: "hsl(var(--secondary))",
foreground: "hsl(var(--secondary-foreground))",
},
destructive: {
DEFAULT: "hsl(var(--destructive))",
foreground: "hsl(var(--destructive-foreground))",
},
muted: {
DEFAULT: "hsl(var(--muted))",
foreground: "hsl(var(--muted-foreground))",
},
accent: {
DEFAULT: "hsl(var(--accent))",
foreground: "hsl(var(--accent-foreground))",
},
},
borderRadius: {
lg: "var(--radius)",
md: "calc(var(--radius) - 2px)",
sm: "calc(var(--radius) - 4px)",
},
keyframes: {
"accordion-down": {
from: { height: "0" },
to: { height: "var(--radix-accordion-content-height)" },
},
"accordion-up": {
from: { height: "var(--radix-accordion-content-height)" },
to: { height: "0" },
},
},
animation: {
"accordion-down": "accordion-down 0.2s ease-out",
"accordion-up": "accordion-up 0.2s ease-out",
},
},
},
plugins: [require("tailwindcss-animate")],
}CSS Variables (globals.css)
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--card: 0 0% 100%;
--card-foreground: 222.2 84% 4.9%;
--popover: 0 0% 100%;
--popover-foreground: 222.2 84% 4.9%;
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;
--secondary: 210 40% 96.1%;
--secondary-foreground: 222.2 47.4% 11.2%;
--muted: 210 40% 96.1%;
--muted-foreground: 215.4 16.3% 46.9%;
--accent: 210 40% 96.1%;
--accent-foreground: 222.2 47.4% 11.2%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 210 40% 98%;
--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;
--ring: 222.2 84% 4.9%;
--radius: 0.5rem;
}
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
--card: 222.2 84% 4.9%;
--card-foreground: 210 40% 98%;
--popover: 222.2 84% 4.9%;
--popover-foreground: 210 40% 98%;
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 11.2%;
--secondary: 217.2 32.6% 17.5%;
--secondary-foreground: 210 40% 98%;
--muted: 217.2 32.6% 17.5%;
--muted-foreground: 215 20.2% 65.1%;
--accent: 217.2 32.6% 17.5%;
--accent-foreground: 210 40% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 210 40% 98%;
--border: 217.2 32.6% 17.5%;
--input: 217.2 32.6% 17.5%;
--ring: 212.7 26.8% 83.9%;
}
}
@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}shadcn/ui - UI Components Reference
Button
npx shadcn@latest add buttonimport { Button } from "@/components/ui/button"
import { Loader2 } from "lucide-react"
// Variants: default | destructive | outline | secondary | ghost | link
// Sizes: default | sm | lg | icon
<Button variant="default">Default</Button>
<Button variant="destructive">Delete</Button>
<Button variant="outline">Outline</Button>
<Button size="sm">Small</Button>
<Button size="icon"><Icon className="h-4 w-4" /></Button>
// Loading state
<Button disabled>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Please wait
</Button>Input & Label
npx shadcn@latest add input labelimport { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
// Basic input
<Input type="email" placeholder="Email" />
// Input with label
<div className="grid w-full max-w-sm items-center gap-1.5">
<Label htmlFor="email">Email</Label>
<Input type="email" id="email" placeholder="Email" />
</div>
// Input with button
<div className="flex w-full max-w-sm items-center gap-2">
<Input type="email" placeholder="Email" />
<Button type="submit" variant="outline">Subscribe</Button>
</div>Card
npx shadcn@latest add cardimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
<Card>
<CardHeader>
<CardTitle>Card Title</CardTitle>
<CardDescription>Card Description</CardDescription>
</CardHeader>
<CardContent>
<p>Card Content</p>
</CardContent>
<CardFooter className="flex justify-between">
<Button variant="outline">Cancel</Button>
<Button>Deploy</Button>
</CardFooter>
</Card>Dialog (Modal)
npx shadcn@latest add dialogimport {
Dialog, DialogContent, DialogDescription, DialogFooter,
DialogHeader, DialogTitle, DialogTrigger,
} from "@/components/ui/dialog"
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Open Dialog</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>Make changes to your profile here.</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="name" className="text-right">Name</Label>
<Input id="name" className="col-span-3" />
</div>
</div>
<DialogFooter>
<Button type="submit">Save changes</Button>
</DialogFooter>
</DialogContent>
</Dialog>Sheet (Slide-over)
npx shadcn@latest add sheetimport {
Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger,
} from "@/components/ui/sheet"
// sides: top | right | bottom | left (default: right)
<Sheet>
<SheetTrigger asChild>
<Button variant="outline">Open Sheet</Button>
</SheetTrigger>
<SheetContent side="right">
<SheetHeader>
<SheetTitle>Settings</SheetTitle>
<SheetDescription>Configure your application settings.</SheetDescription>
</SheetHeader>
{/* Sheet content */}
</SheetContent>
</Sheet>Select (Dropdown)
npx shadcn@latest add selectimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
<Select>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select a fruit" />
</SelectTrigger>
<SelectContent>
<SelectItem value="apple">Apple</SelectItem>
<SelectItem value="banana">Banana</SelectItem>
<SelectItem value="orange">Orange</SelectItem>
</SelectContent>
</Select>Toast Notifications
npx shadcn@latest add toastAdd <Toaster /> to root layout:
// app/layout.tsx
import { Toaster } from "@/components/ui/toaster"
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
<Toaster />
</body>
</html>
)
}Using toast:
import { useToast } from "@/components/ui/use-toast"
export function ToastDemo() {
const { toast } = useToast()
return (
<Button onClick={() => toast({ title: "Success", description: "Changes saved." })}>
Show Toast
</Button>
)
}
// Variants
toast({ title: "Success", description: "Changes have been saved." })
toast({ variant: "destructive", title: "Error", description: "Something went wrong." })
toast({ title: "Undo?", action: <ToastAction altText="Undo">Undo</ToastAction> })Table
npx shadcn@latest add tableimport {
Table, TableBody, TableCaption, TableCell,
TableHead, TableHeader, TableRow,
} from "@/components/ui/table"
const invoices = [
{ invoice: "INV001", status: "Paid", method: "Credit Card", amount: "$250.00" },
{ invoice: "INV002", status: "Pending", method: "PayPal", amount: "$150.00" },
]
<Table>
<TableCaption>A list of your recent invoices.</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Invoice</TableHead>
<TableHead>Status</TableHead>
<TableHead>Method</TableHead>
<TableHead className="text-right">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{invoices.map((invoice) => (
<TableRow key={invoice.invoice}>
<TableCell className="font-medium">{invoice.invoice}</TableCell>
<TableCell>{invoice.status}</TableCell>
<TableCell>{invoice.method}</TableCell>
<TableCell className="text-right">{invoice.amount}</TableCell>
</TableRow>
))}
</TableBody>
</Table>Menubar & Navigation
npx shadcn@latest add menubarimport {
Menubar, MenubarContent, MenubarItem, MenubarMenu,
MenubarSeparator, MenubarShortcut, MenubarSub,
MenubarSubContent, MenubarSubTrigger, MenubarTrigger,
} from "@/components/ui/menubar"
<Menubar>
<MenubarMenu>
<MenubarTrigger>File</MenubarTrigger>
<MenubarContent>
<MenubarItem>New Tab <MenubarShortcut>⌘T</MenubarShortcut></MenubarItem>
<MenubarItem>New Window <MenubarShortcut>⌘N</MenubarShortcut></MenubarItem>
<MenubarSeparator />
<MenubarItem>Print</MenubarItem>
</MenubarContent>
</MenubarMenu>
<MenubarMenu>
<MenubarTrigger>Edit</MenubarTrigger>
<MenubarContent>
<MenubarItem>Undo <MenubarShortcut>⌘Z</MenubarShortcut></MenubarItem>
<MenubarSeparator />
<MenubarSub>
<MenubarSubTrigger>Find</MenubarSubTrigger>
<MenubarSubContent>
<MenubarItem>Search the web</MenubarItem>
<MenubarItem>Find...</MenubarItem>
</MenubarSubContent>
</MenubarSub>
</MenubarContent>
</MenubarMenu>
</Menubar>Related skills
Forks & variants (1)
Shadcn Ui has 1 known copy in the catalog totaling 36 installs. They canonicalize to this original listing.
- giuseppe-trisciuoglio - 36 installs
FAQ
Does shadcn-ui copy components into the project?
shadcn-ui follows the shadcn/ui model where components are copied into your repository on Radix UI and Tailwind CSS, so developers own and customize every component file.
What form stack does shadcn-ui use?
shadcn-ui implements complex form layouts with React Hook Form for state management and Zod schemas for validation alongside shadcn/ui input and layout components.
Is Shadcn Ui safe to install?
skills.sh reports 2 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.