Skip to main content

Starwind UI v3.0 is now available! Migration guide

Toast imports

The local Toast component re-exports toast, so styled parts and imperative notifications use the same @/components/starwind/toast import path.

Installation

Usage

---
import { Button } from "@/components/starwind/button";
---
<div class="flex flex-wrap gap-2">
<Button variant="outline" id="toast-demo-default">Default</Button>
<Button variant="outline" id="toast-demo-success">Success</Button>
<Button variant="outline" id="toast-demo-error">Error</Button>
</div>
<script>
import { toast } from "@/components/starwind/toast";
document.getElementById("toast-demo-default")?.addEventListener("click", () => {
toast("Default Toast");
});
document.getElementById("toast-demo-success")?.addEventListener("click", () => {
toast.success("Success!", { description: "Your changes have been saved." });
});
document.getElementById("toast-demo-error")?.addEventListener("click", () => {
toast.error("Error", { description: "Something went wrong." });
});
</script>

Setup

Render Toaster once near the application root so notifications can appear from any route.

src/layouts/Layout.astro
---
import { Toaster } from "@/components/starwind/toast";
---
<!doctype html>
<html lang="en">
<head>
<!-- ... -->
</head>
<body>
<main>
<slot />
</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.

---
import { Button } from "@/components/starwind/button";
---
<Button id="show-toast">Show Toast</Button>
<script>
import { toast } from "@/components/starwind/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

View version history v2.1.0 3 releases

v2.1.0

  • Re-exported toast and its public types from the local Toast component barrel so imperative notifications and styled parts can use the same import path.

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.