Toast

Contextual notifications for background work, confirmations, and quick feedback.

Overview

The Toast primitive provides consistent, styled notifications. Use the exported toast helper to trigger messages and mount a single <Toaster /> once near the root of your app.

Usage

import { toast, Toaster } from "@tilt-legal/cubitt-components/primitives";
// Mount Toaster once near the root of your app
export function AppLayout({ children }: { children: React.ReactNode }) {
  return (
    <>
      {children}
      <Toaster />
    </>
  );
}
// Trigger a toast from anywhere
toast("Settings saved");

toast.success("Saved with description", {
  description: "We updated your preferences.",
});

toast.error("Something went wrong");
toast.warning("Please review before continuing");
toast.info("New update available");

Examples

Variants

With Description

Buttons

Toasts support action (primary) and cancel (secondary) buttons. For a close button (X), pass closeButton to the <Toaster />.

Promise

API Reference

Toaster

Mount once near the root of your app to render toast notifications.

PropTypeDefaultDescription
position"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""bottom-right"Position of toasts on screen.
durationnumber4000Default duration in ms before toasts auto-dismiss.
closeButtonbooleanfalseShow close button on all toasts.
richColorsbooleanfalseUse richer colors for different toast types.
expandbooleanfalseExpand toasts by default.
visibleToastsnumber3Maximum number of visible toasts.
offsetstring | number-Offset from the edges of the screen.
dir"ltr" | "rtl" | "auto""auto"Text direction.
hotkeystring[]["altKey", "KeyT"]Keyboard shortcut to focus toasts.
theme"light" | "dark" | "system""light"Color theme for toasts.
gapnumber14Gap between toasts in pixels.

toast()

Function to trigger toast notifications. Returns a toast ID that can be used to dismiss or update the toast.

const toastId = toast("Message");
toast.dismiss(toastId);

Methods

MethodDescription
toast(message, options?)Show a default toast.
toast.success(message, options?)Show a success toast.
toast.error(message, options?)Show an error toast.
toast.warning(message, options?)Show a warning toast.
toast.info(message, options?)Show an info toast.
toast.loading(message, options?)Show a loading toast.
toast.promise(promise, options)Show loading/success/error based on promise state.
toast.dismiss(toastId?)Dismiss a specific toast or all toasts.

Options

PropTypeDefaultDescription
descriptionstring | ReactNode-Secondary text below the main message.
durationnumber4000Duration in ms before auto-dismiss. Use Infinity to persist.
positionPosition-Override the default position for this toast.
action{ label: string, onClick: () => void }-Primary action button.
cancel{ label: string, onClick: () => void }-Secondary/cancel button.
idstring | number-Custom ID for the toast. Useful for updating or preventing duplicates.
onDismiss(toast) => void-Callback when toast is dismissed.
onAutoClose(toast) => void-Callback when toast auto-closes.
dismissiblebooleantrueWhether the toast can be dismissed by swiping.
iconReactNode-Custom icon to display.
classNamesobject-Custom class names for toast parts.

On this page