Toast
Non-blocking notification toasts with variants, actions, and auto-dismiss. Singleton manager accessible from anywhere.
import { getToastManager } from "phoundry-ui";Variants
Loading interactive example…
View source
<script lang="ts"> import { Button } from "phoundry-ui"; import { getToastManager } from "phoundry-ui";
const toast = getToastManager();</script>
<div class="flex flex-wrap items-center gap-2"> <Button variant="primary" onclick={() => toast.success("Changes saved")} >Success</Button > <Button variant="danger" onclick={() => toast.error("Something went wrong")} >Error</Button > <Button onclick={() => toast.warning("Storage almost full")}>Warning</Button> <Button onclick={() => toast.info("New version available")}>Info</Button></div>With Description
Loading interactive example…
View source
<script lang="ts"> import { Button } from "phoundry-ui"; import { getToastManager } from "phoundry-ui";
const toast = getToastManager();</script>
<Button onclick={() => toast.add({ message: "File uploaded", description: "report.pdf was uploaded successfully.", variant: "success", })}> Toast with Description</Button>With Action
Loading interactive example…
View source
<script lang="ts"> import { Button } from "phoundry-ui"; import { getToastManager } from "phoundry-ui";
const toast = getToastManager();</script>
<Button onclick={() => toast.add({ message: "Item deleted", action: { label: "Undo", onclick: () => toast.info("Undone!") }, })}> Toast with Action</Button>Stable ID (replace in place)
Loading interactive example…
View source
<script lang="ts"> import { Button } from "phoundry-ui"; import { getToastManager } from "phoundry-ui";
const toast = getToastManager();</script>
<div class="flex flex-wrap gap-2"> <Button size="sm" onclick={() => toast.add({ id: "demo-sync", message: "Saving…", duration: 0, dismissible: false, })} > Start save </Button> <Button size="sm" variant="primary" onclick={() => toast.add({ id: "demo-sync", message: "Saved", variant: "success", duration: 2500, })} > Finish save </Button></div>Persistent & clear
Loading interactive example…
View source
<script lang="ts"> import { Button } from "phoundry-ui"; import { getToastManager } from "phoundry-ui";
const toast = getToastManager();</script>
<div class="flex flex-wrap gap-2"> <Button size="sm" onclick={() => toast.add({ message: "Pinned - click ✕ to close", duration: 0 })} >Sticky toast</Button > <Button size="sm" variant="outline" onclick={() => toast.clear()} >Clear all</Button ></div>ToastOptions
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
messagerequired | string | — | Toast message text. |
id | string | undefined | — | Stable ID - posting another toast with the same ID replaces the previous one. |
variant | ToastVariant | undefined | — | Visual style. |
duration | number | undefined | — | Auto-dismiss time in ms. Set to 0 for persistent. |
description | string | undefined | — | Secondary text shown below the message. |
dismissible | boolean | undefined | — | Show a dismiss button. |
action | ToastAction | undefined | — | Action button displayed in the toast. |
ToastOverlay Props
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
position | ToastPosition | 'bottom-right' | Screen position for the toast stack. |
ToastManager
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
add | (options: ToastOptions) => string | — | Enqueue a toast; returns its ID. |
dismiss | (id: string) => void | — | Remove one toast by ID. |
clear | () => void | — | Remove every toast. |
toasts | ToastEntry[] | — | Reactive list for debugging or custom UI. |
success / error / warning / info: Shorthand variants of add().
Usage tips
- Pass
maxToaststosetupOverlaysor the firstgetToastManager(max)call - it only applies when the singleton is first created. getToastManager()returns a singleton - call it from any component or service after overlays are initialized.- Render
ToastOverlayonce in your root layout to display toasts. - Set
duration: 0for persistent toasts that require manual dismissal. - Use
manager.clear()to dismiss all active toasts at once.
CSS styling
.ph-toast-overlay is the stable identification hook for Toast. Part selectors and --_ph-* properties are internal. Component CSS is scoped and unlayered; Consumer classes remain additive and utility overrides may lose precedence.
Individual notifications use .ph-toast. Placement uses data-position, and notification variants use data-variant. Variant colors consume Theme tokens.
Keep the shared component stylesheet and a named Theme imported. Decorative motion respects reduced-motion preferences.