A toast notification with animated status icons, built on Sonner.
Toasts stack in a corner and fan out when you hover them. Each status pops in with its own icon, and a promise toast morphs from a spinner into a check or a cross in place. Swipe one away, press its action, or hover it to show the close button. Honors prefers-reduced-motion.
Options you can pass to customize this component.
toast(title, options)(title: ReactNode, options?: ToastOptions) => string | numberShows a plain toast and returns its id. toast.success, toast.error, toast.warning, toast.info and toast.loading take the same arguments and add a status icon.
toast.promise(task: Promise<T> | (() => Promise<T>), messages, options?) => Promise<T>Shows messages.loading until the task settles, then swaps to messages.success or messages.error in the same toast. Either can be a function of the result.
descriptionReactNodeMuted second line under the title.
action{ label: string; onClick: () => void }A pill button on the right. Clicking it runs onClick and closes the toast.
durationnumberMilliseconds before the toast closes. Loading toasts stay until updated or dismissed.
idstringnumberReuse an id to update a toast that is already showing instead of adding a new one.
dismissiblebooleanShows the close button and allows swiping it away.
position"top-left""top-center""top-right""bottom-left""bottom-center""bottom-right"On Toaster, where the stack sits. Toaster takes the rest of Sonner's Toaster props too, like expand, visibleToasts, offset, duration and hotkey. Dark mode follows your .dark class.
gapnumberOn Toaster, the space in pixels between expanded toasts.
npx shadcn@latest add swamimalode07/rare-ui/toast"use client"import { Toaster, toast } from "@/components/ui/toast"const save = () => fetch("/api/save", { method: "POST" })// mount Toaster once, in your root layoutexport function Demo() {return (<><buttononClick={() =>toast.promise(save(), {loading: "Saving",success: "Saved",error: "Couldn't save",})}>Save</button><Toaster /></>)}
Click the code icon in the top-right corner to view the source code.
Most components here are recreations of great work from around the web. I don't claim to be the original creator - this is my attempt to reverse-engineer, replicate, and often add a few extra features. I've tried to credit everyone; if I missed someone, let me know.
1