Toast
Brief notifications from anywhere with toast(), including promises and actions.
Brief notifications from anywhere with toast(), including promises and actions.
toast.success("Invoice sent", {
description: "Northwind will get it in a minute.",
});The same component at all four levels. Pick the one that fits your project; they share tokens, so they mix.
npm i junco @junco/tailwindimport { Toaster, toast } from "junco";
// Once, near the root of your app
<Toaster />
// Anywhere
toast("Saved");
toast.success("Invoice sent", { description: "Northwind will get it in a minute." });
toast.error("Couldn't save", { action: { label: "Retry", onClick: save } });
toast.promise(upload(), { loading: "Uploading…", success: "Uploaded", error: "Upload failed" });Each status has its own icon and words, so it never relies on color.
Shows a loading toast that turns into success or error when the promise settles.
Reuse an id to update a toast instead of stacking a new one.
toast(title, options?)#Also toast.success, .error, .warning, .info, .loading, .promise and .dismiss(id?). Returns the toast id.
descriptioniddurationactiondismissibleariaLabelonDismiss / onAutoClose| Prop | Type | Default |
|---|---|---|
descriptionSecond line of text. | ReactNode | – |
idReuse an id to update a toast in place. | string | number | – |
durationMs before it closes. Infinity keeps it open; loading toasts never auto-close. | number | Toaster's duration |
actionA button in the toast. It closes after onClick unless you call event.preventDefault(). | { label, onClick } | – |
dismissibleWhether close button, swipe and Esc can close it. | boolean | true |
ariaLabelText for screen readers when title or description aren't plain strings. | string | – |
onDismiss / onAutoCloseCalled when the user closes it, or when it times out. | (toast) => void | – |
Toaster#Render once near the root of your app.
positionvisibleToastsdurationexpandcloseButtonhotkeyclassNames| Prop | Type | Default |
|---|---|---|
positionWhere the stack sits. | "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" | "bottom-right" |
visibleToastsHow many show at once; older ones wait behind. | number | 3 |
durationDefault auto-close time in ms. | number | 5000 |
expandAlways show the full stack instead of collapsing it until hover or focus. | boolean | false |
closeButtonShow the × button on each toast. | boolean | true |
hotkeyKeys that move focus to the toasts. | string[] | ["altKey", "KeyT"] |
classNamesClass overrides for each part. | Partial<Record<slot, string>> | – |
| Key | Action |
|---|---|
| AltT | Moves focus to the newest toast. |
| Tab | Moves between toasts and their buttons. |
| Esc | Closes the focused toast. |