Skip to main content

Starwind UI v3.0 is now available! Migration guide

Runtime adjustment

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

Installation

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>

Variants

The toast system supports multiple variants for different message types.

Promise Toast

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

Updating & Dismissing

You can update existing toasts or dismiss them programmatically.

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. 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.1

  • Named the generated aggregate default export so React and Astro tooling can identify the installed component cleanly.

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.
  • The styled package supplies the Toaster markup, while imperative notifications now come from the framework primitive entrypoint: @starwind-ui/astro/toast.