Skip to Content

Toast

Brief messages that stack in a corner and clear on their own.

    import { Toaster, toast } from "@dapplelight/signet-ui/components/toast"
    import { Button } from "@dapplelight/signet-ui/components/button"
    
    export function Demo() {
      return (
        <>
          <Toaster />
          <Button variant="outline" onClick={() => toast("Invoice INV-1042 sent")}>
            Send invoice
          </Button>
        </>
      )
    }

    Installation

    npm i @dapplelight/signet-ui

    Usage

    import { Toaster, toast } from "@dapplelight/signet-ui/components/toast"
    
    // Mount once near the app root
    <Toaster />
    
    // Call from anywhere
    toast("Invoice sent")

    Examples

    Types

    import { Toaster, toast } from "@dapplelight/signet-ui/components/toast"
    import { Button } from "@dapplelight/signet-ui/components/button"
    
    export function Demo() {
      return (
        <div className="flex flex-wrap gap-2">
          <Button variant="outline" onClick={() => toast.success("Payment received")}>Success</Button>
          <Button variant="outline" onClick={() => toast.info("3 orders shipped today")}>Info</Button>
          <Button variant="outline" onClick={() => toast.warning("Card expires next month")}>Warning</Button>
          <Button variant="outline" onClick={() => toast.error("Could not reach the bank")}>Error</Button>
        </div>
      )
    }

    Description and action

    import { Toaster, toast } from "@dapplelight/signet-ui/components/toast"
    import { Button } from "@dapplelight/signet-ui/components/button"
    
    export function Demo() {
      return (
        <Button
          variant="outline"
          onClick={() =>
            toast("Order #1042 archived", {
              description: "It moves out of your active list.",
              action: { label: "Undo", onClick: () => toast.success("Order restored") },
              cancel: { label: "Dismiss" },
            })
          }
        >
          Archive order
        </Button>
      )
    }

    Promise

    import { Toaster, toast } from "@dapplelight/signet-ui/components/toast"
    import { Button } from "@dapplelight/signet-ui/components/button"
    
    export function Demo() {
      return (
        <Button
          variant="outline"
          onClick={() =>
            toast.promise(new Promise((resolve) => setTimeout(resolve, 1500)), {
              loading: "Exporting orders...",
              success: "Export ready",
              error: "Export failed",
            })
          }
        >
          Export orders
        </Button>
      )
    }

    API Reference

    Toaster

    PropTypeDefaultDescription
    position"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""bottom-right"Where the stack sits. Left and right follow the writing direction.
    expandbooleanhover and focusKeep the stack expanded.
    visibleToastsnumber3How many show at once; the rest wait.
    closeButtonbooleanfalseShow a close button on dismissible toasts.
    labelstring"Notifications"Region name for screen readers.
    closeLabelstring"Close"Accessible name of the close button.
    pendingAnnouncementstring-What screen readers hear while a slow action runs.
    hotkeystring | null"F6"Key that moves focus into the region and back. null turns it off.
    classNamestring-Merged onto the region.
    classNamesPartial<Record<"toast" | "icon" | "content" | "title" | "description" | "action" | "cancel" | "close", string>>{}Classes for each part of every toast.

    toast(message, options?) returns the toast id. Variants: toast.success, toast.info, toast.warning, toast.error, toast.loading, toast.promise(promise, messages, options?) and toast.dismiss(id?). The API mirrors sonner.

    ToastOptions

    PropTypeDefaultDescription
    idstring-Reuse an id to update a toast that is still showing.
    descriptionReactNode-Second line.
    durationnumber5000Milliseconds. Infinity keeps it until dismissed.
    dismissiblebooleantrueWhether swipe, Escape and the close button can dismiss it.
    action{ label: ReactNode; onClick: () => unknown }-A button such as Undo. A returned Promise keeps the toast open until it settles.
    cancel{ label: ReactNode; onClick?: () => void }-A second button that only dismisses.
    onDismiss() => void-Called when it is dismissed.