shadcn.io is not affiliated with official shadcn/ui
Installation
bunx --bun shadcn@latest add https://kit.dev/r/aria/toast.jsonnpx shadcn@latest add https://kit.dev/r/aria/toast.jsonpnpm dlx shadcn@latest add https://kit.dev/r/aria/toast.jsonyarn shadcn@latest add https://kit.dev/r/aria/toast.jsonInstall the following dependencies:
bun add sonner lucide-reactnpm install sonner lucide-reactpnpm add sonner lucide-reactyarn add sonner lucide-reactAdd the following to your globals.css.
:root {
--destructive-foreground: var(--color-red-700);
--info: var(--color-blue-500);
--info-foreground: var(--color-blue-700);
--success: var(--color-emerald-500);
--success-foreground: var(--color-emerald-700);
--warning: var(--color-amber-500);
--warning-foreground: var(--color-amber-700);
}
.dark {
--destructive-foreground: var(--color-red-400);
--info: var(--color-blue-500);
--info-foreground: var(--color-blue-400);
--success: var(--color-emerald-500);
--success-foreground: var(--color-emerald-400);
--warning: var(--color-amber-500);
--warning-foreground: var(--color-amber-400);
}Copy and paste the following code into your project.
"use client";
import {
CircleCheckIcon,
InfoIcon,
Loader2Icon,
OctagonXIcon,
TriangleAlertIcon,
} from "lucide-react";
import type React from "react";
import {
Toaster as Sonner,
toast as sonnerToast,
type ToasterProps,
} from "sonner";
import { cn } from "@/lib/utils";
export const toast = sonnerToast;Update the import paths to match your project setup.
Anatomy
ToastItem
├── ToastGroup
├── ToastTitle
├── ToastDescription
├── ToastActionTrigger
└── ToastCloseTriggerUsage
import { Button } from "@/components/ui/button";
import { createToaster, Toaster } from "@/components/ui/toast";const toast = createToaster({
overlap: true,
placement: "bottom-end",
});
const ToastDemo = () => {
const handleShowToast = () => {
const id = toast.create({
action: {
label: "Undo",
onClick() {
toast.dismiss(id);
},
},
description: "Sunday, December 3 at 9:00 AM",
title: "Event created",
});
};
return (
<>
<Toaster toaster={toast} />
<Button onClick={handleShowToast} variant="outline">
Show Toast
</Button>
</>
);
};Accessibility
| Key | Description |
|---|---|
Enter | Activate the focused control. |
Space | Activate the focused control. |
Demos
Types
Set the type option to render a status icon.
Promise
Use toast.promise for loading, success, and error states.
API Reference
toast
createToaster
Toaster
PropType
AttributeType
CSS variableType
--borderstring--popoverstring--popover-foregroundstring--radiusstring