Skip to content

Toast

import { Toaster, toast } from '@yarcl/react';

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

import { Toaster, toast } from '@yarcl/react';
<App />
<Toaster placement="bottom-right" />
toast({ title: 'Saved', color: 'success', radius: 'lg', padding: 'md' });
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.
  • radius, gap, padding and textStyle use keys from your config and can be set in components.Toast.

Spacing props accept typed breakpoint maps. See responsive props for supported props, defaults and examples.

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.
dismissLabelstringconfig.labels.dismissAccessible name of this notification's dismiss button.
durationnumberconfig.timing.toastDurationTime before it dismisses itself, in ms. Paused while hovered or focused. 0 keeps it until dismissed.
gapResponsive<Spacing>configconfig.components.Toast.gap ?? config.defaults.gapSpace between the message, action and dismiss button, from the spacing config. Accepts a scalar or breakpoint map.
paddingResponsive<Spacing>configconfig.components.Toast.padding ?? config.defaults.paddingInner spacing, from the spacing config. Accepts a scalar or breakpoint map.
radiusRadiusconfigconfig.components.Toast.radius ?? config.defaults.radiusCorner radius, from the radii config.
textStyleTextStyleconfigconfig.components.Toast.textStyle ?? config.defaults.labelStyleTypography style, from the typography.styles config.
urgentbooleanAnnounces immediately (role="alert") instead of politely. Use for errors that need attention.
PropTypeDefaultDescription
labelstringconfig.labels.notificationsAccessible 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.