ToastUpdated
News that arrives on the page: the page leans in towards the place where a toast is about to stand, the toast comes up out of it, and a ripple runs out as the page lets go. Toasts pile up behind the newest one; press the pile and it opens into a list under a header of glass buttons that shows less or clears it. Each toast is swiped away.
Latest changeImprovedv3.0.9A toast swiped away carries on at the speed of the finger instead of stopping for a moment and speeding up again (the drawer curve, not an ease-in).
- v3.0.9ImprovedA toast swiped away carries on at the speed of the finger instead of stopping for a moment and speeding up again (the drawer curve, not an ease-in).
- v3.0.7ImprovedThe row under an open list's header no longer frosts the page in a pill with round ends, which stood behind the name like a card. Its frost grows instead: from nothing 40 px past the row on either side (never past the edge of the screen: it is cut there) and 50 px above it, to twice the toasts' blur (
blur) 143 px in from the sides and 120 px in from the top, and it ends 40 px under the row, under the first toast. It is four layers of backdrop blur, each more blurred than the one before it, so the page goes soft gradually instead of a blurred page fading in over a sharp one. The name and the buttons stay where they were, and the name takes the tone of the toasts' glass. The row draws no glass of its own any more: one canvas and its pictures of the page fewer while a list is open. - v3.0.7ImprovedThe page leans in for a toast with a wider ring of blur around the place the toast will stand: 40 px of blur where it had 16 (
ARRIVE.haze, tuned in the lab with the rest of the arrival). It is the toast's own: Sweep's lean, the landing page's slide and the theme switch keep 16. - v2.4.8ImprovedToasts now arrive at the top right of the screen:
GlassToasterstands atside="top"andalign="end"unless you say otherwise (it stood at the middle of the bottom edge;side="bottom" align="center"keeps it there). - v2.4.8ImprovedA stack at the bottom of the screen now looks as it does at the top: the newest toast on top and the ones behind it showing 10 px under it, where they used to show over it. The pile stands on its place, so the newest is lifted by the ones under it and nothing reaches past the gap to the edge. Opened, the list reads downwards too, under its header: the newest first, the rest below. The header follows the list as toasts come and go and stays where it was while a list is cleared, a toast on its way out keeps its place, and Show less folds into an arrow that points down, towards the pile.
- v2.4.8ImprovedThe header of an open list now stands on a row that frosts the page behind it, with the blur the toasts and Dialog's pane have (10.25 px, set by
blur): a row 44 px tall with round ends and nothing else of glass, no tint, no line, no bend, no light and no shadow. The list's name reads on it over text and colour, in the tone of the page. - All changes →
Use it for
- News that asks nothing of the visitor, or offers one way back: saved, sent, copied, archived with an Undo.
- The outcome of something that took a moment: an upload, a save over a slow connection. One toast loads, then turns into the result.
- Something nobody pressed: a message from someone else, a payment that came in.
Not for
- A question that must be answered: use Dialog with
alert. A toast leaves by itself. - What is wrong with one field of a form: say it beside the field, where it stays.
- Every row checked or every key typed: the page leaning in marks a moment, and a moment that repeats is noise. Keep such toasts rare, or give the toaster
gather={false}.
Installation
npx shadcn@latest add https://liquidglass.onemorethink.dev/r/toast.jsonThe behaviour (the queue and its timers, the top layer, the stack's measures, the swipe, F6 and Escape, the announcements to screen readers) comes from UI SDK, so Toast needs @ui-sdk/core and @ui-sdk/react. The install command adds them at the exact version this was built on: UI SDK is in beta and its API may still change.
Usage
import { GlassToaster, toast } from '@/components/liquid-glass/glass-toast'
// Once, near the root of your app.
<GlassToaster />
// From anywhere: a component, a server action's callback, plain code.
toast('Event created')
toast.success('Changes saved', { description: 'Friday at 10:00' })
toast('Message archived', { action: { label: 'Undo', onAction: restore } })Place GlassToaster once and call toast() from anywhere; it returns the toast's id. As a toast arrives, the page around where it will stand is drawn in towards that place for a third of a second, softening in a ring around it. Half way through, the toast comes up out of it: it fades up as it grows from 80%, lands a little past its size and settles, on the spring Dialog's pane rises on. Then the page lets go and one crest runs outwards, leaving it flat. The toast wears the glass of every surface that opens over the page (Dialog's pane, a Popover, a Menu): a 60% tint, a 10 px frost and a rim that bends the page it covers, and its text follows the tone of the glass.
The stack stands at the top right of the screen unless you place it elsewhere (side, align). Newer toasts come in front: the ones behind stand as tall as the newest, a little smaller each, and show 10 px under it. It looks the same wherever it stands, the newest on top and the rest under it: at the bottom of the screen the stack stands on its place, so the newest is lifted by the ones under it. Press the pile, or move the keyboard's focus into it, and it opens into a list, as a notification centre does: each toast under the one before it, below a header with the list's name (title) and two small glass buttons. The header's row only frosts the page behind it, with the toasts' own blur: no tint, no line, no bend and no edge. The frost has nowhere it begins: it grows from nothing well past the row to twice the toasts' blur under the name, so the name reads over whatever the list covers and no card stands behind it. Show less folds the list back into the pile. The other is a cross that opens into Clear while the pointer is on it, as Show less folds into an arrow, and dismisses every toast. The words are yours to translate (labels), expanded keeps the stack a list, and a list left with one toast closes by itself. The timers wait while the pointer or focus is in the stack. A toast leaves after five seconds (duration, in ms, on one toast or on a toaster made with createToaster; Infinity keeps it). It can be swiped towards the edge it stands on or the end it is aligned to, the glass following the finger over a picture of the page it already has, and the close button in its corner shows while the pointer is on it. However a toast is closed, it goes where it stands, as a notification does: within a seventh of a second what it says blurs away and the glass fades as it grows a little, so the page shows sharp through it before it has gone. A swiped one goes the same way on its way off to the side.
Types and promises
toast.success, .info, .warning, .error and .loading set the toast's type: it brings its own icon, and decides how the toast is announced (an error interrupts, the others wait for a pause). toast.promise() shows a loading toast and turns the same toast into the result when the promise settles; each message is a string, or options with a description and an action. A loading toast stays until it is updated or dismissed.
Actions
An action is a soft pill at the end of the toast, like Undo; with an href it is a link. Pressing it runs onAction and closes the toast, and a Promise returned from it keeps the toast open and the button pending until it settles. A cancel is a second button, plain text beside the action, that only dismisses (GlassToastClose in a toast you render yourself). onDismiss tells you why a toast is closing (timeout, swipe, close-press, escape-key, action), and dismissible: false takes the swipe, Escape and the corner button away for a toast that has to be answered with its own button.
const id = toast('Message archived', {
action: { label: 'Undo', onAction: async () => { await restore() } },
onDismiss: ({ reason }) => console.log(reason),
})
toast.update(id, { title: 'Message restored', type: 'success' })
toast.dismiss(id) // or toast.dismiss() for every toastA toast of your own
The toaster's children render each toast. GlassToast is the pane of glass; put GlassToastTitle, GlassToastDescription, GlassToastAction and GlassToastClose in it, and anything of yours beside them. Empty, each part shows the text of the toast it is in. icon replaces the type's icon with an avatar or an app's mark, and whatever else a toast needs travels in data. side and align place the stack: top or bottom, and start, center or end; the page leans in wherever it stands.
The page leaning in
The lean is gatherPage(), in glass-gather.ts, and it is ported from the page effect of glimm (glimm.dev, MIT): the gather that reads the page further out around a point, the ring of blur around it, and the crest and trough of the ripple are its, with its numbers, but for the ring, which is wider for a toast: 40 px of blur where glimm has 16 (Sweep's lean keeps 16). glimm moves the page itself, which takes HTML-in-Canvas (Chrome 157 and later). This moves a picture of the page, painted by the kit's own dom-snapshot, so it runs wherever WebGL2 does. The picture is of the field around the toast alone and is taken once (again every 120 ms only while something in it moves by itself), and it shows only where it moves the page: everywhere else, and before and after, the page under it is the page. A scroll or a resize lets go at once. It carries no colour band of its own.
// The page stays still: toasts only come up.
<GlassToaster gather={false} />
// The lean by itself, for something of your own that arrives (a point of the viewport, CSS px).
import { gatherPage } from '@/components/liquid-glass/glass-gather'
gatherPage({ x: 640, y: 80 })
// The lean alone, for a page that waits on something it was asked for: you say how far in it is
// (0 to 1 is a toast's own lean; up to 2 is further in) and when it ends. `keep` is left as it
// is while the page leans in around it. The ripple is yours to run too: where its crest is, as a
// share of the field (0 to 1), and how strong.
import { leanPage } from '@/components/liquid-glass/glass-gather'
const page = leanPage({ x: 640, y: 400 }, { keep: button })
page?.lean(1)
page?.ripple(0.4, 1)
page?.end()API reference
| Prop | Type | Default |
|---|---|---|
toast(message, options) / toast(options)Shows a toast and returns its id. | (…) => string | — |
title / descriptionOn a toast: the main message, and more detail under it. | ReactNode | — |
durationOn a toast, or in | number | 5000 |
actionOn a toast: a button that does something, like Undo. A Promise from | { label, onAction?, href?, dismiss? } | — |
cancel / dismissible / onDismissOn a toast: a button that only dismisses it, whether the visitor can dismiss it (default | { label, onCancel? } / boolean / (details) => void | — |
id / type / priority / dataOn a toast: an id of your own (a toast with an id that is showing is updated in place), its type, how it is announced, and anything else for your own rendering. | string / ToastType / 'polite' | 'assertive' / unknown | — |
GlassToaster side / alignWhere the stack stands: the top right corner by default. On either side the newest is on top and the rest show under it. Swiping towards the side dismisses a toast and, unless it is centred, so does swiping towards the end it is aligned to. | 'top' | 'bottom' / 'start' | 'center' | 'end' | 'top' / 'end' |
GlassToaster gatherThe page leans in towards a toast as it arrives, and ripples as it lets go. | boolean | true |
GlassToaster maxVisible / expandedHow many toasts show at once (the rest wait, with their timers stopped), and whether the stack is always a list (its header then has no Show less). | number / boolean | 3 / false |
GlassToaster title / labelsThe name of the open list, at the start of its header (left out: the two buttons alone), and the words on those buttons, in the page's language. | ReactNode / { less?: string; clear?: string } | — / { less: 'Show less', clear: 'Clear' } |
GlassToaster offsetHow far the stack keeps from the edges of the screen, in px. | number | 16 |
GlassToaster toasterFrom | Toaster | — |
GlassToaster shortcut / aria-labelThe key that moves focus into the stack and back ( | string | null / string | 'F6' / 'Notifications' |
GlassToaster tint / blur / opticsThe toasts' glass, as on Card: how much tint covers the page, how much it is frosted (px), and the fine-tuning. | number / number / GlassOptics | 0.6 / 10.25 |
GlassToaster childrenRenders each toast, with | (toast, item) => ReactNode | — |
GlassToast iconWhat stands before the text, in place of the type's icon. | ReactNode | — |
GlassToast classNameClasses for the pane: | string | — |
GlassToastTitle / GlassToastDescriptionThe toast's title and description; the toast's own text when they have no children. | children, className | — |
GlassToastAction onAction / dismissThe action's button. | (event, details) => unknown / boolean | — |
GlassToastClose actionA text button that closes the toast. Its | () => unknown | — |
Accessibility
- Every toast is announced once through a live region, without taking focus: politely, and an error at once. Keep messages short, and give one that has to stay
duration: Infinity. - While it has toasts the stack is a landmark named Notifications: set
aria-labelin the page's language. - F6 moves focus to the newest toast and back, and the pile opens into a list as the keyboard's focus comes in; Tab goes through the header's buttons, the toasts and their buttons, and Escape dismisses the toast that has focus. The stack stays reachable over a modal dialog.
- The timers wait while the pointer or focus is in the stack, while the page is hidden and while its window is inactive.
- With reduced motion the page stays still and a toast only fades. Without WebGL2 it is a plain frosted panel, and the page stays still too.
Liquid Glass is built and maintained by one person. If it saves you time, you can sponsor the work.