fix: let toast width auto-size

This commit is contained in:
esdrasrenan 2025-10-05 00:06:20 -03:00
parent cc7fa83622
commit cad42f8b8c

View file

@ -6,17 +6,24 @@ import { Toaster as Sonner, ToasterProps } from "sonner"
const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme()
const baseClass =
"inline-flex w-auto min-w-0 items-center justify-center gap-2 self-center rounded-xl border border-black bg-black px-3 py-2 text-sm font-medium text-white shadow-lg"
const baseStyle = {
background: "#000",
color: "#fff",
border: "1px solid #000",
width: "fit-content" as const,
minWidth: 0,
maxWidth: "min(24rem, calc(100vw - 2rem))",
}
return (
<Sonner
theme={theme as ToasterProps["theme"]}
className="toaster group"
toastOptions={{
className: "inline-flex w-auto min-w-0 items-center justify-center gap-2 self-center rounded-xl border border-black bg-black px-3 py-2 text-sm font-medium text-white shadow-lg",
style: {
background: "#000",
color: "#fff",
border: "1px solid #000",
},
className: baseClass,
style: baseStyle,
classNames: {
icon: "size-[14px] text-white [&>svg]:size-[14px] [&>svg]:text-white",
},
@ -27,32 +34,18 @@ const Toaster = ({ ...props }: ToasterProps) => {
primary: "#ffffff",
secondary: "#000000",
},
success: {
className: "inline-flex w-auto min-w-0 items-center justify-center gap-2 self-center rounded-xl border border-black bg-black px-3 py-2 text-sm font-medium text-white shadow-lg",
style: { background: "#000", color: "#fff", border: "1px solid #000" },
},
error: {
className: "inline-flex w-auto min-w-0 items-center justify-center gap-2 self-center rounded-xl border border-black bg-black px-3 py-2 text-sm font-medium text-white shadow-lg",
style: { background: "#000", color: "#fff", border: "1px solid #000" },
},
info: {
className: "inline-flex w-auto min-w-0 items-center justify-center gap-2 self-center rounded-xl border border-black bg-black px-3 py-2 text-sm font-medium text-white shadow-lg",
style: { background: "#000", color: "#fff", border: "1px solid #000" },
},
warning: {
className: "inline-flex w-auto min-w-0 items-center justify-center gap-2 self-center rounded-xl border border-black bg-black px-3 py-2 text-sm font-medium text-white shadow-lg",
style: { background: "#000", color: "#fff", border: "1px solid #000" },
},
loading: {
className: "inline-flex w-auto min-w-0 items-center justify-center gap-2 self-center rounded-xl border border-black bg-black px-3 py-2 text-sm font-medium text-white shadow-lg",
style: { background: "#000", color: "#fff", border: "1px solid #000" },
},
success: { className: baseClass, style: baseStyle },
error: { className: baseClass, style: baseStyle },
info: { className: baseClass, style: baseStyle },
warning: { className: baseClass, style: baseStyle },
loading: { className: baseClass, style: baseStyle },
}}
style={
{
"--normal-bg": "var(--popover)",
"--normal-text": "var(--popover-foreground)",
"--normal-border": "var(--border)",
"--width": "fit-content",
} as React.CSSProperties
}
{...props}