PeakUI

Toast

Temporary notifications with auto-dismiss and stacking

Usage

Mount <Toast.Provider /> once at the app root; the toast helper then works anywhere.

import {Button, Toast, toast} from "@peakui/react";

export default () => (
  <>
    <Toast.Provider />
    <Button onPress={() => toast("Simple message")}>Show toast</Button>
  </>
);

Anatomy

import {Toast} from "@peakui/react";

export default () => (
  <Toast.Provider>
    <Toast toast={{key: "..."}}>
      <Toast.Indicator />
      <Toast.Content>
        <Toast.Title />
        <Toast.Description />
      </Toast.Content>
      <Toast.ActionButton />
      <Toast.CloseButton />
    </Toast>
  </Toast.Provider>
);

Examples

Variants

Placements

Expanded Stack

Simple Toasts

Custom Indicator

Custom Toast Rendering

Promise and Loading

Callbacks

Custom Queues

Customization

Tailwind CSS

Global CSS

@layer components {
  .toast {
    @apply rounded-xl shadow-lg;
  }

  .toast__content {
    @apply gap-2;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Toast component uses these CSS classes (view source styles):

Base & Element Classes

  • .toast - Base toast styles with stacking and motion
  • .toast-region - Fixed region container, rendered when the queue is non-empty
  • .toast__content - Content wrapper for title and description
  • .toast__indicator - Icon or spinner container
  • .toast__title - Toast title text
  • .toast__description - Toast description text
  • .toast__action - Action button wrapper
  • .toast__close-button - Close button, revealed on toast hover

Variant Classes

  • .toast--default
  • .toast--accent
  • .toast--success
  • .toast--warning
  • .toast--danger

Placement Classes

  • .toast-region--top, .toast--top
  • .toast-region--top-start, .toast--top-start
  • .toast-region--top-end, .toast--top-end
  • .toast-region--bottom, .toast--bottom
  • .toast-region--bottom-start, .toast--bottom-start
  • .toast-region--bottom-end, .toast--bottom-end

Slots

  • [data-slot="toast-region"] - The region landmark
  • [data-slot="toast"] - A single toast
  • [data-slot="toast-content"] - The content wrapper
  • [data-slot="toast-indicator"] - The indicator
  • [data-slot="toast-default-icon"] - The variant's default status icon
  • [data-slot="toast-title"] - The title
  • [data-slot="toast-description"] - The description
  • [data-slot="toast-action-button"] - The action button
  • [data-slot="toast-close"] - The close button

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Frontmost: [data-frontmost="true"] - The topmost visible toast
  • Index: [data-index] - Position in the stack, 0 is frontmost
  • Placement: [data-placement] - Region placement
  • Entering: [data-entering="true"] - First paint of a new toast
  • Exiting: [data-exiting="true"] - Exit animation is playing
  • Expanded: [data-expanded="true"] - The stack is expanded
  • Hidden: [data-hidden="true"] - Beyond maxVisibleToasts
  • Focus: :focus-visible on .toast and .toast-region
  • Swapped: [data-swapped="true"] on .toast__indicator when its content is replaced

API Reference

Toast.Provider

PropTypeDefaultDescription
placement"top start" | "top" | "top end" | "bottom start" | "bottom" | "bottom end""bottom"Placement of the toast region
gapnumber12The gap between toasts in pixels
isExpandedbooleanfalseForce the stack into its expanded layout; does not pause timers
maxVisibleToastsnumber3Maximum number of toasts to display at once (visual only)
hotkeystring[]["altKey", "KeyT"]Hotkey that moves focus to the region and expands the stack. Modifiers match KeyboardEvent boolean properties, other keys match event.code. Modifiers left out must be up. Pass [] to disable
scaleFactornumber0.05How much each toast behind the front one scales down
widthnumber | string460Width of the toast; numbers are pixels
queueToastQueue<T>shared queueCustom toast queue instance
childrenReactNode | ((props) => ReactNode)default layoutCustom render function or children replacing the default toast layout
aria-labelstringlocalized countAccessible name of the region landmark
...restToastRegionProps-React Aria ToastRegion attributes

Toast

PropTypeDefaultDescription
toastQueuedToast<T>-Toast data from the queue, required
variant"default" | "accent" | "success" | "warning" | "danger""default"Visual variant of the toast
placementToastVariants["placement"]from ProviderStacking direction of the toast
scaleFactornumberfrom ProviderHow much each toast behind the front one scales down
...restToastProps-React Aria Toast attributes

Toast.Content

PropTypeDefaultDescription
childrenReactNode-Content, typically Toast.Title and Toast.Description
classNamestring-Additional classes
...restToastContentProps-React Aria ToastContent attributes

Toast.Indicator

PropTypeDefaultDescription
variantToastVariants["variant"]-Selects the default status icon
childrenReactNodedefault iconCustom indicator; null in queue content hides the slot
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

Toast.Title

PropTypeDefaultDescription
childrenReactNode-Title text; labels the toast via aria-labelledby
classNamestring-Additional classes
...restTextProps-React Aria Text attributes

Toast.Description

PropTypeDefaultDescription
childrenReactNode-Description text, linked as aria-describedby
classNamestring-Additional classes
...restTextProps-React Aria Text attributes

Toast.ActionButton

PropTypeDefaultDescription
childrenReactNode-Action button content
...restButtonProps-All Button component props

Toast.CloseButton

PropTypeDefaultDescription
...restCloseButtonProps-All CloseButton component props; closes the toast

Render Props

PropTypeDescription
Toast.Provider children(props: {toast: QueuedToast<T>, isLoading: boolean}) => ReactNodeRenders a custom toast layout; isLoading reads the queued content
Toast classNamestring | ((renderProps) => string)Additional classes, or a function of the toast state
Toast styleCSSProperties | ((renderProps) => CSSProperties)Merged after the computed stacking variables

ToastQueue

A ToastQueue manages the state for a <Toast.Provider>. The state is stored outside React, so you can trigger toasts from anywhere.

Constructor Options

OptionTypeDefaultDescription
exitDurationnumber300How long a closing toast stays mounted for its exit animation; 0 removes immediately
maxVisibleToastsnumber3Maximum number of toasts to display at once (visual only); used when the provider omits its own
wrapUpdate(fn: () => void) => void-Wraps state updates, e.g. document.startViewTransition

Methods

MethodParametersReturnsDescription
add(content: T, options?: ToastOptions)stringAdd a toast to the queue, returns its key
update(key: string, content: T, options?: {timeout?: number; onClose?: () => void})booleanUpdate a toast in place, preserving its stack position; timeout restarts the countdown (0 keeps it open), omitting it keeps the current countdown. Returns false if the toast no longer exists
close(key: string)voidClose a toast by its key
pauseAll()voidPause all toast timers
resumeAll()voidResume all toast timers
clear()voidClose all toasts; each animates out and fires its onClose
subscribe(fn: () => void)() => voidSubscribe to queue changes
destroy()voidRelease pending timeouts and timers, for HMR and test teardown

toast

The default toast function is bound to the shared queue used by <Toast.Provider>:

import {toast} from "@peakui/react";

// Basic toast (auto-dismisses after 4 seconds by default)
toast("Event has been created");

// Variant methods
toast.success("File saved");
toast.info("New update available");
toast.warning("Please check your settings");
toast.danger("Something went wrong");

// With options. The returned id lets the action close its own toast.
const eventId = toast("Event has been created", {
  description: "Your event has been scheduled for tomorrow",
  timeout: 5000,
  onClose: () => console.log("Closed"),
  actionProps: {children: "View", onPress: () => toast.close(eventId)},
});

// Update in place (same toast, same stack position).
const id = toast("Saving…", {timeout: 0});
toast.update(id, "Saved", {variant: "success", timeout: 4000});

// Promise support: a persistent loading toast settles in place.
toast.promise(uploadFile(), {
  loading: "Uploading file...",
  success: (data) => `File ${data.filename} uploaded`,
  error: "Failed to upload file",
});

// Queue methods
toast.close(key);
toast.clear();
toast.pauseAll();
toast.resumeAll();

toast Options

OptionTypeDefaultDescription
descriptionReactNode-Description text below the title
indicatorReactNodevariant iconCustom indicator icon; null hides the indicator
variant"default" | "accent" | "success" | "warning" | "danger""default"Visual variant
actionPropsButtonProps-Props for the action button
isLoadingbooleanfalseShow a spinner in place of the indicator
timeoutnumber4000Auto-dismiss timeout in milliseconds; 0 keeps the toast open
onClose() => void-Called when the toast is dismissed, as its exit animation starts

toast.promise Options

OptionTypeDefaultDescription
loadingReactNode-Message shown while the promise is pending
successReactNode | ((data: T) => ReactNode)-Message shown on success
errorReactNode | ((error: Error) => ReactNode)-Message shown on rejection

On this page