Toast
Ephemeral notifications fired imperatively from anywhere — no context, no wiring.
"use client";
import { Button, HStack, Toaster, toast } from "astralis-ui";
export function ToastDemo() {
return (
<>
{/* Mount ONE Toaster near your app root — it catches toasts from anywhere. */}
<Toaster placement="bottom-end" />
<HStack gap="3" wrap="wrap">
<Button size="sm" colorScheme="blue" variant="subtle" onClick={() => toast.info("Heads up", { description: "A new version is available." })}>
Info
</Button>
<Button size="sm" colorScheme="green" variant="subtle" onClick={() => toast.success("Deploy complete", { description: "v0.2.0 is live." })}>
Success
</Button>
<Button size="sm" colorScheme="orange" variant="subtle" onClick={() => toast.warning("Approaching quota")}>
Warning
</Button>
<Button size="sm" colorScheme="red" variant="subtle" onClick={() => toast.error("Payment failed", { description: "Your card was declined." })}>
Error
</Button>
</HStack>
</>
);
}Import#
import { Toaster, toast } from "astralis-ui";Mount one <Toaster /> near your app root (inside AstralisProvider),
then call toast(...) from any event handler, effect, or async flow. The
store is module-level, so it works outside React trees too.
Options: actions, sticky toasts, dismiss#
"use client";
import { Button, HStack, toast } from "astralis-ui";
export function ToastOptions() {
return (
<HStack gap="3" wrap="wrap">
<Button
size="sm"
variant="outline"
onClick={() =>
toast({
title: "File deleted",
description: "report-final-v2.pdf was moved to trash.",
status: "info",
action: { label: "Undo", onClick: () => toast.success("Restored") },
})
}
>
With action
</Button>
<Button
size="sm"
variant="outline"
onClick={() =>
toast({
title: "Copies itself to your clipboard history",
duration: null,
status: "warning",
})
}
>
Sticky (duration: null)
</Button>
<Button size="sm" variant="text" colorScheme="gray" onClick={() => toast.dismiss()}>
Dismiss all
</Button>
</HStack>
);
}toast() API#
| Call | Returns | Description |
|---|---|---|
toast(options) | id | Full-control form. |
toast.info/success/warning/error(title, options?) | id | Status shorthands. |
toast.dismiss(id?) | — | Close one toast, or all when called with no id. |
Options#
| Option | Type | Default | Description |
|---|---|---|---|
title | ReactNode | — | Required headline. |
description | ReactNode | — | Supporting copy. |
status | "info" | "success" | "warning" | "error" | "info" | Icon, hue, ARIA role. |
colorScheme | all 11 schemes | from status | Hue override. |
duration | number | null | 5000 | Auto-dismiss ms; null keeps it until dismissed. Hovering pauses the timer. |
closable | boolean | true | Show the ✕ button. |
action | { label, onClick } | — | Action button after the text. |
<Toaster /> props#
| Prop | Type | Default | Description |
|---|---|---|---|
placement | "top-start" | "top-center" | "top-end" | "bottom-start" | "bottom-center" | "bottom-end" | "bottom-end" | Screen edge the stack grows from. |
max | number | 5 | Newest-first cap on visible toasts. |
Accessibility#
- Each toast renders
role="alert"(error/warning — assertive) orrole="status"(info/success — polite), inside a labelledrole="region"outlet. - Hover pauses the auto-dismiss timer and resumes with the remaining time, so slow readers aren't raced.