Files
homelable/frontend/src/components/ui/sonner.tsx
T
Pouzor 5726289b18 fix(toaster): enable richColors so error surface actually applies
Setting --error-bg alone had no effect: sonner only honors per-type
surfaces when richColors is enabled, so error toasts kept using
--normal-bg and looked identical to a normal toast. Enable richColors
and pin success/info/warning back to the neutral popover surface so only
errors turn red.
2026-07-19 11:44:47 +02:00

68 lines
2.1 KiB
TypeScript

"use client"
import { useTheme } from "next-themes"
import { Toaster as Sonner, type ToasterProps } from "sonner"
import { CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from "lucide-react"
const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme()
return (
<Sonner
theme={theme as ToasterProps["theme"]}
className="toaster group"
richColors
icons={{
success: (
<CircleCheckIcon className="size-4" />
),
info: (
<InfoIcon className="size-4" />
),
warning: (
<TriangleAlertIcon className="size-4" />
),
error: (
<OctagonXIcon className="size-4" />
),
loading: (
<Loader2Icon className="size-4 animate-spin" />
),
}}
style={
{
"--normal-bg": "var(--popover)",
"--normal-text": "var(--popover-foreground)",
"--normal-border": "var(--border)",
"--border-radius": "var(--radius)",
// richColors (below) is required for sonner to honor per-type surfaces.
// Errors get a red surface so failures (e.g. a save while the backend
// is down) stand out instead of reading like a normal toast...
"--error-bg": "#f85149",
"--error-text": "#ffffff",
"--error-border": "#da3633",
// ...while success/info/warning stay on the neutral popover surface so
// the rest of the toast UX is unchanged.
"--success-bg": "var(--popover)",
"--success-text": "var(--popover-foreground)",
"--success-border": "var(--border)",
"--info-bg": "var(--popover)",
"--info-text": "var(--popover-foreground)",
"--info-border": "var(--border)",
"--warning-bg": "var(--popover)",
"--warning-text": "var(--popover-foreground)",
"--warning-border": "var(--border)",
} as React.CSSProperties
}
toastOptions={{
classNames: {
toast: "cn-toast",
},
}}
{...props}
/>
)
}
export { Toaster }