Skip to content

Feedback

IToaster

Transient notifications, raised from anywhere — including plain functions outside a component's setup.

Mount one <IToaster /> in the app, typically just inside <IApp>, then call useToast() wherever you need it. This site mounts one, so every button below raises a real toast.

A string is shorthand for { title }. Pass an object for anything more.

Variants

Five of them, with the colour in the icon rather than the surface, as in IAlert and IBadge.

success(…) and friends are shorthand for toast({ …, variant }), so anything the base call takes works on them too.

Duration

duration is milliseconds before the toast dismisses itself, falling back to the IToaster's own duration (5000 by default). 0 keeps it open until dismissed.

Actions

An action puts one button in the toast. A toast leaves on its own, so keep it to undo-shaped offers and put anything the reader must do in a dialog.

Dismissing from code

toast() returns an id, so a toast raised while work is in flight can be taken down when the work finishes.

Position

Six viewport positions, set once on the IToaster. Individual toasts do not choose their own.

vue
<IApp>
  <RouterView />
  <IToaster position="bottom-right" />
</IApp>

The API

ts
const { toast, success, warning, danger, info, dismiss, clear } = useToast()

toast(options) // returns a number: the toast's id
success(options)
warning(options)
danger(options)
info(options)
dismiss(id)
clear()

options is a string — shorthand for the title — or:

ts
interface ToastOptions {
  title?: string
  description?: string
  variant?: 'neutral' | 'success' | 'warning' | 'danger' | 'info'
  /** Milliseconds before auto-dismiss. `0` keeps it until dismissed. */
  duration?: number
  action?: {
    label: string
    onClick: () => void
  }
}

The store behind it is a module-level singleton, so toast() can be called from a plain function with no component in scope.

Props

PropTypeDefaultDescription
position'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'Viewport corner the stack grows from
durationnumber5000Fallback auto-dismiss; a toast's own duration wins
closeLabelstring'Close'Accessible name for each dismiss button
unstyledbooleanDrop built-in classes
classstringMerged with the built-in classes
ui{ viewport?, root?, icon?, content?, title?, description?, action?, close? }Per-slot class overrides

Mount exactly one. Two toasters render the same store twice, so every toast appears twice.