Skip to content

Feedback

Toast

A brief, non-blocking message after an action: saved, hidden, failed.

import { Toaster } from '@jsonresume/ui'Source(opens in a new tab)

Examples

Tones and actionsSuccess, an undo action, and an error that stays announced assertively.
Show code
toast/tones.tsx
'use client';

import { Button, toast } from '@jsonresume/ui';

// Mount <Toaster /> once in your root layout, then call toast() anywhere.
export default function ToastTones() {
  return (
    <>
      <Button
        variant="primary"
        onClick={() => toast({ title: 'Resume saved', tone: 'success' })}
      >
        Save
      </Button>
      <Button
        onClick={() =>
          toast({
            title: 'Job hidden',
            description: 'Senior Engineer at Stripe',
            action: {
              label: 'Undo',
              altText: 'Undo hiding the job',
              onClick: () => toast({ title: 'Job restored' }),
            },
          })
        }
      >
        Hide job
      </Button>
      <Button
        variant="danger"
        onClick={() =>
          toast({
            title: 'Upload failed',
            description: 'resume.pdf is larger than 5 MB.',
            tone: 'danger',
          })
        }
      >
        Fail upload
      </Button>
    </>
  );
}

Usage

Do

  • Confirm actions that happen out of view.
  • Offer Undo instead of asking "Are you sure?".

Don’t

  • Put the only copy of important information in a toast.
  • Show more than one at a time for one action.

Accessibility

  • Announced through a live region; errors use an assertive announcement.
  • Timers pause on hover and focus; F8 moves focus to the notifications region.

Props

<Toaster>

Also accepts the attributes of the element Toaster renders.
PropTypeDefaultDescription
closeLabelstringDismiss
labelstringNotificationsAccessible name of the notifications region.