Sonner
A toast notification wrapper around Sonner that applies MUI theme palette, shape, shadows, and typography to Sonner's toaster and toast elements. It renders a Toaster with rich colors and exposes the toast function for triggering notifications.


shadcn add · no workarounds · theme neutral (none shipped)Installation
Requires @mui-treasury in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
import { Sonner, toast } from '@/src/mui-treasury/components/sonner';export default function App() { return ( <> <Sonner position="top-right" duration={3000} closeButton /> <button onClick={() => toast.success('Saved')}>Save</button> </> );}- Showing brief, non-blocking feedback after a user action such as saving or submitting a form
- Surfacing success, error, warning, or info messages styled consistently with an MUI theme
- Adding a single app-wide toaster that is triggered from anywhere via the exported toast function
- Displaying dismissible notifications that can include a close button
Examples
Basic app-level toaster
Mount Sonner once near the root of the app, then call toast from any client component.
import { Sonner, toast } from '@/src/mui-treasury/components/sonner';export function Root({ children }: { children: React.ReactNode }) { return ( <> <Sonner /> {children} </> );}export function SaveButton() { return <button onClick={() => toast('Changes saved')}>Save</button>;}Typed status toasts
Use Sonner's typed helpers to show success and error states that pick up the themed colors.
import { toast } from '@/src/mui-treasury/components/sonner';export function notifyResult(ok: boolean) { if (ok) { toast.success('Upload complete'); } else { toast.error('Upload failed', { description: 'Please try again.' }); }}Top-center toaster with close button and longer duration
Configure position, duration, and the close button through props.
import { Sonner } from '@/src/mui-treasury/components/sonner';export default function Layout({ children }: { children: React.ReactNode }) { return ( <> <Sonner position="top-center" duration={6000} closeButton /> {children} </> );}API reference
Accessibility
- Sonner renders toasts in an ARIA live region so screen readers announce new notifications automatically.
- Toast text should be short and self-explanatory because toasts disappear after the duration elapses.
- Enable closeButton for messages users may need more time to read, and avoid very short durations for important content.
- Theme-based colors come from the MUI palette, so keep contrast ratios sufficient in custom themes, especially for warning and info variants.
- Do not rely on color alone to convey status; include a clear title or message such as 'Upload failed'.
Docs written by anthropic:claude-haiku-5-5 from the registry source.
Use with Coding Agent
Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.
Use the "Sonner" component (mui-treasury/sonner) from its shadcn registry.1. Install it with: npx shadcn@latest add @mui-treasury/sonner2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: position, duration, closeButton.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { Sonner, toast } from '@/src/mui-treasury/components/sonner';export default function App() { return ( <> <Sonner position="top-right" duration={3000} closeButton /> <button onClick={() => toast.success('Saved')}>Save</button> </> );}```Files & dependencies
- components/sonner/sonner.tsx→ src/mui-treasury/components/sonner/sonner.tsx
- components/sonner/index.ts→ src/mui-treasury/components/sonner/index.ts