Skip to content

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
variants.svelte
<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
with-description.svelte
<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
with-action.svelte
<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
stable-id-replace-in-place.svelte
<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
persistent-clear.svelte
<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

NameTypeDefaultDescription
messagerequiredstring—Toast message text.
idstring | undefined—Stable ID - posting another toast with the same ID replaces the previous one.
variantToastVariant | undefined—Visual style.
durationnumber | undefined—Auto-dismiss time in ms. Set to 0 for persistent.
descriptionstring | undefined—Secondary text shown below the message.
dismissibleboolean | undefined—Show a dismiss button.
actionToastAction | undefined—Action button displayed in the toast.

ToastOverlay Props

From phoundry-ui@0.4.21

NameTypeDefaultDescription
positionToastPosition'bottom-right'Screen position for the toast stack.

ToastManager

From phoundry-ui@0.4.21

NameTypeDefaultDescription
add(options: ToastOptions) => string—Enqueue a toast; returns its ID.
dismiss(id: string) => void—Remove one toast by ID.
clear() => void—Remove every toast.
toastsToastEntry[]—Reactive list for debugging or custom UI.

success / error / warning / info: Shorthand variants of add().

Usage tips

  • Pass maxToasts to setupOverlays or the first getToastManager(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 ToastOverlay once in your root layout to display toasts.
  • Set duration: 0 for 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.

Documentation is licensed under CC BY 4.0. Phoundry names and marks remain reserved.