apps/design-system/content/docs/components/sonner.mdx
Sonner is built and maintained by emilkowalski_.
<Step>Install the following dependencies:</Step>
npm install sonner next-themes
<Step>Copy and paste the following code into your project.</Step>
<ComponentSource name="sonner" /><Step>Add the Toaster component</Step>
import { Toaster } from '@/components/ui/sonner'
export default function RootLayout({ children }) {
return (
<html lang="en">
<head />
<body>
<main>{children}</main>
<Toaster />
</body>
</html>
)
}
import { toast } from 'sonner'
toast('Event has been created.')
Use a toast for short-lived, non-blocking feedback or to confirm an operation after its originating surface has closed or navigated away.
Do not use a toast as the only feedback for:
FormMessage or FieldError beside the field.role="alert" message in destructive text near the actions.Admonition or ErrorDisplay.Keep error copy specific and include the next step when it is not obvious.
You can change the amount of toasts visible through the visibleToasts prop.
<Toaster expand={true | false} />
You can use the Input below to try it out.
<SonnerExpandConfig />You can change the amount of toasts visible through the visibleToasts prop.
<Toaster
position={
'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center'
}
/>
You can use the Input below to try it out.
<SonnerPositionConfig />You can customize the type of toast you want to render, and pass an options object as the second argument.
<ComponentPreview name="sonner-types" />