Toaster
The corner where toasts appear. Mount it once, in the layout. It also starts the page's smooth resizing (smooth-size.ts). A toast has no close button: it leaves by itself or is swiped away. A thin ring round its mark runs down with the time it has left, so the person sees that it goes on its own; it waits whenever the toast's timer waits (the pointer or focus on the stack, which UI SDK marks data-expanded, or the window in the background, marked here).
Preview
Use
import { Button, Row, Toaster, toast } from '@/components/ui';
<Row gap={2} center>
{/* <Toaster /> goes once in the root layout; then call toast from anywhere. */}
<Button onClick={() => toast.success({ title: 'Booking confirmed', description: 'Noor Haddad gets an email with the time' })}>Confirm</Button>
<Button onClick={() => toast.show({ title: 'Booking deleted', action: { label: 'Undo', onClick: () => toast.success({ title: 'Booking restored' }) } })}>Delete</Button>
<Button onClick={() => toast.error({ title: 'Could not send the reminder', description: 'The email address bounced' })}>Send reminder</Button>
</Row>Options
No options of its own.
Without React
With the CSS in parts (/ui/css/), it needs these, besides the ones every page loads:
components/button.csscomponents/loading.csscomponents/toast.csscomponents/icons.csscomponents/button-group-toggle.csscomponents/carousel-arrows.cssOn top of the page: states, do and don’t
A message that pops up and leaves by itself: "Saved". Its kind shows as a small round mark in front (none for show); the words stay in the text colour. It has no close button: it goes after five seconds, or is swiped away, and a thin ring round its mark runs down with the time left (it waits while the pointer or focus is on the stack, or the window is in the background). Anything the person must not miss is an Alert, never a toast that stays. ToastMark type draws the same mark elsewhere. Toaster goes once in the root layout; it also starts smooth resizing for the whole page (startSmoothSizes): cards and dialogs grow and shrink in the kit's movement time when their content changes, and a box of your own joins with data-ui-smooth. Add action: { label: 'Undo', onClick } for a button on it.
States. Closed, opening (fades and rises), open, closing (fades before what it changed appears: afterClose). While open, focus is inside and Escape closes it; when it closes, focus goes back to what opened it.
Do
- Name every dialog, drawer and popover (
DialogTitle,DrawerTitle, oraria-label). - Use
AlertDialogfor anything that cannot be undone, with the action named on its button ("Delete 3 files"). - Use a
Draweron a phone for what aPopoverdoes on a computer.
Don't
- Don't open a dialog from a dialog; change what the open one shows instead.
- Don't put the only way to do something in a right-click menu or a tooltip.
- Don't use a toast for something the person must not miss: that is an
Alerton the page.