StacklyUI

ToastNew

Imperative, Sonner-style toasts — call toast() from anywhere, no context wiring. A collapsed peek stack expands on hover, toasts pause on hover and swipe to dismiss, and toast.promise wires loading → success/error automatically.

01

Preview & playground

Edit the code — the preview updates live. Try changing props, text, or classes.

playground.tsx
function Demo() {
  return (
    <div className="flex flex-wrap gap-2">
      <Toaster richColors closeButton />
      <Button size="sm" onClick={() => toast("Event created", { description: "Sunday, Dec 3 at 9:00 AM" })}>
        Show toast
      </Button>
      <Button size="sm" variant="outline" onClick={() => toast.success("Changes saved")}>Success</Button>
      <Button size="sm" variant="outline" onClick={() => toast.error("Something went wrong")}>Error</Button>
      <Button size="sm" variant="outline" onClick={() => toast.warning("Low on storage")}>Warning</Button>
      <Button size="sm" variant="outline" onClick={() => toast.info("A new version is available")}>Info</Button>
    </div>
  )
}
render(<Demo />)
02

Examples

Common variations — edit any of them live.

Promise toasts

One call shows a loading toast, then swaps to success or error when the promise settles.

playground.tsx
function Demo() {
  const run = () => {
    const upload = new Promise((resolve, reject) =>
      setTimeout(() => (Math.random() > 0.3 ? resolve({ name: "report.pdf" }) : reject()), 1800),
    )
    toast.promise(upload, {
      loading: "Uploading…",
      success: (data) => data.name + " uploaded",
      error: "Upload failed — try again",
    })
  }
  return (
    <div>
      <Toaster />
      <Button size="sm" onClick={run}>Upload file</Button>
    </div>
  )
}
render(<Demo />)

Action & undo

Attach a primary action — perfect for an undoable, destructive step.

playground.tsx
function Demo() {
  const remove = () =>
    toast.warning("File moved to trash", {
      description: "You can still get it back.",
      action: { label: "Undo", onClick: () => toast.success("File restored") },
    })
  return (
    <div>
      <Toaster />
      <Button size="sm" variant="outline" onClick={remove}>Delete with undo</Button>
    </div>
  )
}
render(<Demo />)

Update in place

Reuse an id to morph one toast through several states instead of stacking new ones.

playground.tsx
function Demo() {
  const run = () => {
    const id = toast.loading("Connecting…")
    setTimeout(() => toast.loading("Authenticating…", { id }), 900)
    setTimeout(() => toast.success("Connected", { id, duration: 3000 }), 1800)
  }
  return (
    <div>
      <Toaster />
      <Button size="sm" onClick={run}>Connect</Button>
    </div>
  )
}
render(<Demo />)
03

Installation

Copy the source into your project with the registry CLI:

$pnpm dlx shadcn@latest add @stacklyui/toast

Or install the package and import it:

$pnpm add @stacklyui/ui motion
04

Usage

Drop a single <Toaster /> at your app root, then call the imperative API from anywhere — no provider, no context. The store is a singleton read through useSyncExternalStore, so toast(), toast.success/error/warning/info/loading, toast.custom (arbitrary JSX), and toast.promise (loading that resolves to success or error) all work from event handlers, effects, or plain functions. Pass an id to update a toast in place. Each toast takes a description, an action and a cancel button, and a duration (Infinity to persist). The stack shows as a collapsed peek that expands on hover, auto-dismiss pauses while hovered, and toasts can be swiped away. Configure the <Toaster /> with position, richColors, closeButton, expand, visibleToasts, gap, offset, and width.