Toast
Displays temporary feedback for background actions.
See it and copy it
Framework example
Choose Astro, React, or Elements to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.
View Toast code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. React and Elements use their own behavior APIs; complete the matching framework setup before copying an example.---
import {
Button,
Toast
} from '@santi020k/lumen-astro'
---
<lumen-toast-demo style="display: block;">
<div style="display: grid; gap: 1.25rem;">
<div>
<strong style="display: block; margin-bottom: 0.625rem;">Common feedback</strong>
<div style="display: flex; flex-wrap: wrap; gap: 0.75rem;">
<Button data-ex-toast="default" variant="outline">Default</Button>
<Button data-ex-toast="success">Success</Button>
<Button data-ex-toast="warning" variant="secondary">Warning</Button>
<Button data-ex-toast="error" variant="destructive">Error</Button>
</div>
</div>
<div>
<strong style="display: block; margin-bottom: 0.625rem;">Interactive patterns</strong>
<div style="display: flex; flex-wrap: wrap; gap: 0.75rem;">
<Button data-ex-toast="action" variant="outline">With action</Button>
<Button data-ex-toast="progress" variant="secondary">Loading → success</Button>
<Button data-ex-toast="dismiss" variant="ghost">Dismiss all</Button>
</div>
</div>
</div>
<div style="display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem;">
<Toast style="min-width: min(100%, 18rem);">
<strong>Static toast</strong>
<p>Useful when feedback already exists in the page markup.</p>
</Toast>
<Toast variant="success" style="min-width: min(100%, 18rem);">
<strong>Changes saved</strong>
<p>Static Toast markup remains readable without JavaScript.</p>
</Toast>
</div>
</lumen-toast-demo>
<script>
class LumenToastDemo extends HTMLElement {
connectedCallback() {
if (this.dataset.ready) return
this.dataset.ready = 'true'
const lumenWindow = window as Window & {
LumenToast?: {
create: (detail: Record<string, unknown>) => string
dismiss: (id?: string) => void
update: (id: string, detail: Record<string, unknown>) => void
}
}
const createToast = (detail: Record<string, unknown>) => lumenWindow.LumenToast?.create(detail)
const showToast = (type: string | null): void => {
switch (type) {
case 'default': {
createToast({
description: 'Your draft is ready to keep editing.',
title: 'Draft saved'
})
break
}
case 'success': {
createToast({
description: 'The latest version is now live.',
title: 'Published',
variant: 'success'
})
break
}
case 'warning': {
createToast({
description: 'We will keep retrying in the background.',
title: 'Connection interrupted',
variant: 'warning'
})
break
}
case 'error': {
createToast({
description: 'Check the required fields and try again.',
title: 'Could not save changes',
variant: 'destructive'
})
break
}
case 'action': {
createToast({
action: { label: 'Undo', value: 'deploy' },
description: 'lumen-docs was moved to production.',
duration: 8000,
title: 'Deployment complete',
variant: 'success'
})
break
}
case 'progress': {
const toastId = createToast({
description: 'Preparing the production bundle.',
duration: 10000,
title: 'Deploying…'
})
if (!toastId) return
window.setTimeout(() => {
lumenWindow.LumenToast?.update(toastId, {
description: 'The production bundle is live.',
duration: 4000,
title: 'Deployment complete',
variant: 'success'
})
}, 1600)
break
}
case 'dismiss': {
lumenWindow.LumenToast?.dismiss()
break
}
// No default
}
}
this.addEventListener('click', event => {
if (!(event.target instanceof Element)) return
const button = event.target.closest('[data-ex-toast]')
if (button) showToast(button.getAttribute('data-ex-toast'))
})
}
}
if (!customElements.get('lumen-toast-demo')) {
customElements.define('lumen-toast-demo', LumenToastDemo)
}
</script>'use client'
import { Button, ToastProvider, useToast } from '@santi020k/lumen-react'
function SaveButton() {
const toast = useToast()
return (
<Button onClick={() => toast.create({ title: 'Preview saved', description: 'Example feedback; no data is persisted.', variant: 'success' })}>
Show success toast
</Button>
)
}
export const Example = () => (
<ToastProvider placement="bottom-right" maxCount={5}>
<SaveButton />
</ToastProvider>
)<lumen-button id="show-preview-toast">Show success toast</lumen-button>
<lumen-toast variant="success">
<strong>Static feedback</strong>
<p>This message remains readable without JavaScript.</p>
</lumen-toast>
<script type="module">
import { defineLumenElements, LumenToast } from '@santi020k/lumen-elements'
defineLumenElements()
document.getElementById('show-preview-toast')?.addEventListener('click', () => {
LumenToast.create({
title: 'Preview saved',
description: 'Example feedback; no data is persisted.',
variant: 'success'
})
})
</script>Framework differences
React: Wrap the application with ToastProvider and call useToast inside that provider. The Astro global LumenToast API is not used in React.
Elements: Register the elements and call the exported LumenToast API from your event handler. The Elements example includes its own button listener; the Astro demo controller is not required.
Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astropnpm add @santi020k/lumen-astrolumen add Toastlumen add Toastpnpm add @santi020k/lumen-reactpnpm add @santi020k/lumen-reactlumen add Toast --target reactlumen add Toast --target reactpnpm add @santi020k/lumen-elementspnpm add @santi020k/lumen-elementslumen add Toast --target elementslumen add Toast --target elementsGlass
Add the glass prop to apply the shared blur, saturation, border, and highlight tokens. Glass reads best over vivid content, so place the surface above imagery or color.
View Toast code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. React and Elements use their own behavior APIs; complete the matching framework setup before copying an example.---
import { Toast } from '@santi020k/lumen-astro'
---
<div class="docs-glass-demo docs-glass-demo--stack" style="justify-items: center;">
<Toast glass style="min-width: min(100%, 20rem);">
<strong>Build complete</strong>
<p>The glass toast floats over content with a slightly stronger fill for readability.</p>
</Toast>
<Toast variant="success" glass style="min-width: min(100%, 20rem);">
<strong>Published</strong>
<p>Status tints layer on top of the frosted surface.</p>
</Toast>
</div>'use client'
import { Button, ToastProvider, useToast } from '@santi020k/lumen-react'
function SaveButton() {
const toast = useToast()
return (
<Button onClick={() => toast.create({ title: 'Preview saved', description: 'Example feedback; no data is persisted.', variant: 'success' })}>
Show success toast
</Button>
)
}
export const Example = () => (
<ToastProvider placement="bottom-right" maxCount={5}>
<SaveButton />
</ToastProvider>
)<lumen-button id="show-preview-toast">Show success toast</lumen-button>
<lumen-toast variant="success">
<strong>Static feedback</strong>
<p>This message remains readable without JavaScript.</p>
</lumen-toast>
<script type="module">
import { defineLumenElements, LumenToast } from '@santi020k/lumen-elements'
defineLumenElements()
document.getElementById('show-preview-toast')?.addEventListener('click', () => {
LumenToast.create({
title: 'Preview saved',
description: 'Example feedback; no data is persisted.',
variant: 'success'
})
})
</script>API reference
Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.
| Attribute | Values | Default | Description |
|---|---|---|---|
| glass | boolean | "subtle" | "strong" | false | Applies the tokenized liquid-glass surface treatment with backdrop-filter fallbacks; "subtle" and "strong" adjust the fill intensity. |
| variant | "default" | "destructive" | "success" | "warning" | "default" | Controls the toast tone. |
| placement | "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" | "bottom-right" | Positions the notification viewport used for programmatic toasts. |
| max | number | 5 | Limits the number of runtime toasts kept in the notification viewport. |
| window.LumenToast.create(detail) | function | - | Creates a runtime toast and returns its id. Also available through document ui:toast. |
| window.LumenToast.update(id, detail) | function | - | Updates the title, description, variant, action, or duration for a runtime toast. |
| window.LumenToast.dismiss(id?) | function | - | Dismisses one runtime toast, or all runtime toasts when id is omitted. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Keyboard interactions
Keyboard behavior provided by the Astro UIPrimitives runtime for this component.
| Key | Action |
|---|---|
| Escape in a toast | Dismiss the focused toast. |
Runtime events
CustomEvents dispatched by the Astro UIPrimitives runtime for this component.
| Event | Target | Detail | When |
|---|---|---|---|
| ui:toast | Document | { id?: string, title?: string, description?: string, variant?: string, duration?: number, placement?: string, action?: { label: string } } | Creates a programmatic toast in the matching notification viewport. |
| ui:toast-update | Document | { id: string, title?: string, description?: string, variant?: string, duration?: number } | Updates a programmatic toast created by ui:toast or window.LumenToast.create(detail). |
| ui:toast-dismiss | Document | { id?: string } | Dismisses one programmatic toast by id, or all runtime toasts when id is omitted. |
| ui:toast-action | Toast ([data-ui-toast]) | { id: string, value?: unknown } | Fires after a programmatic toast action button is pressed unless the action specifies a custom event name. |