Captain UI

Toast

A deck that fans out when you hover it. Swipe a toast back the way it came, undo from it, or watch a promise turn from loading into done.

npx shadcn@latest add https://captain-ui.vercel.app/r/toast.json

Usage

import { Toaster, toast } from "@/components/ui/toast"

<Toaster />

toast("Archived run 1187", { action: { label: "Undo", onClick: restore } })
toast.promise(merge(482), { loading: "Merging #482", success: "Merged #482 into main", error: "Merge failed" })

Props

PropTypeDefaultWhat it does
toast(title, options)functionShows a toast and returns its id. Options: description, action, duration, type, id.
toast.success / toast.errorfunctionSame, with a drawn check or a warning glyph.
toast.promise(p, messages)functionOne toast that morphs from loading to success or error in place.
toast.dismiss(id?)functionDismiss one, or all with no id.
Toaster position"bottom-right" | "bottom-center" | … | "top-left""bottom-right"Toasts enter from that edge and swipe back toward it.
Toaster durationnumber4000Time on screen in ms. Paused while hovered, focused or the tab is hidden.
Toaster visiblenumber3How many show in the deck.
Toaster inlinebooleanPosition inside the nearest positioned parent instead of the viewport.

Keyboard

Alt+T
Focus the newest toast
Tab
Move through toasts and their actions
Esc
Dismiss the focused toast

Accessibility

  • A labelled region with a polite live list; errors use role=alert.
  • Timers pause while the deck is hovered or focused, so nobody has to race a toast.
  • Swiping is optional: Esc dismisses and every action is a real button.