Start here
  • InstallationAdd Nelumbo to a shadcn project
  • ThemingBrand accent, neutrals, dynamic color
  • Biology componentsSequences, maps, plates and trees
  • katalyx.bio

    Snackbar

    A brief message about something the app just did, with at most one action. It rises in from the bottom on a spring, waits while you hover it, and can be swiped away.

      Install

      npx shadcn@latest add @nelumbo/snackbar

      Message

      Short and in the past tense: what just happened. Gone after four seconds.

      With an action

      One action, usually Undo. It stays seven seconds so there's time to reach it, and F8 jumps to it from the keyboard.

      Weekly report
      Invoice #2024-118
      Design review notes

      Longer messages

      Two lines at most. When the text is long, the action moves below it.

      Persistent

      For something that needs reading, keep it until it's dismissed and add a close button. Errors can interrupt screen readers with urgent.

      Queue

      One at a time, as in Material: later messages wait their turn instead of piling up.

      Sonner-style API

      toast and Toaster are sonner's names for the same API, with its types, descriptions and promise toasts. Types add an icon; turn on rich colors (below) to tint them too.

      // Coming from shadcn's Sonner? Change the imports:- import { toast } from "sonner"- import { Toaster } from "@/components/ui/sonner"+ import { toast, Toaster } from "@/components/ui/snackbar"​toast.success("Changes saved")toast.error("Couldn't save", { description: "You're offline." })toast.promise(upload(), {  loading: "Uploading…",  success: (n) => `${n} photos uploaded`,  error: "Upload failed",})​// <Toaster /> stacks and takes richColors, like sonner's.// Differences: bottom positions only, a single action (no cancel), no toast.custom.

      Stack and colors

      Stack shows up to three at once like sonner: the newest in front, older ones tucked behind; hover or focus fans them out, and each keeps its own timer. Rich colors tint success, error, warning and info with their container colors. Both are host settings; Toaster stacks by default.

      <Snackbars />                       // one at a time (Material)<Snackbars stack richColors />      // sonner-style<Toaster />                         // stacks by default, like sonner<Toaster richColors visibleToasts={4} />​toast.error("Payment failed", { richColors: true })   // tint just this one

      Usage

      Mount the host once, near the root of your app. Above a navigation bar, pass offset so snackbars clear it.

      // app/layout.tsximport { Snackbars } from "@/components/ui/snackbar"​<body>  {children}  <Snackbars />               {/* or <Snackbars offset={80} /> above a navigation bar */}</body>​// anywhereimport { snackbar } from "@/components/ui/snackbar"​snackbar("Message archived", {  action: { label: "Undo", onClick: restore },})

      Options

      PropTypeDefaultNotes
      snackbar / toast(message, options?) => id.success .error .warning .info .loading .message .promise .dismiss
      descriptionReactNodeSecond line; the message reads as a title
      action{ label, onClick, altText? }One action; altText describes it for screen readers
      iconIconName | ReactNodeLeading icon; types set one
      idnumber | stringReuse to update a snackbar in place
      closable / closeButtonbooleanfalseClose button
      durationnumber (ms)4000, 7000 with an actionInfinity keeps it; loading stays until updated
      urgentbooleanfalse (true for errors)Announce assertively
      onDismiss / onAutoClose(id) => voidClosed by the person / by the timer
      richColorsbooleanPer snackbar: tint it with its type's color
      <Snackbars position>"bottom-center" | "bottom-start" | "bottom-end""bottom-center"Also bottom-left / bottom-right
      <Snackbars stack>booleanfalse (true on <Toaster>)Several at once, fanned out on hover
      <Snackbars visibleToasts>number3How many a stack shows
      <Snackbars richColors>booleanfalseTint success, error, warning and info
      <Snackbars offset>number (px)0Extra bottom space