Toast
--- 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 "@starwind-ui/astro/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>import { Button } from "@/components/starwind/button";import { toast } from "@starwind-ui/react/toast";
export function Example() { return ( <div className="flex flex-wrap gap-2"> <Button variant="outline" onClick={() => toast("Default Toast")}>Default</Button> <Button variant="outline" onClick={() => toast.success("Success!", { description: "Your changes have been saved." })}>Success</Button> <Button variant="outline" onClick={() => toast.error("Error", { description: "Something went wrong." })}>Error</Button> </div> );}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
pnpx starwind@latest add toastnpx starwind@latest add toastyarn dlx starwind@latest add toastFramework Availability
Astro Available React AvailableToast 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.
---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.
---import { Button } from "@/components/starwind/button";---
<div class="flex flex-wrap gap-2"> <Button variant="outline" id="toast-default">Default</Button> <Button variant="outline" id="toast-success">Success</Button> <Button variant="outline" id="toast-error">Error</Button> <Button variant="outline" id="toast-warning">Warning</Button> <Button variant="outline" id="toast-info">Info</Button> <Button variant="outline" id="toast-loading">Loading</Button></div>
<script> import { toast } from "@starwind-ui/astro/toast";
document.getElementById("toast-default")?.addEventListener("click", () => { toast("Default Toast"); });
document.getElementById("toast-success")?.addEventListener("click", () => { toast.success("Success!", { description: "Your changes have been saved.", }); });
document.getElementById("toast-error")?.addEventListener("click", () => { toast.error("Error", { description: "Something went wrong.", }); });
document.getElementById("toast-warning")?.addEventListener("click", () => { toast.warning("Warning", { description: "Please review your input.", }); });
document.getElementById("toast-info")?.addEventListener("click", () => { toast.info("Info", { description: "Here's some helpful information.", }); });
document.getElementById("toast-loading")?.addEventListener("click", () => { toast.loading("Loading...", { description: "Please wait while we process your request.", }); });</script>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.
---import { Button } from "@/components/starwind/button";---
<div class="flex flex-wrap gap-2"> <Button variant="primary" id="toast-promise-success">Promise (Success)</Button> <Button variant="error" id="toast-promise-error">Promise (Error)</Button></div>
<script> import { toast } from "@starwind-ui/astro/toast";
document.getElementById("toast-promise-success")?.addEventListener("click", () => { const fakeApiCall = async () => { await new Promise((resolve) => setTimeout(resolve, 2000)); return { name: "John" }; };
toast.promise(fakeApiCall(), { loading: { title: "Saving...", description: "Please wait" }, success: (data) => ({ title: "Saved!", description: `Welcome, ${data.name}!` }), error: { title: "Error", description: "Failed to save" }, }); });
document.getElementById("toast-promise-error")?.addEventListener("click", () => { const fakeApiCall = async () => { await new Promise((resolve) => setTimeout(resolve, 2000)); throw new Error("Network error"); };
toast .promise(fakeApiCall(), { loading: "Processing...", success: "Done!", error: (err) => ({ title: err.message || "Contact support for assistance", description: "Pardon our dust while we fix this issue.", }), }) .catch(() => {}); });</script>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.
---import { Button } from "@/components/starwind/button";---
<div class="flex flex-wrap gap-2"> <Button variant="outline" id="toast-update">Create & Update</Button> <Button variant="outline" id="toast-dismiss-all">Dismiss All</Button></div>
<script> import { toast } from "@starwind-ui/astro/toast";
document.getElementById("toast-update")?.addEventListener("click", () => { const id = toast("Processing...", { description: "Step 1 of 3" });
setTimeout(() => { toast.update(id, { title: "Still working...", description: "Step 2 of 3" }); }, 1500);
setTimeout(() => { toast.update(id, { title: "Complete!", description: "All steps finished", variant: "success", }); }, 3000); });
document.getElementById("toast-dismiss-all")?.addEventListener("click", () => { toast.dismiss(); });</script>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:
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:
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:
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:
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
createToastManagerfrom@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.