Get Started
Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Card
- Checkbox
- Collapsible
- Combobox
- Context Menu
- Date Picker (Lite)
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP (Lite)
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
import { Button } from "@/components/ui/button"
export function ToastDemo() {
return (
<Button
variant="outline"
data-toast-trigger=""
data-toast-title="Event created"
data-toast-description="Sunday, December 3 at 9:00 AM"
>
Show Toast
</Button>
)
}Installation
pnpm dlx shadcnui-hono-jsx@latest add toastnpx shadcnui-hono-jsx@latest add toastyarn dlx shadcnui-hono-jsx@latest add toastbunx shadcnui-hono-jsx@latest add toastThis component uses a small client script. add installs it into public/shadcn/; serve that directory at /shadcn/ and load the script on pages that use the component (see Client Scripts):
<script type="module" src="/shadcn/toast.js"></script>Usage
import { toast } from "@/components/ui/toast"toast.add({
title: "Event created",
description: "Sunday, December 3 at 9:00 AM",
})Types
Set the type option to render a status icon. The built-in renderer recognizes
success, info, warning, error, and loading.
import { Button } from "@/components/ui/button"
export function ToastTypes() {
return (
<div class="flex flex-wrap gap-2">
<Button
variant="outline"
data-toast-trigger=""
data-toast-description="Event has been created."
>
Default
</Button>
<Button
variant="outline"
data-toast-trigger=""
data-toast-type="success"
data-toast-description="Event has been created."
>
Success
</Button>
<Button
variant="outline"
data-toast-trigger=""
data-toast-type="info"
data-toast-description="Arrive 10 minutes before the event."
>
Info
</Button>
<Button
variant="outline"
data-toast-trigger=""
data-toast-type="warning"
data-toast-description="The event cannot start before 8:00 AM."
>
Warning
</Button>
<Button
variant="outline"
data-toast-trigger=""
data-toast-type="error"
data-toast-description="The event could not be created."
>
Error
</Button>
</div>
)
}Action
Pass button props with actionProps to render an action.
const id = toast.add({
title: "Event created",
actionProps: {
children: "Undo",
onClick() {
toast.close(id)
},
},
})Promise
Use toast.promise to update one toast as an asynchronous task moves through
loading, success, and error states.
import { Button } from "@/components/ui/button"
export function ToastPromise() {
return (
<Button
variant="outline"
data-toast-trigger=""
data-toast-type="success"
data-toast-description="Event created."
>
Create Event
</Button>
)
}Notes
- Toasts are added in the browser with
toastfrom the client script (import { toast } from "/shadcn/toast.js", thentoast.add({ title, description, type, actionProps })), or declaratively withdata-toast-triggerbuttons (data-toast-title,data-toast-description,data-toast-type). The script copies the toast markup from templates that<Toaster>renders, so edit the components as usual. - On the server, pass toasts to
<Toaster toasts={[{ title: "Saved" }]} />(for example flash messages after a form post) or use a per-responsecreateToastManager()with<Toaster toastManager={manager}>; they show without JavaScript, and the script times them out. The exportedtoastis shared by every request on the server, so itsadd()throws there. ActiononClickand other function props, anduseToastManager()state updates, work only through/shadcn/toast.js. - Accepts
classinstead ofclassName. - Upstream documentation: shadcn/ui Toast. See also Differences from shadcn/ui.
API Reference
See the Base UI Toast documentation for details about manager options, stacking, swipe dismissal, and the primitive API.