Xzero UI
Pro library

Toast stack

Stack short results at the edge until you reach for them.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/toast-stack
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/toast-stack

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { ToastStack, ToastStackProvider, useToastStack } from "@/components/xzero/toast-stack/toast-stack";

function PublishButton() {
  const { toast, update } = useToastStack();
  async function publish() {
    const id = toast({ type: "loading", title: "Publishing" });
    await api.publish();
    update(id, { type: "success", title: "Published", action: { label: "View", onClick: openSite } });
  }
  return <button type="button" onClick={publish}>Publish</button>;
}

export function App() {
  return <ToastStackProvider><PublishButton /><ToastStack /></ToastStackProvider>;
}

Examples

Undo action

const { toast, dismiss } = useToastStack();

toast({
  type: "info",
  title: "Message archived",
  action: { label: "Undo", onClick: id => { restore(); dismiss(id); } },
});

API reference

ToastStackProvider

Scopes a toast queue to its subtree. Wrap the app or panel once.

PropTypeDefaultDescription
children (required)ReactNode–Subtree that can raise toasts.
durationnumber5000Base lifetime in ms. Warnings and errors stay 1.6 times longer; loading waits for an update.
limitnumber12Oldest toasts beyond this count are dropped.

ToastStack

The viewport. Toasts rise from the bottom, tuck behind each other, and fan out on hover or focus.

PropTypeDefaultDescription
labelstring"Notifications"Accessible name of the region.
position"bottom-right" | "bottom-center" | "bottom-left""bottom-right"Corner of the viewport.
containedbooleanfalsePins the stack inside the nearest positioned ancestor instead of the window.
visibleToastsnumber3How many toasts show at once.
hotkeybooleantrueAlt+T moves focus into the stack.
classNamestring–Class on the region.

useToastStack

Hook returning { toast, update, dismiss, count }. Must be called inside ToastStackProvider.

PropTypeDefaultDescription
toast(options: ToastOptions) => string–Shows a toast and returns its id. Options: id, type ("success" | "info" | "warning" | "error" | "loading"), title, description, action { label, onClick(id) }, duration.
update(id: string, patch: Partial<Omit<ToastOptions, "id">>) => void–Morphs a toast in place and restarts its timer. Pass action: undefined to remove the action.
dismiss(id?: string) => void–Dismisses one toast, or all when called without an id.
countnumber–How many toasts are queued.

Keyboard interactions

KeysAction
Alt+TMoves focus to the front toast and fans out the stack.
TabMoves between toast actions and dismiss buttons.
EscapeDismisses the focused toast.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in messages

Guidance for AI tools

Toast stack: Stack short results at the edge until you reach for them. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components