Skip to content

Adding Components

What is shadcn/ui?

shadcn/ui gives you ready components:

  • Buttons
  • Dialogs (popups)
  • Forms
  • Cards
  • Tables
  • And more...

Important: Components go into YOUR code. Not node_modules. You can change them.

Add a Component

bash
npx shadcn add button
bash
bunx shadcn add button
bash
pnpm dlx shadcn add button
bash
yarn dlx shadcn add button

This creates src/components/ui/button.tsx.

Add Many Components

bash
npx shadcn add dialog card form input
bash
bunx shadcn add dialog card form input
bash
pnpm dlx shadcn add dialog card form input
bash
yarn dlx shadcn add dialog card form input
ComponentWhat It Does
buttonClickable button
dialogPopup window
cardBox with content
inputText field
formForm with validation
tableData table
selectDropdown menu
tabsTab navigation
sonnerNotifications

See all: ui.shadcn.com/docs/components

How to Use

tsx
import { Button } from "@/components/ui/button"

export default function MyPage() {
  return (
    <Button onClick={() => alert("Hello!")}>
      Click Me
    </Button>
  )
}

Dialog Example

tsx
import { Button } from "@/components/ui/button"
import {
  Dialog,
  DialogContent,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"

export default function MyPage() {
  return (
    <Dialog>
      <DialogTrigger asChild>
        <Button>Open Popup</Button>
      </DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Hello!</DialogTitle>
        </DialogHeader>
        <p>This is a popup.</p>
      </DialogContent>
    </Dialog>
  )
}

Change Components

Components are in src/components/ui/. Open and edit them.

Example - add green button:

tsx
// src/components/ui/button.tsx

const buttonVariants = cva(
  "...",
  {
    variants: {
      variant: {
        default: "bg-primary text-white",
        // Add your own:
        success: "bg-green-500 text-white hover:bg-green-600",
      }
    }
  }
)

Now use it:

tsx
<Button variant="success">Save</Button>

Change Colors

Edit src/index.css:

css
:root {
  --primary: oklch(0.5 0.2 260);  /* Change this color */
}

Want a theme generator? Go to ui.shadcn.com/themes

Released under the MIT License.