// preview in
saved for every page

Toast

Short feedback after an action, shown in a corner and gone after a few seconds. Use it to confirm what happened without moving people away from their work.

Built on Base UIPattern WAI-ARIA statusClient componentSource ↗
minimal · light · #3fa34d
type

Installation

Set up Camaleo once (Installation), then import what you need.

import { ToastProvider, useToast } from "@camaleo/react";

One provider for the whole app

Put ToastProvider once, near the root, inside your StyleProvider. It renders the corner where toasts stack and the live region that reads them out. Two providers mean two stacks that overlap and two voices for screen readers.

app/layout.tsx
import { StyleProvider, ToastProvider } from "@camaleo/react";

export default function RootLayout({ children }: { children: React.ReactNode }) {
	return (
		<html lang="en">
			<body>
				<StyleProvider styleName="editorial">
					<ToastProvider closeLabel="Close">{children}</ToastProvider>
				</StyleProvider>
			</body>
		</html>
	);
}

Then call useToast() in any component below it:

const toast = useToast();
toast.add({ title: "Preferences saved", type: "success" });

Anatomy

A corner of the screen (the viewport) that stacks the toasts. Each toast has the tone's icon, a title, an optional description and action, and a close button.

viewporttoastPreferences saved
[data-slot="toast-viewport"][data-slot="toast"]title · description · action · close

Examples

Every example is a real file you can copy. They all wear the skin, mode and brand from the bar above. Each one brings its own ToastProvider only so it runs alone on this page; in your app, use the one at the root.

minimal · light · #3fa34d

Tones

Click each one. The type picks the color and icon: info for progress, success when it worked, warning when it may not, danger when it failed.

With undo

Click Archive, then Undo. Offer undo for actions that are easy to reverse, instead of asking "Are you sure?" first.

Longer on screen

timeout is in milliseconds; the default is 5000. Give a longer message more time, so people can finish reading it.

Stays until closed

timeout: 0 keeps the toast until people act on it or close it. Use it when the message still matters later, like a new version to reload.

Loading, then done

Click Upload. toast.promise() shows a loading toast with a spinner, then turns it into the success or error toast when the promise settles. One toast tells the whole story.

Urgent

priority: "high" interrupts the screen reader. Keep it for problems people must know about right now, like losing the connection.

One toast for a batch

After a bulk action, sum it up in one toast: "12 contacts updated", not twelve toasts.

Read out without moving focus

Toasts are announced when the screen reader is free, and focus stays where it was, so people can keep typing.

In context

Toasts confirm actions taken elsewhere on the page. These are whole pieces of UI you can copy, in the skin you picked.

Q3 roadmap review

Marcus Lee · 4 replies · last reply on Oct 24

Archive a conversationCard · Toast · Button

Design tokens

design-tokens-v2.json · 1.4 MB

Export a fileCard · Toast · Button

Invite teammates

Anyone with this link can join Acme Studio as an editor until November 30.

Copy an invite linkCard · Toast · Button

Guidelines

DoConfirm what just happened.

A few words people can read at a glance: what was done and, if useful, where to find it.

Don’tAsk for a decision in a toast.

It disappears on its own, and keyboard users may never reach it. Use a dialog for choices people must make.

DoOne toast for a bulk action.

"4 conversations archived" says it once and keeps the screen clear.

Don’tOne toast per item.

A stack of toasts covers the page, and screen readers read every one of them.

Props

PropTypeDefaultDescription
closeLabelstring"Close"Accessible name of each toast's close button (translatable).
timeoutnumber5000Default time on screen, in milliseconds, for every toast. 0 keeps toasts until people close them.
limitnumber3How many toasts show at once. Older ones get data-limited and are hidden until a newer one closes.

useToast() returns add, update, close, promise and the toasts list. add takes title, description, type, timeout, priority, actionProps and onClose, and returns the toast's id. type is info, success, warning or danger; loading (a spinner) and error (same as danger) also work, and are what promise uses.

Styling hooks

Restyle it without forking: target the attributes, or set the tokens on a parent, a skin or the viewport.

Attributes

data-toneinfo · success · warning · danger

Tokens it reads

Color

--cml-border--cml-fg--cml-fg-muted--cml-focus-offset--cml-focus-ring--cml-focus-width--cml-popover-bg--cml-popover-border--cml-radius-surface--cml-shadow-popover--cml-surface-raised

Shape & size

--cml-border-width--cml-popover-border-width--cml-radius-control

Type & motion

--cml-duration-base--cml-ease-standard--cml-motion-distance

This component only

--cml-corner-shape--cml-item-highlight

Accessibility

F6Moves focus to the toast stack from anywhere on the page.
TabMoves between the action and close buttons of the toasts.
EscapeCloses the focused toast.
Was this page helpful? · Edit this page on GitHub