Unified UI

Sonner

Stacked toast notification system with promise/loading states, built on the sonner library with Unified UI styling.

Basic

Stacked toast notification system with promise/loading states, built on the sonner library with Unified UI styling. Trigger toasts from anywhere using the toast() function.

Installation

Install the component via the CLI in one command.

npx @work-rjkashyap/unified-ui add sonner
pnpm dlx @work-rjkashyap/unified-ui add sonner
npx @work-rjkashyap/unified-ui add sonner
bunx @work-rjkashyap/unified-ui add sonner

If you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.

Or install the full package

Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.

npm install @work-rjkashyap/unified-ui
pnpm add @work-rjkashyap/unified-ui
yarn add @work-rjkashyap/unified-ui
bun add @work-rjkashyap/unified-ui

Anatomy

import { SonnerToaster } from "@work-rjkashyap/unified-ui";

Setup

Place <SonnerToaster /> once in your root layout:

// app/layout.tsx
import { SonnerToaster } from "@work-rjkashyap/unified-ui";

export default function RootLayout({ children }) {
	return (
		<html>
			<body>
				{children}
				<SonnerToaster />
			</body>
		</html>
	);
}

Examples

Basic Toasts

With Description

With Action

Promise-Based

Loading Toast

Custom Duration

Custom JSX


Props (SonnerToaster)

PropTypeDefaultDescription
position"top-left" | "top-center" | ... | "bottom-right""bottom-right"Toast stack position.
richColorsbooleantrueUse distinct colors per toast type.
closeButtonbooleantrueShow close button on each toast.
durationnumber4000Auto-dismiss duration in ms.
visibleToastsnumber3Max visible toasts at once.
expandbooleantrueExpand toast stack on hover.
theme"light" | "dark" | "system""system"Theme override.
offsetnumber | string16Offset from viewport edge.
gapnumber14Gap between toasts.
toastOptionsobjectCustom class names for toast elements.
classNamestringAdditional CSS classes on container.

toast() API

MethodDescription
toast(message)Default toast.
toast.success()Success toast with green styling.
toast.error()Error toast with red styling.
toast.warning()Warning toast with amber styling.
toast.info()Info toast with blue styling.
toast.loading()Persistent loading toast with spinner.
toast.promise()Promise-based with loading/success/error.
toast.custom()Render custom JSX.
toast.dismiss()Dismiss a toast by ID.

Toast Options

OptionTypeDescription
descriptionstringBody text below the title.
durationnumberOverride auto-dismiss duration.
action{ label: string, onClick: () => void }Action button config.
cancel{ label: string, onClick: () => void }Cancel button config.
idstring | numberCustom toast ID for updates.
iconReactNodeCustom icon.
onDismiss() => voidCallback when toast dismisses.

Accessibility

  • Toasts use role="status" and aria-live="polite" for screen reader announcements.
  • Keyboard dismissible via Escape or the close button.
  • Focus management handled by sonner internally.
  • Action and cancel buttons are fully keyboard accessible.

For critical, blocking messages that require user action, use AlertDialog or ConfirmDialog instead of toast notifications.


Design Tokens

TokenUsage
--backgroundToast background
--foregroundToast title text
--muted-foregroundToast description text
--borderToast border
--primaryAction button background
--primary-foregroundAction button text
--secondaryCancel button background
--successSuccess toast accent
--dangerError toast accent
--warningWarning toast accent
--infoInfo toast accent
--radius-lgToast border radius
--shadow-lgToast shadow

On this page