Skip to content
Porcelana

Toast

Short notifications raised from anywhere with toast(), with actions and swipe to dismiss.

Overlays

Example

Example.tsx
import { Button, toast } from "@porcelana/ui";

// Mount <Toaster /> once near the root of your app (this site already does).

export default function Example() {
  return (
    <div style={{ display: "flex", flexWrap: "wrap", gap: 12 }}>
      <Button
        onClick={() =>
          toast({
            title: "Alarm saved",
            description: "06:00 · weekdays",
            action: { label: "Undo", altText: "Undo saving the alarm", onClick: () => {} }
          })
        }
      >
        Show toast
      </Button>
      <Button variant="danger" onClick={() => toast({ title: "Sync failed", tone: "danger" })}>
        Error toast
      </Button>
    </div>
  );
}

Import

Import
import { Toaster } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app root

Props

Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.

Toaster

Mount once near the root. Toasts are announced politely and can be swiped away.

PropTypeDefaultDescription
closeLabelstringDismissAccessible name of each toast's close button.
hotkeystring[]–Keyboard shortcut that moves focus to the toasts. Default F8.
labelstringNotificationsLabel for the region landmark announced to screen readers.
swipeDirection"right" | "left" | "up" | "down"rightDirection a toast can be swiped to dismiss it.

Accessibility

  • Toasts are announced politely (errors assertively) in a labelled region; F8 moves focus there.
  • Actions need altText describing another way to do the same thing.
  • Timers pause while the toast is hovered or focused.

Mobile

  • Swipe sideways to dismiss; the stack respects the iPhone home indicator area.