shadcn.io is not affiliated with official shadcn/ui
Installation
bunx --bun shadcn@latest add https://kit.dev/r/base/toast.jsonnpx shadcn@latest add https://kit.dev/r/base/toast.jsonpnpm dlx shadcn@latest add https://kit.dev/r/base/toast.jsonyarn shadcn@latest add https://kit.dev/r/base/toast.jsonThis component depends on Button and Spinner. Install them first if you haven't already.
Install the following dependencies:
bun add @base-ui/react lucide-reactnpm install @base-ui/react lucide-reactpnpm add @base-ui/react lucide-reactyarn add @base-ui/react 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 { Toast as ToastPrimitive } from "@base-ui/react/toast";
import {
CircleCheckIcon,
InfoIcon,
OctagonXIcon,
TriangleAlertIcon,
XIcon,
} from "lucide-react";
import type React from "react";
import { cn } from "@/lib/utils";
import { Button } from "@/registry/base/components/button";
import { Spinner } from "@/registry/base/components/spinner";
const { createToastManager: createToaster, useToastManager } = ToastPrimitive;
export { createToaster, useToastManager };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
div
PropType
AttributeType
CSS variableType
--gapstring--heightstring--offset-ystring--peekstring--scalestring--shrinkstring--toast-heightstring--toast-indexstring--toast-offset-ystring--toast-swipe-movement-xstring--toast-swipe-movement-ystringToastItem
div
PropType
className?stringAttributeType
ToastTitle
h2
PropType
AttributeType
ToastDescription
p
PropType
AttributeType
toast
PropType
AttributeType
ToastPortal
div
PropType
AttributeType
ToastViewport
div
PropType
AttributeType
ToastContent
div
PropType
AttributeType
ToastAction
button
PropType
AttributeType
ToastClose
button
PropType
AttributeType
ToastActionTrigger
PropType
AttributeType
ToastCloseTrigger
PropType
AttributeType
ToastIcon
PropType
className?stringAttributeType
Toaster
PropType
AttributeType
ToastProvider
PropType
children?React.ReactNodeAttributeType