Components

Toast

The shadcn/ui Sonner Toaster restyled for dark interfaces, with tinted status icons and on-brand rich colors — plus two animated React toast notification blocks built with Motion: a custom toast whose icon morphs from loading to success or error with a progress line and promise helpers, and an undo toast for optimistic deletes.

  • Sonner
  • Drop-in shadcn API
  • Promise toasts
  • Motion blocks

Installation

$ npx shadcn@latest add https://duskui.com/r/toast.json

Replaces components/ui/sonner.tsx; the Toaster export and all Sonner props still work, and your toastOptions.classNames are merged with ours. It defaults to the dark theme and no longer needs next-themes. Mount <Toaster /> once (e.g. in your root layout), then call toast() from sonner anywhere.

Usage

app/layout.tsx
import { Toaster } from "@/components/ui/sonner"

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en" className="dark">
      <body>
        {children}
        <Toaster position="bottom-right" />
      </body>
    </html>
  )
}

// anywhere in a client component
import { toast } from "sonner"

toast.success("Changes saved", { description: "Your team can see them now." })

Examples

Types

toast(), toast.success, .info, .warning and .error on the popover surface with a layered shadow, tinted icons and a mint action button. Hover the stack to expand it and pause the timers; swipe to dismiss.

Promise

Sonner's toast.promise shows a spinner until the promise settles, then the success or error message. Pass richColors to the Toaster for tinted success and error toasts in the DuskUI palette.

Blocks

Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.

Animated Toast

A custom toast rendered with toast.custom. Update it by id and the icon changes: the spinner fades out and the check or cross draws itself in. A thin line shows the time left, driven by the same motion value as the timer, so they never drift; it pauses on hover, focus and hidden tabs. animatedToast.promise keeps the spinner up for at least minLoading ms so fast requests don't flash, and when you pass a function it adds a Retry button that re-runs it in the same toast. Try “Sync”.

$ npx shadcn@latest add https://duskui.com/r/animated-toast.json
PropTypeDefaultDescription
animatedToast(title, options?)=> id—Neutral toast. Also .success, .error, .info, .warning and .loading.
animatedToast.promise(task, messages, options?)=> { id, unwrap }—task is a promise or a function returning one (enables Retry). Messages are text or { title, description }, or functions of the result / error.
options.idstring | number—Reuse an id to update a toast in place.
options.descriptionReactNode—Second line.
options.durationnumber5000Lifetime in ms once settled. Infinity keeps it open.
options.action{ label, onClick }—A button under the text. Call event.preventDefault() to keep the toast open.
options.dismissiblebooleantrueShow the close button and allow swiping.
options.onAutoClose / onDismiss() => void—Timer ran out / the user closed it.
minLoadingnumber600Promise only: minimum spinner time in ms.
retryLabelReactNode | false"Retry"Promise only: label of the retry button; false hides it.
AnimatedToast / ToastSurface / ToastStatusIcon / useToastCountdownexports—The building blocks, for your own custom toasts.

Undo Toast

The optimistic-delete pattern: remove the item right away, call undoToast(), and only make it permanent in onCommit. A ring drains around the seconds left; Undo (or ⌘Z / Ctrl+Z) calls onUndo and the toast turns into a “Restored” confirmation. onUndo and onCommit are guaranteed to run at most once, and never both. Archive a few emails, then undo one.

  • Ada Kim

    Motion specs for the onboarding flow

  • Leo Park

    Re: Q3 roadmap review

  • Vercel

    Your deployment is ready

$ npx shadcn@latest add https://duskui.com/r/undo-toast.json
PropTypeDefaultDescription
titleReactNode—What happened, e.g. "Email archived". Required.
descriptionReactNode—Second line, e.g. the item's name.
onUndo() => void—Restore the item. Required.
onCommit() => void—Runs when time runs out or the toast is closed without undoing.
durationnumber6000How long the user has to undo, in ms.
undoLabelReactNode"Undo"Button label.
undoneTitleReactNode"Restored"Title shown after undoing.
shortcutbooleantrueUndo with ⌘Z / Ctrl+Z (ignored in text fields).
id / position / classNameSonner options—Passed through to toast.custom.

API Reference

Toaster accepts every Sonner ToasterProps. Fire toasts with the toast function from sonner.

PropTypeDefaultDescription
theme"light" | "dark" | "system""dark"Sonner theme. DuskUI is styled for dark.
position"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""bottom-right"Where toasts stack.
richColorsbooleanfalseTinted success, info, warning and error toasts in the DuskUI palette.
toastOptionsToastOptions—Defaults for every toast; classNames are merged with the DuskUI ones.
iconsToastIcons—Override any of the status, loading or close icons.
expand / visibleToasts / duration / closeButtonSonner props—Stacking, count, default lifetime and close button.

Accessibility

  • Sonner renders toasts in a labelled, polite live region, so new toasts are announced without stealing focus. Alt+T moves focus to the toasts.
  • Timers pause while the stack is hovered or focused and while the tab is hidden, giving everyone time to read and act. The blocks follow the same rules with their own timers.
  • Close, Retry and Undo are real buttons with accessible labels, reachable by keyboard. Undo Toast also supports ⌘Z / Ctrl+Z.
  • Don't put the only path to something important in a toast; it disappears. Use an Alert or Alert Dialog for that.
  • Sonner turns off its own animations under prefers-reduced-motion; the blocks skip scale and rotate and keep simple fades.