Skip to content
ComponentsMarkdown

Toast

Transient status notification delivered via an imperative toast() store and <Toaster /> viewport, built on Radix Toast.

Live example

Position:

    Props

    PropTypeDefaultDescription
    Toaster.position"bottom-right" | "top-right""bottom-right"Viewport corner on >=640px screens; collapses to full-width bottom-center or top-center on mobile.
    toast({ title })string—Primary notification heading.
    toast({ description })string—Optional secondary detail copy rendered at caption size.
    toast({ variant })"neutral" | "info" | "success" | "warning" | "destructive""neutral"Visual style and live-region politeness (destructive uses foreground/assertive).
    toast({ action }){ label: string; altText: string; onClick: () => void }—Optional action button; disables auto-dismiss so users never miss interactive actions.
    toast({ duration })number5000Auto-dismiss delay in milliseconds (paused on hover or focus; ignored when action is set).

    Sizes and tokens

    Tier / RoleTokenValue
    Viewport width & marginsm:w-[26rem] / p-4 / --z-toast384px toast width · 16px viewport margin · full-width on <640px · z-index 50
    Queue capacityMAX_VISIBLE_TOASTS3 visible max · FIFO queue for overflow · newest nearest edge
    Neutral & feedback surfacespopupSurface / alertVariants / --shadow-lgNeutral uses popover surface; feedback variants reuse Alert subtle tints and icons
    Motion--duration-262 / --duration-16216px edge slide + fade (262ms enter, 162ms exit); opacity-only under reduced motion

    States

    Code

    import { Button, Toaster, toast } from "@freshgemui/monoplinth";
    
    export function Example() {
      return (
        <>
          <Button
            onClick={() =>
              toast({
                title: "Tokens exported",
                description: "CSS variables written to tokens/theme.css.",
                variant: "success",
                action: {
                  label: "Undo",
                  altText: "Undo token export",
                  onClick: () => {},
                },
              })
            }
          >
            Export tokens
          </Button>
          <Toaster position="bottom-right" />
        </>
      );
    }

    Do and don't

    Do: Use Toast for brief, non-blocking feedback
    Confirm background saves, exports, or undoable actions without interrupting the user's current focus.
    Don't: Auto-dismiss toasts with actions
    Always keep action toasts open until the user acts or dismisses them (enforced automatically when action is provided).

    Accessibility

    • destructive toasts use Radix type="foreground" (assertive live region), while all other variants use type="background" (polite).
    • Press F8 to jump keyboard focus to the <Toaster /> viewport; timers pause automatically on hover and focus (WCAG 2.2.1).
    • Each toast renders at z-toast (50) with pointer-events-auto, keeping close and action buttons clickable even when a Dialog or Sheet is open.

    Rationale

    Capping visible toasts at three with a FIFO queue prevents viewport clutter, while reusing Alert variant tints and icons keeps semantic feedback consistent across inline and floating surfaces.