Skip to content

Toast

import { Toaster, toast } from 'yarcl';

Render one <Toaster /> near the root of your app, then call toast() from anywhere.

import { Toaster, toast } from 'yarcl';
<App />
<Toaster placement="bottom-right" />
toast({ title: 'Saved', color: 'success' });
toast({ title: 'Message deleted', action: { label: 'Undo', onClick: restore } });
toast({ title: 'Upload failed', color: 'danger', urgent: true, duration: 0 });
  • Toasts dismiss themselves after duration (5 s); hovering or focusing one pauses the timer. duration: 0 keeps it until dismissed.
  • Beyond limit, the oldest toasts are dismissed.
  • The toaster lives in the browser’s top layer, above everything. While a modal Dialog is open, toasts render inside it so they stay clickable.
  • Toasts are announced politely (role="status"); urgent uses role="alert".
  • toast() returns an id; toast.dismiss(id) removes one, toast.dismiss() removes all.
PropTypeDefaultDescription
title requiredReactNodeMain message.
action{ label: string; onClick: () => void }A single action, e.g. Undo. Choosing it dismisses the toast.
colorColorconfigconfig.defaults.colorAccent color, from the colors config.
descriptionReactNodeSupporting text.
durationnumber5000Time before it dismisses itself, in ms. Paused while hovered or focused. 0 keeps it until dismissed.
urgentbooleanAnnounces immediately (role="alert") instead of politely. Use for errors that need attention.
PropTypeDefaultDescription
labelstring'Notifications'Accessible name of the notifications region.
limitnumber4Maximum toasts shown at once. When exceeded, the oldest are dismissed.
placement'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right''bottom-right'Screen corner or edge where toasts appear.