Sonner

Toast notifications on Sonner that follow Ward's light and dark theme, with Toaster and toast imported from one place.

Installation

pnpm dlx shadcn@latest add @ward/sonner

Add the Ward registry to components.json once:

"registries": {
  "@ward": "https://ward.so/r/{name}.json"
}

Or install from the URL with no configuration: npx shadcn@latest add https://ward.so/r/sonner.json

Usage

import { Toaster, toast } from "@/components/ui/sonner";
import { Button } from "@/components/ui/button";
// Once, in your root layout
<Toaster />

// Anywhere in a client component
<Button onClick={() => toast("Saved")}>Save</Button>
<Button variant="outline" onClick={() => toast.success("Link copied", { description: "Paste it anywhere." })}>Copy link</Button>

Props

PropTypeDefaultDescription
toast(message, options)(message: ReactNode, options?: ExternalToast) => string | number-Show a toast and return its id. Import it from this file, not from sonner, so it reaches the same Toaster.
toast.success, error, info, warning, loading(message, options?) => string | number-The same call with a matching icon; loading stays until you update or dismiss it.
toast.promise(promise, { loading, success, error }) => ...-Show a loading toast that turns into a success or error toast when the promise settles.
toast.dismiss(id?: string | number) => void-Close one toast by id, or every toast when no id is given.
options descriptionReactNode-Second line of smaller text under the message.
options action{ label: string; onClick: () => void }-Button in the toast, such as Undo.
options durationnumber4000Milliseconds before the toast closes; Infinity keeps it until it is dismissed.
Toaster position"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""bottom-right"Corner or edge of the screen the toasts stack in.
Toaster closeButtonbooleanfalseShow a close button on every toast.
Toaster theme"light" | "dark" | "system"-Follows the data-theme attribute or dark class on the html element; set it only to force one.

Ward · Version 1.0.0 · Registry manifest