Docs
Sonner
Sonner
A succinct message that is displayed temporarily.
A ShadCN Toast component customized by adding icons to each sonner type.
Installation
Run the following command:
pnpm dlx shadcn@latest add "https://akasha-ui.pages.dev/r/styles/default/sonner.json"
Add the Toaster component
app/layout.tsx
import { Toaster } from "@/components/ui/toaster";
export default function RootLayout({ children }) {
return (
<html lang="en">
<head />
<body>
<main>{children}</main>
<Toaster />
</body>
</html>
);
}
Usage
The useToast
hook returns a sonner
function that you can use to display a sonner.
import { useToast } from "@/hooks/use-sonner";
export const ToastDemo = () => {
const { sonner } = useToast();
return (
<Button
onClick={() => {
sonner({
title: "Scheduled: Catch up",
description: "Friday, February 10, 2023 at 5:57 PM",
});
}}
>
Show Toast
</Button>
);
};
Examples
Info
Success
Use sonner.success("message")
to display a warning sonner.
Warning
Use sonner.warning("warning")
to display a warning sonner.
Error
Use sonner.error("message")
to display a destructive sonner.