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.1 4 releases

v2.1.1

  • Vue Toaster now uses the spacing set through its gap and peek props.
  • Fixed toasts skipping their entrance animation or leaving incorrect spacing when updated immediately, including when a promise resolves.
  • Updated the Vue loading icon to match Astro and React.

v2.1.0

  • You can now import toast and its types from your local Toast component folder. This is the same import path as the styled parts.

v2.0.1

  • The default export in index.ts now has a name, ToastParts, so framework tools show a clear name.

v2.0.0

  • Toast now gets its behavior from Starwind Runtime. Runtime manages the list of toasts, templates, updates, closing, and when each toast shows and goes away.
  • See the Toast Primitive for the unstyled parts and the behavior API.
  • The styled component renders the Toaster. To show a toast from your code, import toast from @starwind-ui/astro/toast.