Toast

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

Overview

The Toast primitive provides consistent, styled notifications. Mount one <Toaster /> near the root of your app, then use the exported toast helper to trigger messages from anywhere.

Usage

import {
  toast,
  Toaster,
} from "@tilt-legal/cubitt-components/toast";
// 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

Basic

Variants

Semantic variants keep the same Cubitt surface treatment and apply semantic color to the icon and title.

With Description

Buttons

Toasts support action and cancel buttons. The action button follows Cubitt's default button treatment. The cancel and close buttons follow Cubitt's secondary button treatment.

Promise

API Reference

Toaster

Mount once near the root of your app to render toast notifications. Cubitt supplies the surface, border, shadow, and control styling; Sonner props remain available for behavior.

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.
richColorsbooleanfalseSonner rich color mode. Cubitt defaults to token-driven surfaces with semantic icon/title colors.
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"-Optional Sonner theme override. Cubitt surface tokens follow the app theme.
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-Sonner class name escape hatch. Not needed for normal Cubitt styling.

On this page