Search every page in the navigation.
A succinct message that is displayed temporarily.
"use client"
import { Button } from "@/components/ui/button"
import { toast } from "@/components/ui/toast"
function ToastDemo() {
function showToast() {
const id = toast.add({
title: "Event created",
description: "Sunday, December 3 at 9:00 AM",
actionProps: {
children: "Undo",
onClick() {
toast.close(id)
},
},
})
}
return (
<Button variant="outline" onClick={showToast}>
Show Toast
</Button>
)
}
export default ToastDemonpx shadcn@latest add @ziiz/toastimport { toast } from "@/components/ui/toast"toast.add({
title: "Event created",
description: "Sunday, December 3 at 9:00 AM",
})Set the type option to render a status icon. The built-in renderer recognizes
success, info, warning, error, and loading.
"use client"
import { Button } from "@/components/ui/button"
import { toast } from "@/components/ui/toast"
function ToastTypes() {
return (
<div className="flex flex-wrap gap-2">
<Button
variant="outline"
onClick={() => toast.add({ description: "Event has been created." })}
>
Default
</Button>
<Button
variant="outline"
onClick={() =>
toast.add({
type: "success",
description: "Event has been created.",
})
}
>
Success
</Button>
<Button
variant="outline"
onClick={() =>
toast.add({
type: "info",
description: "Arrive 10 minutes before the event.",
})
}
>
Info
</Button>
<Button
variant="outline"
onClick={() =>
toast.add({
type: "warning",
description: "The event cannot start before 8:00 AM.",
})
}
>
Warning
</Button>
<Button
variant="outline"
onClick={() =>
toast.add({
type: "error",
description: "The event could not be created.",
priority: "high",
})
}
>
Error
</Button>
</div>
)
}
export default ToastTypesPass button props with actionProps to render an action.
const id = toast.add({
title: "Event created",
actionProps: {
children: "Undo",
onClick() {
toast.close(id)
},
},
})Use toast.promise to update one toast as an asynchronous task moves through
loading, success, and error states.
"use client"
import { Button } from "@/components/ui/button"
import { toast } from "@/components/ui/toast"
function ToastPromise() {
function showToast() {
toast.promise(
new Promise<{ name: string }>((resolve) => {
window.setTimeout(() => resolve({ name: "Event" }), 2000)
}),
{
loading: "Creating eventโฆ",
success: (data) => `${data.name} created.`,
error: "Could not create event.",
}
)
}
return (
<Button variant="outline" onClick={showToast}>
Create Event
</Button>
)
}
export default ToastPromiseSee the Base UI Toast documentation for details about manager options, stacking, swipe dismissal, and the primitive API.