Faber UI
Components

Sonner

Toast notifications powered by sonner.

Sonner is built on the sonner library. The Toaster component sets up the viewport, and the toast function (imported from sonner) triggers notifications programmatically.

Installation

Terminal
pnpm dlx shadcn@latest add https://faber-ui.vercel.app/r/sonner.json

Usage

Add the Toaster to your root layout, then call toast() anywhere in a client component:

app/layout.tsx
import { Toaster } from "@/components/ui/sonner";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Toaster />
      </body>
    </html>
  );
}
components/save-button.tsx
"use client";

import { toast } from "sonner";

export function SaveButton() {
  return <button onClick={() => toast("Event has been created")}>Save</button>;
}

Examples

Default

With description and action

Types

The toast function accepts a type option that renders an icon:

typescript
toast.success("Saved");
toast.info("Heads up");
toast.warning("Warning");
toast.error("Failed");
toast.loading("Loading");
toast.promise(myAsyncFn, { success: "Done", error: "Failed" });

API

ComponentDescription
ToasterThe viewport. Drop it in your layout once.
toastThe trigger function (imported from sonner). Call toast(message).

Changelog

  1. v0.3.0KbdGroup is typed as a kbd element, Combobox imports its Base UI subpath, the motion lib mirrors the exit easing and travel tokens, and the chart item declares its react-is peer.patch
Full Sonner history

Last updated on

On this page