Skip to main content
196

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Web docs
FeedbackGlass surface

Toast

Displays temporary feedback for background actions.

FrameworksAstro · React · Elements

Registry commandlumen add Toast

InteractionEnhanced runtime

01

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.

AstroCode target · live preview uses Astro
Common feedback
Interactive patterns
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.
astro
---
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>
Edit Toast in browser

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.

02

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.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add Toast
lumen add Toast

Glass

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.

AstroCode target · live preview uses Astro
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.
astro
---
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>
Edit Toast in browser

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.

AttributeValuesDefaultDescription
glassboolean | "subtle" | "strong"falseApplies 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.
maxnumber5Limits 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, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML 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.

KeyAction
Escape in a toastDismiss the focused toast.

Runtime events

CustomEvents dispatched by the Astro UIPrimitives runtime for this component.

EventTargetDetailWhen
ui:toastDocument{ 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-updateDocument{ 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-dismissDocument{ id?: string }Dismisses one programmatic toast by id, or all runtime toasts when id is omitted.
ui:toast-actionToast ([data-ui-toast]){ id: string, value?: unknown }Fires after a programmatic toast action button is pressed unless the action specifies a custom event name.

Web docsFull catalog