Toast Primitive
Toast is a Starwind Runtime primitive in the notification-system contract family. Astro and React share one semantic component API. React coordinates reactive state through controlled and default props plus callbacks. Astro renders initial state and coordinates later changes through DOM events and Runtime methods. Raw HTML uses Runtime attributes, DOM events, and imperative methods.
Anatomy
Use the Astro primitive adapter to render Toast anatomy with the Runtime wiring included.
---import { Toast } from "@starwind-ui/astro/toast";---
<Toast.Viewport> <Toast.Root> <Toast.Content> <Toast.Title>Saved</Toast.Title> <Toast.Description>Your changes were saved.</Toast.Description> </Toast.Content> <Toast.Close>Dismiss</Toast.Close> </Toast.Root></Toast.Viewport>Use the React primitive adapter when Toast state participates in React rendering.
import { Toast } from "@starwind-ui/react/toast";
export function Example() { return ( <Toast.Viewport> <Toast.Root> <Toast.Content> <Toast.Title>Saved</Toast.Title> <Toast.Description>Your changes were saved.</Toast.Description> </Toast.Content> <Toast.Close>Dismiss</Toast.Close> </Toast.Root> </Toast.Viewport> );}Render the Toast data-sw-* contract yourself, then initialize createToastManager.
<div data-sw-toast-viewport role="region" aria-live="polite" aria-atomic="false" aria-relevant="additions text" aria-label="Notifications" tabindex="-1"> <div data-sw-toast-root> <div data-sw-toast-content> <div data-sw-toast-title>Saved</div> <div data-sw-toast-description>Your changes were saved.</div> </div> <button data-sw-toast-close type="button" aria-label="Close notification">Dismiss</button> </div></div>
<script type="module"> import { createToastManager } from "@starwind-ui/runtime/toast";
const root = document.querySelector("[data-sw-toast-viewport]"); if (root) { createToastManager(root); }</script>API Reference
Viewport
The visible viewport for Toast content.
- Default element
- div
- Discovery hook
- data-sw-toast-viewport
- Role
- region
Props
duration number 5000
- Description
- Configures the duration option for the Viewport part.
- Kind
- option
- Targets
- -
- Full type
- number
gap string "0.5rem"
- Description
- Configures the gap option for the Viewport part.
- Kind
- option
- Targets
- -
- Full type
- string
limit number 3
- Description
- Configures the limit option for the Viewport part.
- Kind
- option
- Targets
- -
- Full type
- number
peek string "1rem"
- Description
- Configures the peek option for the Viewport part.
- Kind
- option
- Targets
- -
- Full type
- string
position "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" "bottom-right"
- Description
- Configures the position option for the Viewport part.
- Kind
- option
- Targets
- -
- Full type
- "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right"
Data Attributes
Runtime hooks
Metadata
Template
Template markup used to create Toast items.
- Default element
- template
- Discovery hook
- data-sw-toast-template
- Role
- -
Props
variant "default" | "error" | "info" | "loading" | "success" | "warning" "default"
- Description
- Selects the visual variant for the Template part.
- Kind
- option
- Targets
- template, root
- Full type
- "default" | "error" | "info" | "loading" | "success" | "warning"
Data Attributes
Runtime hooks
Root
The main element that owns the Toast Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-toast-root
- Role
- -
Props
variant "default" | "error" | "info" | "loading" | "success" | "warning" "default"
- Description
- Selects the visual variant for the Root part.
- Kind
- option
- Targets
- template, root
- Full type
- "default" | "error" | "info" | "loading" | "success" | "warning"
Data Attributes
Runtime hooks
State
Metadata
Content
The content container rendered by Toast.
- Default element
- div
- Discovery hook
- data-sw-toast-content
- Role
- -
Data Attributes
Runtime hooks
Title
The accessible title for Toast.
- Default element
- div
- Discovery hook
- data-sw-toast-title
- Role
- -
Data Attributes
Runtime hooks
Title Text
Text content for the Toast title.
- Default element
- span
- Discovery hook
- data-sw-toast-title-text
- Role
- -
Data Attributes
Runtime hooks
Description
Supporting description text for Toast.
- Default element
- div
- Discovery hook
- data-sw-toast-description
- Role
- -
Data Attributes
Runtime hooks
Action
An optional action button shown inside Toast.
- Default element
- button
- Discovery hook
- data-sw-toast-action
- Role
- -
Data Attributes
Runtime hooks
Close
A control that closes Toast.
- Default element
- button
- Discovery hook
- data-sw-toast-close
- Role
- -
Data Attributes
Runtime hooks
Runtime API
- Factory
createToastManager- Import
@starwind-ui/runtime/toast- Root hook
- viewport
data-sw-toast-viewport - Option props
- -
Related Styled Components
Changelog
View version history v1.0.0 3 releases
v1.0.0
- Promoted this Primitive's vendoring version to the stable 1.0.0 baseline. Its existing API and Runtime behavior carry forward from the previous release.
v0.1.1
- Marked generated React Primitive files as client modules so vendored installs preserve client boundaries in React server frameworks.
v0.1.0
- Introduced the toast manager, templates, updates, dismissal, pause behavior, and notification lifecycle.