Toast
Short messages that stack at one edge of the screen and dismiss themselves.
<arc-toast>Overview
Toast shows short messages that don't block the page and dismiss themselves, such as "File saved" or "Back online". Place one <arc-toast> in your layout and call its show() method whenever a message should appear. Toasts stack at one corner or edge of the viewport, set by position, and span the full width below 640px.
max-visible (3 by default) caps how many are on screen. The rest wait in a queue, up to queue-limit, and appear as space frees up. Set max-visible="0" for no cap. Dedupe is on by default. Showing a message that matches a visible or queued toast of the same variant adds a "(×N)" counter to that toast and restarts its timer, in place, with no second toast. Set no-dedupe to turn it off.
To raise a toast without a reference to the element, dispatch an arc-toast event on document with the options show() takes.
For long-running work, pass a numeric progress to show(). The toast draws a track under its message, is never deduped and never dismisses on a timer, so two uploads with the same file name get two bars. Move the bar with updateToast(id, { progress }) and finish with complete(id). That dismisses the toast and fires arc-complete. complete is separate from dismiss so that code waiting for the work to finish doesn't run when the reader closes the toast. An onCancel callback turns the close button into a cancel button that fires arc-cancel. Progress mode is set at show() and can't be turned on later.
actionLabel adds a button for an undo or a retry. Clicking it runs the action callback, fires arc-action and dismisses the toast.
Guidelines
Do
- Place one `<arc-toast>` at the root of your layout so every page shares it
- Use `success` to confirm saves, uploads and deletions
- Keep messages to one sentence so readers finish before the toast goes
- Use `error` for failures that need acknowledging but not a blocking dialog
- Set `duration` to 0 for a message the reader must close
- Use progress mode for work with a known percentage, such as uploads, exports and batch jobs
- Give a progress toast `onCancel` only when the work can really be stopped
- Call `complete(id)` when the work finishes
Don't
- Don't use a toast for anything that needs a decision or input. Use Dialog, or Confirm for a yes or no
- Don't show passwords, tokens or other secrets. Anyone nearby can see them
- Don't set a duration under 2000ms. Readers may not finish the message
- Don't rely on color alone. The icon and the text must carry the meaning
- Don't fire one toast per item in a batch. Summarize the batch in one
- Don't use progress mode for work of unknown length. Use Spinner
- Don't leave a progress toast open after the work ends. It never dismisses itself, so call `complete(id)` or `dismiss(id)`
- Don't make an action button the only way to reach an irreversible action. The toast dismisses on its own
Features
- `show({ message, variant, duration })` returns the toast's id, and `dismiss(id)` removes it whether it's visible or queued
- `duration` defaults to 4000ms, and 0 keeps a toast until it's closed
- Positions: `top-right`, `top-left`, `top-center`, `bottom-right`, `bottom-left` and `bottom-center`
- Four variants (info, success, warning and error), each with an icon and a colored bottom edge
- `updateToast()` can change the message in the same call as the progress
- `arc-queue-change` reports the visible and queued counts, and `arc-queue-overflow` fires when the queue is full and the oldest waiting toast is dropped
- `arc-close` fires with the toast's id when it's removed
- The container has `role="status"` and `aria-live="polite"`, so screen readers announce new messages without moving focus
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<script type="module" src="@arclux/arc-ui"></script>
<arc-toast id="toaster" position="top-right"></arc-toast>
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
<arc-button variant="primary"
onclick="document.getElementById('toaster').show({ message: 'Changes saved successfully.', variant: 'success' })">
Success
</arc-button>
<arc-button variant="secondary"
onclick="document.getElementById('toaster').show({ message: 'Something went wrong.', variant: 'error' })">
Error
</arc-button>
<arc-button variant="ghost"
onclick="document.getElementById('toaster').show({ message: 'Deployment in progress...', variant: 'warning', duration: 6000 })">
Warning (6 s)
</arc-button>
<arc-button variant="ghost" onclick="upload()">Upload</arc-button>
</div>
<script>
// Progress mode: a numeric progress option renders the track. The toast then
// skips dedupe and never auto-dismisses — it ends when complete() says so.
async function upload() {
const toaster = document.getElementById('toaster');
const controller = new AbortController();
const id = toaster.show({
message: 'Uploading report.pdf…',
progress: 0,
onCancel: () => controller.abort(), // this is what renders the cancel button
});
try {
for (let sent = 0; sent <= 100; sent += 10) {
await sendChunk(sent, { signal: controller.signal });
toaster.updateToast(id, { progress: sent });
}
toaster.updateToast(id, { message: 'Uploaded report.pdf' });
toaster.complete(id); // dismisses and fires arc-complete
} catch {
toaster.dismiss(id);
toaster.show({ message: 'Upload failed.', variant: 'error' });
}
}
// Completion and cancellation are distinct events, so a listener can tell
// "the work finished" from "the user closed it".
document.getElementById('toaster').addEventListener('arc-complete', (e) => {
console.log('upload finished', e.detail.id);
});
</script>import { Toast, Button } from '@arclux/arc-ui-react';
import type { ArcToast } from '@arclux/arc-ui/toast';
import { useRef } from 'react';
export function NotificationDemo() {
// Typing the ref as ArcToast is what makes show()/updateToast()/complete()
// and the shape of the options object visible to TypeScript.
const toastRef = useRef<ArcToast>(null);
const showSuccess = () =>
toastRef.current?.show({ message: 'Changes saved successfully.', variant: 'success' });
const showError = () =>
toastRef.current?.show({ message: 'Something went wrong.', variant: 'error' });
// Progress mode. show() returns the id every later call needs, and the toast
// stays until complete() or dismiss() — there is no timer to race.
const upload = async () => {
const toaster = toastRef.current;
if (!toaster) return;
const controller = new AbortController();
const id = toaster.show({
message: 'Uploading report.pdf…',
progress: 0,
onCancel: () => controller.abort(),
});
for (let sent = 0; sent <= 100; sent += 10) {
await sendChunk(sent, { signal: controller.signal });
toaster.updateToast(id, { progress: sent });
}
toaster.complete(id);
};
return (
<>
<Toast ref={toastRef} position="top-right" />
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
<Button variant="primary" onClick={showSuccess}>Success</Button>
<Button variant="secondary" onClick={showError}>Error</Button>
<Button variant="ghost" onClick={upload}>Upload</Button>
</div>
</>
);
}<script setup>
import { ref } from 'vue';
import { Button, Toast } from '@arclux/arc-ui-vue';
const toaster = ref(null);
const showSuccess = () => toaster.value?.show({ message: 'Changes saved successfully.', variant: 'success' });
const showError = () => toaster.value?.show({ message: 'Something went wrong.', variant: 'error' });
</script>
<template>
<Toast ref="toaster" position="top-right" />
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
<Button variant="primary" @click="showSuccess">Success</Button>
<Button variant="secondary" @click="showError">Error</Button>
</div>
</template><script>
import { Button, Toast } from '@arclux/arc-ui-svelte';
let toaster;
const showSuccess = () => toaster?.show({ message: 'Changes saved successfully.', variant: 'success' });
const showError = () => toaster?.show({ message: 'Something went wrong.', variant: 'error' });
</script>
<Toast bind:this={toaster} position="top-right" />
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
<Button variant="primary" on:click={showSuccess}>Success</Button>
<Button variant="secondary" on:click={showError}>Error</Button>
</div>import { Component, ViewChild, ElementRef } from '@angular/core';
import { Button, Toast } from '@arclux/arc-ui-angular';
import type { ArcToast } from '@arclux/arc-ui/toast';
@Component({
imports: [Button, Toast],
template: `
<arc-toast #toaster position="top-right"></arc-toast>
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
<arc-button variant="primary" (click)="showSuccess()">Success</arc-button>
<arc-button variant="secondary" (click)="showError()">Error</arc-button>
</div>
`,
})
export class NotificationDemoComponent {
@ViewChild('toaster') toaster!: ElementRef<ArcToast>;
showSuccess() {
this.toaster.nativeElement.show({ message: 'Changes saved successfully.', variant: 'success' });
}
showError() {
this.toaster.nativeElement.show({ message: 'Something went wrong.', variant: 'error' });
}
}import { Button, Toast } from '@arclux/arc-ui-solid';
import type { ArcToast } from '@arclux/arc-ui/toast';
export function NotificationDemo() {
let toaster: ArcToast | undefined;
return (
<>
<Toast ref={toaster} position="top-right" />
<div style={{ display: 'flex', gap: '8px', 'flex-wrap': 'wrap' }}>
<Button variant="primary"
onClick={() => toaster?.show({ message: 'Changes saved successfully.', variant: 'success' })}>
Success
</Button>
<Button variant="secondary"
onClick={() => toaster?.show({ message: 'Something went wrong.', variant: 'error' })}>
Error
</Button>
</div>
</>
);
}import { Button, Toast } from '@arclux/arc-ui-preact';
import type { ArcToast } from '@arclux/arc-ui/toast';
import { useRef } from 'preact/hooks';
export function NotificationDemo() {
const toastRef = useRef<ArcToast>(null);
const showSuccess = () =>
toastRef.current?.show({ message: 'Changes saved successfully.', variant: 'success' });
const showError = () =>
toastRef.current?.show({ message: 'Something went wrong.', variant: 'error' });
return (
<>
<Toast ref={toastRef} position="top-right" />
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
<Button variant="primary" onClick={showSuccess}>Success</Button>
<Button variant="secondary" onClick={showError}>Error</Button>
</div>
</>
);
}API
durationnumber4000- Time in milliseconds before a toast auto-dismisses. Applies as the default for every show() call but can be overridden per-toast via the duration option in the show() payload. Set to 0 to disable auto-dismiss entirely, requiring the user to click the close button.
max-visiblenumber3- Maximum toasts on screen at once (attribute: max-visible). Further show() calls queue FIFO and release as visible toasts dismiss. Set to 0 for no cap.
position'top-right' | 'top-left' | 'top-center' | 'bottom-right' | 'bottom-left' | 'bottom-center''top-right'- Anchors the toast stack to a fixed edge of the viewport. Top-right is the most conventional position for web applications. Bottom positions work well for media players or editors where the top area is occupied by toolbars.
dedupebooleantrue- When true, a show() whose message and variant match a visible or queued toast is coalesced: the existing toast gains a "(×N)" counter and a fresh timer instead of a second toast appearing. Set the property to false from JS to disable.
queueLimitnumber20- Maximum queued (not visible) toasts (attribute: queue-limit). Beyond it the oldest queued entries are dropped and arc-queue-overflow fires with the drop count.
Methods
show(options?)options?: { id?: number|string, message?: string, variant?: 'info' | 'success' | 'warning' | 'error', duration?: number, persistent?: boolean, progress?: number, action?: () => void, actionLabel?: string, onCancel?: () => void }number|string- Show a toast, or coalesce it into an identical one that is already showing.
Passing
progressputs the toast in progress mode, absorbed from arc-progress-toast in 4.2: it renders a track beneath the message, exempts itself from dedupe and from the auto-dismiss timer, and, givenonCancel, offers a cancel button that firesarc-cancel. Move the bar withupdateToast(id, { progress })and end it withcomplete(id), which firesarc-complete. The mode is chosen here and is not switchable afterwards: a track appearing mid-life would relayout a notification the reader is already reading.actionandactionLabelarrive from arc-snackbar the same way. The label renders a ghost button; a click runs the callback and firesarc-actionbefore the toast dismisses. dismiss(id)id: number|string- Dismiss a toast by the id show() returned, whether it is visible or still queued. Unknown ids are ignored.
clear()- Dismiss everything on screen and discard the queue.
updateToast(id, changes)id: number|string, changes: { progress?: number, message?: string }- Move a progress toast's bar, its message, or both. Unknown ids are ignored,
matching dismiss().
Named
updateToastrather thanupdatebecauseupdateis Lit's. It is the name arc-progress-toast used, and the reason that component carried a do-nothingupdate(changedProps) { super.update(changedProps); }override that read as if it meant something. complete(id)id: number|string- Finish a progress toast: dismiss it and fire
arc-complete. Distinct fromdismiss()on purpose: the operation finishing and the user closing the toast are different events, and a consumer waiting on the first should not be woken by the second.
Events
arc-queue-overflow- Fired when the queue exceeds queueLimit and the oldest queued entries are dropped. detail: { dropped }.
arc-queue-change- Fired whenever the visible or queued count changes. detail: { visible, queued }.
arc-complete- Fired when a progress toast is completed with complete(id). detail: { id }.
arc-cancel- Fired when the user clicks a progress toast's cancel button. detail: { id }.
arc-action- Fired when the user clicks a toast's action button, before it dismisses. detail: { id }. Absorbed from arc-snackbar, whose action was reachable as an event as well as the
actioncallback; a callback cannot be attached declaratively. arc-close- Fired when a toast notification is dismissed. detail: { id }, the id show() returned.