121
GitHub
Feedback

Sonner

Provides the toast viewport for notifications.

FrameworksAstro · React · Elements

Registry commandlumen add Sonner

InteractionEnhanced runtime

01

See it in context

Preview

02

Copy a working example

Usage

Astro examples assume UIPrimitives is mounted once in your root layout. Do not add the runtime next to each component instance.

astro
---
import {
  Button,
  Sonner
} from '@santi020k/lumen-astro'
---

<Sonner aria-label="Notifications" />
<Button variant="outline" data-ex-toast-trigger>Show toast</Button>

<script>
  document.querySelector('[data-ex-toast-trigger]')?.addEventListener('click', () => {
    document.dispatchEvent(new CustomEvent('ui:toast', {
      detail: { description: 'Your changes are live.', title: 'Saved', variant: 'success' }
    }))
  })
</script>
---
import {
  Button,
  Sonner
} from '@santi020k/lumen-astro'
---

<Sonner aria-label="Notifications" />
<Button variant="outline" data-ex-toast-trigger>Show toast</Button>

<script>
  document.querySelector('[data-ex-toast-trigger]')?.addEventListener('click', () => {
    document.dispatchEvent(new CustomEvent('ui:toast', {
      detail: { description: 'Your changes are live.', title: 'Saved', variant: 'success' }
    }))
  })
</script>
03

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 Sonner
lumen add Sonner

API reference

Lumen-specific props and runtime attributes for the Astro primitive. React props follow the same names; Elements use equivalent kebab-case attributes where custom elements expose them.

AttributeValuesDefaultDescription
placement"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""bottom-right"Positions the toast viewport.
maxCountnumber-Limits the number of runtime toasts kept in the viewport. The runtime default is 5 when omitted.
aria-atomicARIA boolean string"false"Sets the live-region atomicity attribute.
aria-live"off" | "polite" | "assertive""polite"Sets the live-region announcement priority.
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.

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 Sonner 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.