Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

Runtime example adjustment

The styled package supplies the Toaster markup, while imperative notifications now come from the framework primitive entrypoint: @starwind-ui/astro/toast.

Installation

Framework Availability

Astro Available React Available

Toast is available for Astro and React.

Usage

Setup

The Toaster component must be added once to your page, usually in a common layout file shared between pages so you can trigger toasts from anywhere.

src/layouts/Layout.astro
---
import { Toaster } from "@/components/starwind/toast";
---
<!doctype html>
<html lang="en">
<head>
<!-- ... -->
</head>
<body>
<!-- navigation -->
<main>
<!-- content -->
</main>
<Toaster position="bottom-right" />
</body>
</html>

Basic Usage

Toasts are created using the toast function. Import it in a <script> tag and call it to show notifications.

<Button id="show-toast">Show Toast</Button>
<script>
import { toast } from "@starwind-ui/astro/toast";
document.getElementById("show-toast")?.addEventListener("click", () => {
toast("Hello world!");
});
</script>

Runtime example adjustment

Import toast from @starwind-ui/astro/toast; the CLI-installed styled folder no longer ships a separate toast manager.

Variants

The toast system supports multiple variants for different message types.

Runtime example adjustment

Variant helpers are provided by the Runtime toast API imported from @starwind-ui/astro/toast and rendered by the installed Toaster templates.

Promise Toast

Handle async operations with automatic loading, success, and error states.

Runtime example adjustment

Promise lifecycle updates now use the shared Runtime toast manager from the Astro primitive package.

Updating & Dismissing

You can update existing toasts or dismiss them programmatically.

Runtime example adjustment

Updating and dismissing notifications uses the shared Runtime toast API rather than the removed component-local manager.

API Reference

Styled Component API

These props are added or materially changed by the installed Astro styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Follow the Primitive and Runtime links for lower-level behavior props.

Toast

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
gap string "0.5rem"
Description
Sets the space between repeated items.
Classification
Wrapper prop
peek string "1rem"
Description
Sets how much of an adjacent item remains visible.
Classification
Wrapper prop

Toast Item

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
variant "default" | "success" | "error" | "warning" | "info" "default"
Description
Selects the component's visual variant.
Classification
Styled variant

Toast Title

Inherits div attributes.

Contains the following additional props:

Prop Type Default Toggle details
variant "default" | "success" | "error" | "warning" | "info" | "loading" "default"
Description
Selects the component's visual variant.
Classification
Styled variant

Toast Close

Inherits button attributes.

Contains the following additional props:

Prop Type Default Toggle details
showIcon boolean true
Description
Shows the component's generated icon.
Classification
Wrapper prop

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Toast.

Primitive API

Runtime API

Toast primitive
createToastManager from @starwind-ui/runtime/toast

Changelog

v2.0.0

  • Rebuilt Toast on Starwind Runtime for manager state, templates, updates, dismissal, and lifecycle.
  • See the Toast Primitive for the underlying unstyled anatomy and behavior API.