Toast Primitive
Toast is a Starwind Runtime primitive in the notification-system contract family.
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
Prop Type Default Toggle
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
Attribute Value Description
data-sw-toast-viewport - Marks the Viewport part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-position - Reflects the position prop on the Viewport part.
data-limit - Reflects the limit prop on the Viewport part.
data-duration - Reflects the duration prop on the Viewport part.
Template
Template markup used to create Toast items.
- Default element
- template
- Discovery hook
- data-sw-toast-template
- Role
- -
Props
Prop Type Default Toggle
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
Attribute Value Description
data-sw-toast-template - Marks the Template part so Starwind Runtime can find it.
Root
The main element that owns the Toast Runtime instance.
- Default element
- div
- Discovery hook
- data-sw-toast-root
- Role
- -
Props
Prop Type Default Toggle
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
Attribute Value Description
data-sw-toast-root - Marks the Root part so Starwind Runtime can find it.
data-toast-id - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-state - Reflects the current state on the Root part.
Metadata
Attribute Value Description
data-variant - Reflects the variant prop on the Root part.
Content
The content container rendered by Toast.
- Default element
- div
- Discovery hook
- data-sw-toast-content
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-toast-content - Marks the Content part so Starwind Runtime can find it.
Title
The accessible title for Toast.
- Default element
- div
- Discovery hook
- data-sw-toast-title
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-toast-title - Marks the Title part so Starwind Runtime can find it.
Title Text
Text content for the Toast title.
- Default element
- span
- Discovery hook
- data-sw-toast-title-text
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-toast-title-text - Marks the Title Text part so Starwind Runtime can find it.
Description
Supporting description text for Toast.
- Default element
- div
- Discovery hook
- data-sw-toast-description
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-toast-description - Marks the Description part so Starwind Runtime can find it.
Action
An optional action button shown inside Toast.
- Default element
- button
- Discovery hook
- data-sw-toast-action
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-toast-action - Marks the Action part so Starwind Runtime can find it.
Close
A control that closes Toast.
- Default element
- button
- Discovery hook
- data-sw-toast-close
- Role
- -
Data Attributes
Runtime hooks
Attribute Value Description
data-sw-toast-close - Marks the Close part so Starwind Runtime can find it.
Runtime API
- Factory
createToastManager- Import
@starwind-ui/runtime/toast- Root hook
- viewport
data-sw-toast-viewport - Option props
- -
Related Styled Components
Component Relationship
Toast Direct primitive