vael-ui v0.5.7

Feedback

Layout

Toaster

The container that shows the notifications toast() creates. Mount it once, anywhere in your app.

Install

import { Toaster } from 'vael-ui'

Playground

import { toast, Toaster } from 'vael-ui'

<Toaster position="bottom-right" :max-visible="4" :gap="10" />

// anywhere in your app
toast('Saved changes')
toast.success('Upload complete')

// pinned: its own section, never covered by newer toasts
// id: calling again updates this toast instead of adding a second one
toast.warning('Verify your email', { id: 'verify-email', pinned: true, duration: Infinity })
toast.dismiss('verify-email')

Props

NameTypeDefaultDescription
namestringShows only toasts sent to this name. Without one, it shows toasts that have no toaster.
position'bottom-right' | 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center''bottom-right'Screen corner or edge the toasts stack from.
maxVisiblenumber4Max toasts shown at once. Extra toasts wait off-screen, timers paused, until a slot opens.
expandbooleanfalseKeeps the stack open as a list, so every toast stays readable. Timers keep running, and hover or focus still pauses them.
gapnumber10Spacing between stacked cards, in pixels.
teleportTostring | HTMLElement'body'Teleport target: a CSS selector or element. Wins over container either way.
containerDOMTargetScopes the stack to an element instead of the viewport: it teleports there and sits in that element's corner, so give the element position: relative. Pair with name to send only some toasts there. Omit it for a page-level toaster.
motionToasterMotiontrueHow toasts come and go. false shows and removes them at once. An object animates them your way: values for the toast part, or enter / leave hooks for your own library. The stack places them either way.
uiPartial<Record<'root' | 'toast' | 'icon' | 'content' | 'title' | 'description' | 'action' | 'close', UiPartValue>>Class and style overrides for each part.

Events

No events.

Slots

NameTypeDescription
default{ entry: ToastEntry; dismiss: () => void; depth: number; expanded: boolean; }Replaces a toast's inner markup; the toaster still handles its positioning, stacking and swipe.

Exposed

NameTypeDescription
toasterElHTMLElement | nullThe toast list (<ol>) element, inside the live region.

Motion New

Toaster's motion: values or hooks for its parts (ToasterPart), its states (loading, success, error, warning, info), how its items come and go (stagger, leaving, appear). false turns it off.

<Toaster
  :motion="{ initial: { toast: { opacity: 0, y: 8 } }, stagger: 0.04 }"
/>
NameTypeDescription
initialexitroottoasticoncontenttitledescriptionactioncloseSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
statesloadingsuccesserrorwarninginfoSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
staggerleavingappearnumber | 'pop' | 'hold' | booleanItems coming in together start stagger seconds apart. A leaving item lifts out so the rest close the gap ('pop'), or keeps its space until it's gone ('hold'). appear: true also brings in the items already there when it mounts.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

KeyAction
EnterSpaceRuns the focused toast’s action or dismiss button.
  • Toasts render in a <section aria-live="polite"> named “Notifications”, so screen readers announce them without moving focus. Error toasts are announced assertively. Pass aria-label to rename the section when a page has more than one Toaster.
  • Hovering or focusing the stack expands it and pauses every timer; timers also pause while the tab is hidden. Toasts close after 4000 ms by default. Toasts with an action stay until someone closes them, so a keyboard user can reach the button, and loading toasts stay until they settle.
  • The dismiss button is named “Dismiss” and the status icon is aria-hidden. A custom default slot replaces this markup, so label your own buttons.
  • Dismissing a toast from the keyboard moves focus to a neighboring toast, or back to where focus came from.