Examples

Tones

Danger toasts are announced assertively and stay until dismissed.

Preview
    Example.tsx
    import { Button, HStack, ToastProvider, useToast } from '@reactloom/ui';
    
    function Actions() {
      const toast = useToast();
      return (
        <HStack gap="2" wrap>
          <Button onClick={() => toast.show({ title: 'Changes saved', tone: 'success' })}>Save</Button>
          <Button
            variant="secondary"
            onClick={() => toast.show({ title: 'Storage almost full', description: '92% of 10 GB used.', tone: 'warning' })}
          >
            Warn
          </Button>
          <Button
            variant="destructive"
            onClick={() => toast.show({ title: 'Upload failed', description: 'The file is larger than 25 MB.', tone: 'danger' })}
          >
            Fail
          </Button>
        </HStack>
      );
    }
    
    export default function Example() {
      // Usually one provider near the root of your app (or of each micro-frontend).
      return (
        <ToastProvider>
          <Actions />
        </ToastProvider>
      );
    }

    With an action

    Toasts with an action never time out, so everyone has time to use it.

    Preview

    Archived: 0

      Example.tsx
      import { Button, Text, ToastProvider, useToast } from '@reactloom/ui';
      import { useState } from 'react';
      
      function Inbox() {
        const toast = useToast();
        const [archived, setArchived] = useState(0);
        return (
          <>
            <Button
              onClick={() => {
                setArchived((n) => n + 1);
                toast.show({
                  id: 'archive',
                  title: 'Conversation archived',
                  action: { label: 'Undo', onAction: () => setArchived((n) => n - 1) },
                });
              }}
            >
              Archive conversation
            </Button>
            <Text size="sm" tone="muted">Archived: {archived}</Text>
          </>
        );
      }
      
      export default function Example() {
        return (
          <ToastProvider>
            <Inbox />
          </ToastProvider>
        );
      }

      Updating a toast

      Show again with the same id to replace it.

      Preview
        Example.tsx
        import { Button, ToastProvider, useToast } from '@reactloom/ui';
        
        function Publish() {
          const toast = useToast();
          return (
            <Button
              onClick={() => {
                // Reusing an id replaces the toast in place and announces the new text.
                toast.show({ id: 'publish', title: 'Publishing…', duration: Infinity });
                setTimeout(() => toast.show({ id: 'publish', title: 'Published', tone: 'success' }), 1200);
              }}
            >
              Publish
            </Button>
          );
        }
        
        export default function Example() {
          return (
            <ToastProvider placement="top-center">
              <Publish />
            </ToastProvider>
          );
        }

        API reference

        ToastProvider props

        ToastProvider props
        PropTypeDefault
        placement
        'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end''bottom-end'
        max
        Shown at once; later toasts wait in order.
        number3
        duration
        Default auto-dismiss delay in ms.
        number6000
        label
        Name of the landmark.
        string'Notifications'
        dismissLabel
        Translate this.
        string'Dismiss'
        hotkey
        Moves focus to the notifications.
        string | null'F8'

        useToast() → show(options)

        useToast() → show(options)
        PropTypeDefault
        titlerequired
        ReactNode—
        description
        ReactNode—
        tone
        'neutral' | 'info' | 'success' | 'warning' | 'danger''neutral'
        action
        One action; the toast then stays until dismissed.
        { label, onAction }—
        duration
        Infinity keeps it. Danger and action toasts default to Infinity.
        number—
        id
        Reuse to replace a toast.
        string—
        onDismiss
        () => void—
        → returns
        The id, for dismiss(id). Also: dismissAll().
        string—

        Customization

        Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

        State attributes

        Target these in your CSS to style states without depending on class names.

        AttributeValues
        [data-placement]top-start · top-center · top-end · bottom-start · bottom-center · bottom-end

        Accessibility

        • Text is announced through live regions that exist before any toast appears — the reliable way to get screen readers to speak dynamic content.
        • The stack is a labelled region landmark; F8 moves focus to it and Escape dismisses the focused toast, returning focus where you were.
        • Timers pause while the pointer is over the stack, while focus is inside it, and while the tab is hidden (WCAG 2.2.1).
        • Toasts render in the top layer but inside your DOM tree, so scoped themes apply. While a modal dialog is open, everything outside it is inert — show feedback inside the dialog instead.
        Keyboard interactions
        KeyAction
        F8Move focus to the notifications
        TabMove between toast actions
        EscapeDismiss the focused toast

        Usage guidelines

        Do

        • Use for confirmations and background events (“Saved”, “Upload complete”).
        • Offer Undo instead of a confirmation dialog for reversible actions.

        Don’t

        • Don’t put the only copy of critical information in a toast — use Alert or a Dialog.
        • Don’t use toasts for form validation errors — show them next to the field.