Skip to main content

Installation

npx @kuzenbo/cli add toast

Usage

import { ToastProvider, useToast } from "@kuzenbo/notifications";

function App() {
  return (
    <ToastProvider>
      <YourApp />
    </ToastProvider>
  );
}

function YourComponent() {
  const toast = useToast();

  return (
    <button onClick={() => toast.add({ title: "Toast notification" })}>
      Show Toast
    </button>
  );
}

Examples

Toast Types

Use semantic methods for different notification types.
const toast = useToast();

// Success toast
toast.success({
  title: "Success",
  description: "Your changes have been saved."
});

// Error toast
toast.error({
  title: "Error",
  description: "Something went wrong."
});

// Warning toast
toast.warning({
  title: "Warning",
  description: "Your trial is expiring soon."
});

// Info toast
toast.info({
  title: "Info",
  description: "This feature is in beta."
});

// Loading toast
toast.loading({
  title: "Loading",
  description: "Please wait..."
});

Promise Toast

Automatically handle loading, success, and error states.
const toast = useToast();

toast.promise(
  fetchData(),
  {
    loading: { title: "Fetching data..." },
    success: { title: "Data loaded successfully" },
    error: { title: "Failed to load data" }
  }
);

Update Toast

Update an existing toast programmatically.
const toast = useToast();

const toastId = toast.add({
  title: "Processing...",
  type: "loading"
});

// Later, update it
toast.update(toastId, {
  title: "Done!",
  type: "success"
});

Close Toast

Manually close a toast.
const toast = useToast();

const toastId = toast.add({ title: "Click to dismiss" });

// Close it
toast.close(toastId);

Stacked Toasts

Multiple toasts stack automatically.
const toast = useToast();

toast.add({ title: "First notification" });
toast.add({ title: "Second notification" });
toast.add({ title: "Third notification" });

Anchored Toasts

Position toasts relative to specific elements.
import { Toast } from "@kuzenbo/notifications";

<Toast.Root toast={toast}>
  <Toast.Positioner anchor={anchorRef}>
    <Toast.Content>
      <Toast.Title>Anchored toast</Toast.Title>
      <Toast.Description>Positioned near the trigger.</Toast.Description>
    </Toast.Content>
  </Toast.Positioner>
</Toast.Root>

Toast Sizes

Control toast size with the size prop.
const toast = useToast();

toast.add({
  title: "Small toast",
  size: "sm"
});

toast.add({
  title: "Large toast",
  size: "lg"
});

API Reference

useToast

Hook that returns toast manager methods.

Methods

add
(options: ToastOptions) => string
Add a new toast and return its ID.
success
(options: ToastOptions) => string
Add a success toast.
error
(options: ToastOptions) => string
Add an error toast.
warning
(options: ToastOptions) => string
Add a warning toast.
info
(options: ToastOptions) => string
Add an info toast.
loading
(options: ToastOptions) => string
Add a loading toast.
promise
<T>(promise: Promise<T>, options: PromiseOptions) => Promise<T>
Create a promise-based toast with loading, success, and error states.
update
(toastId: string, options: UpdateOptions) => void
Update an existing toast.
close
(toastId: string) => void
Close a specific toast.
toasts
readonly Toast[]
Array of all active toasts.

ToastProvider

size
UISize
default:"md"
Default size for all toasts.Options: "xs" | "sm" | "md" | "lg" | "xl"

Toast.Root

toast
Toast
required
Toast object from the toast manager.
size
UISize
default:"md"
Size of the toast.

Toast.Content

className
string
Additional CSS classes.

Toast.Title

className
string
Additional CSS classes.

Toast.Description

className
string
Additional CSS classes.

Toast.Action

Container for action buttons.
className
string
Additional CSS classes.

Toast.Close

Close button for dismissing toasts.
className
string
Additional CSS classes.

Accessibility

  • Toasts use ARIA live regions for screen reader announcements
  • Toasts can be dismissed with keyboard (Escape key)
  • Focus management preserves user context
  • Sufficient duration for users to read content
  • Color is not the only indicator of toast type

Best Practices

  • Use toasts for temporary, non-critical notifications
  • Don’t use toasts for critical errors requiring user action
  • Keep toast messages concise (1-2 lines)
  • Provide meaningful titles and descriptions
  • Set appropriate auto-dismiss durations
  • Limit the number of simultaneous toasts
  • Use promise toasts for async operations

Build docs developers (and LLMs) love