Toast
Short notifications raised from anywhere with toast(), with actions and swipe to dismiss.
Example
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 { Toaster } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app rootProps
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.
| Prop | Type | Default | Description |
|---|---|---|---|
closeLabel | string | Dismiss | Accessible name of each toast's close button. |
hotkey | string[] | – | Keyboard shortcut that moves focus to the toasts. Default F8. |
label | string | Notifications | Label for the region landmark announced to screen readers. |
swipeDirection | "right" | "left" | "up" | "down" | right | Direction 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.