Basic
Trigger default, success and error toasts from buttons. Showing a toast does not move focus away from the button.
"use client"
import { toast } from "sonner"
import { Button } from "@/components/ui/button"
import { Toaster } from "@/components/ui/sonner"
export function SonnerBasic() {
return (
<div className="flex flex-col items-start gap-4">
<div className="flex flex-wrap items-center gap-2">
<Toaster />
<Button
emphasis="stroke"
onClick={() => toast("Registry rebuilt", { description: "57 items written." })}
>
Show a toast
</Button>
<Button
intent="neutral"
emphasis="stroke"
onClick={() => toast.success("Tokens in sync")}
>
Success
</Button>
<Button
intent="error"
emphasis="stroke"
onClick={() => toast.error("Build failed")}
>
Error
</Button>
</div>
</div>
)
}