shadcn

Sonner

Buttons 235

About

An opinionated toast component for React.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Sonner to your project and fits it to your theme.

Code

How Sonner is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Toaster } from "@/components/ui/sonner";

export default function ToasterDemo() {
  return (
    <div className="flex flex-col gap-2">
      <Toaster />
      <div className="flex flex-row gap-2">
        <Button
          variant="outline"
          onClick={() =>
            toast("Event has been created", {
              description: "Sunday, December 03, 2023 at 9:00 AM",
              action: {
                label: "Undo",
                onClick: () => console.log("Undo"),
              },
            })
          }
        >
          Default Toast
        </Button>

        <Button
          variant="outline"
          onClick={() =>
            toast.success("Success!", {
              description: "Your action was completed successfully",
            })
          }
        >
          Success Toast
        </Button>

        <Button
          variant="outline"
          onClick={() =>
            toast.error("Error!", {
              description: "Something went wrong. Please try again.",
            })
          }
        >
          Error Toast
        </Button>

        <Button
          variant="outline"
          onClick={() =>
            toast.promise(
              new Promise((resolve) => setTimeout(resolve, 2000)),
              {
                loading: "Loading...",
                success: "Promise resolved",
                error: "Promise rejected",
              }
            )
          }
        >
          Promise Toast
        </Button>
      </div>
    </div>
  );
}

export { ToasterDemo };

Dependencies

More by shadcn

View all
  • Navigation menu

    Navigation menu

    778
  • Calendar with time pressets

    Calendar with time pressets

    507
  • Sidebar

    Sidebar

    344
  • Chart

    Chart

    220
  • Icons

    Icons

    188
  • Dropdown Menu

    Dropdown Menu

    153
  • Calendar with event slots

    Calendar with event slots

    117
  • Data Table

    Data Table

    116

More in Buttons

View all
  • Button Group

    Button Group

    2
  • App Store Button

    App Store Button

    457
  • Eclipse Button

    Eclipse Button

    6
  • Texture Button

    Texture Button

    95
  • Button

    Button

    5
  • Button Save

    Button Save

    47
  • Base Button

    Base Button

    3
  • HeroUI Button Group

    HeroUI Button Group