Toast
Advancement toasts that slide in with a fanfare.
Install and use
The first command adds the component and the Mine theme, the second adds this example. Render <Mine> once near your root for the skin, sounds and narrator.
"use client"
import * as React from "react"
import { XIcon } from "lucide-react"
import { Button } from "@/components/ui/button"
import {
Toast,
ToastAction,
ToastClose,
ToastDescription,
ToastRegion,
ToastTitle,
createToaster,
} from "@/components/ui/toast"
import { useLog } from "@/demos/log"
function Example() {
const log = useLog()
const [toast] = React.useState(() => createToaster())
React.useEffect(
() => () => {
toast.dismiss()
},
[toast]
)
return (
<>
<Button
onClick={() =>
toast("Event created", {
description: "Friday, June 12 at 10:00 AM",
action: { label: "Undo", onAction: () => log("Event removed") },
})
}
>
Create Event
</Button>
<ToastRegion toaster={toast}>
{() => (
<Toast>
<div data-slot="stack">
<ToastTitle />
<ToastDescription />
</div>
<ToastAction data-variant="solid" />
<ToastClose aria-label="Close">
<XIcon aria-hidden="true" />
</ToastClose>
</Toast>
)}
</ToastRegion>
</>
)
}
export { Example }