vael-ui v0.5.7

Overlays & confirmation

useToast

Shows toast notifications from anywhere in your app, with variant shortcuts and a promise helper that swaps a loading toast for success or error. Use it for feedback that shouldn’t interrupt the page.

Toasts you show from code. Call toast(title, options) from anywhere, even outside a component. toast.success, .error, .warning, .info and .loading set the variant for you. toast.promise(input, messages) shows a loading toast at once, then swaps it for a success or error toast when the promise settles, with no dismiss() call. Toasts render in a <Toaster/>, which you mount once at the app root.

Install

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

Examples

Parameters

Takes no arguments.

Returns

NameTypeDescription
toast(title, options?)number | stringShows a toast with the default variant and returns its id for dismiss(id): a number, or your own id. Showing an id that's already on screen updates that toast instead of adding another. Options: id, description, variant, action: { label, onClick }, and duration in ms (default 4000, or Infinity for toasts with an action; Infinity keeps it until someone closes it). pinned shows the toast in its own section, where newer toasts can't cover it. toaster sends it to the <Toaster> with that name instead of the unnamed one.
toast.success / .error / .warning / .info / .loading(title, options?) => numberSame signature with a fixed variant. loading defaults to duration: Infinity.
toast.promise(input, messages, options?)Promise<T>input is a promise or a function that returns one. Shows messages.loading at once, then messages.success or messages.error. Each can be a string or a function of the settled value or error.
toast.dismiss(id?)(id?: number | string) => voidDismisses one toast, or every toast when you omit id.
useToastQueue(toaster?){ toasts, dismiss, pauseAll, resumeAll, setWaiting }Reads one Toaster's queue and pauses or resumes its timers: the unnamed Toaster, or the one whose name you pass. <Toaster/> uses it to pause timers on pointerenter. setWaiting(ids) holds the timers of toasts that aren't on screen yet.