Sonner (Toast)
FeedbackToast notification system. Trigger with toast() from the sonner package.
Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.
"use client";
import { Button } from "@dashboardpack/core/components/ui/button";
import { Toaster } from "@dashboardpack/core/components/ui/sonner";
import type { ReactNode } from "react";
import { toast } from "sonner";
export default function SonnerExample() {
return (
<div className="flex flex-wrap gap-3">
<Button
variant="outline"
onClick={() =>
toast("Your report is ready", {
description: "You can download it from the reports page.",
})
}
>
Default toast
</Button>
<Button variant="outline" onClick={() => toast.success("Changes saved")}>
Success
</Button>
<Button
variant="outline"
onClick={() => toast.error("Unable to save. Please try again.")}
>
Error
</Button>
<Button
variant="outline"
onClick={() =>
toast("Project archived", {
action: {
label: "Undo",
onClick: () => toast.success("Project restored"),
},
})
}
>
With action
</Button>
</div>
);
}
// Shell setup only: Apex already includes a Toaster in its root layout.
// Use this wrapper only when integrating the component into another application.
export function ToastShellExample({ children }: { children: ReactNode }) {
return (
<>
{children}
<Toaster richColors closeButton />
</>
);
}Usage
Mount Toaster once in your application shell, then call toast from sonner in event handlers. Apex already mounts Toaster in its root layout. Never add a second Toaster in a page.
import { Toaster } from "@dashboardpack/core/components/ui/sonner";Available in the included @dashboardpack/core package. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.
API reference
Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.
| Prop | Type / Default | Description |
|---|---|---|
| richColors (Toaster) | booleanDefault: false | Use semantic colors for success and error toasts. |
| closeButton (Toaster) | booleanDefault: false | Show a dismiss button. |
| description (toast options) | ReactNodeDefault: — | Secondary message content. |
| action (toast options) | { label, onClick }Default: — | A recovery or follow-up action. |
| duration (toast options) | numberDefault: 4000 | Visible duration in milliseconds. |