Coerce remaining toast variants (lib)

cgen-f665641441ae43f985cd5062ce48c6b9
This commit is contained in:
Builder.io 2025-10-14 03:57:17 +00:00
parent 67cf45ffbc
commit 26d2767120

View file

@ -30,27 +30,66 @@ export const aethexToast = {
}, },
error: (options: AethexToastOptions) => { error: (options: AethexToastOptions) => {
const normalize = (d?: any) => {
if (d == null) return undefined;
if (typeof d === "string") return d;
if (typeof d === "object") {
if ((d as any).message) return String((d as any).message);
try {
return JSON.stringify(d);
} catch (e) {
return String(d);
}
}
return String(d);
};
return toast({ return toast({
title: `${options.title || "Error"}`, title: `${options.title || "Error"}`,
description: options.description, description: normalize(options.description),
duration: options.duration || 5000, duration: options.duration || 5000,
variant: "destructive", variant: "destructive",
}); });
}, },
warning: (options: AethexToastOptions) => { warning: (options: AethexToastOptions) => {
const normalize = (d?: any) => {
if (d == null) return undefined;
if (typeof d === "string") return d;
if (typeof d === "object") {
if ((d as any).message) return String((d as any).message);
try {
return JSON.stringify(d);
} catch (e) {
return String(d);
}
}
return String(d);
};
return toast({ return toast({
title: `⚠️ ${options.title || "Warning"}`, title: `⚠️ ${options.title || "Warning"}`,
description: options.description, description: normalize(options.description),
duration: options.duration || 5000, duration: options.duration || 5000,
variant: "warning" as any, variant: "warning" as any,
}); });
}, },
info: (options: AethexToastOptions) => { info: (options: AethexToastOptions) => {
const normalize = (d?: any) => {
if (d == null) return undefined;
if (typeof d === "string") return d;
if (typeof d === "object") {
if ((d as any).message) return String((d as any).message);
try {
return JSON.stringify(d);
} catch (e) {
return String(d);
}
}
return String(d);
};
return toast({ return toast({
title: ` ${options.title || "Information"}`, title: ` ${options.title || "Information"}`,
description: options.description, description: normalize(options.description),
duration: options.duration || 5000, duration: options.duration || 5000,
variant: "info" as any, variant: "info" as any,
}); });