Skip to content
coatx
Esc
↑↓navigate↵open⌘Jpreview
On this page

Toast

Live stacked toast notifications with auto-dismiss, hover-to-pause, swipe dismissal, actions, and promise states.

Click any button to trigger a live toast.

    Usage

    Pair coatx/toast with @ilha/ui-sdk/toast for real viewport stacking, hover expansion, swipe-to-dismiss, Escape / F6 keyboard navigation, and toaster.promise(...):

    import {
      createToaster,
      Toast,
      ToastAction,
      ToastClose,
      ToastDescription,
      ToastRegion,
      ToastTitle,
    } from "@ilha/ui-sdk/toast";
    import { button } from "coatx/button";
    import {
      toast,
      toastAction,
      toastClose,
      toastDescription,
      toastRegion,
      toastTitle,
    } from "coatx/toast";
    
    const toaster = createToaster({ duration: 5000 });
    
    export const Notifications = () => (
      <>
        <button
          type="button"
          {...button({ variant: "outline" })}
          onclick={() =>
            toaster("Event created", {
              action: { label: "Undo", onAction: () => {} },
              description: "Sunday, December 3 at 9:00 AM",
            })
          }
        >
          Show Toast
        </button>
    
        <ToastRegion
          toaster={toaster}
          side="bottom"
          align="end"
          maxVisible={3}
          class={(s) => toastRegion({ expanded: s.expanded, stacked: true }).class}
        >
          {(_data, item) => (
            <Toast
              class={(s) =>
                toast({
                  expanded: s.expanded,
                  front: s.front,
                  leaving: s.leaving,
                  stacked: true,
                  variant: s.type,
                }).class
              }
            >
              <div>
                <ToastTitle {...toastTitle()} />
                <ToastDescription {...toastDescription()} />
              </div>
              {item.toast.action && <ToastAction {...toastAction()} />}
              <ToastClose aria-label="Dismiss" {...toastClose()}>
                ×
              </ToastClose>
            </Toast>
          )}
        </ToastRegion>
      </>
    );

    Exports (coatx/toast)

    Export Description
    toastRegion(options?) Viewport toast stack container (stacked, expanded)
    toast(options?) Notification card recipe (variant, stacked, front, expanded, leaving)
    toastTitle(options?) Heading slot
    toastDescription(options?) Body copy slot
    toastAction(options?) Inline action button
    toastClose(options?) Dismiss button
    toastStyles Compiled StyleX style map

    Options

    Option Type Default
    variant "default", "success", "info", "warning", "error", "destructive", "loading" "default"
    stacked boolean (enables depth-stacking CSS variables for @ilha/ui-sdk/toast) false
    front boolean (whether this toast is at index 0 when stacked) true
    expanded boolean (whether the stack is expanded on hover/focus) false
    leaving boolean (exit fade state) false

    Was this page helpful?