aethex-forge/client/hooks/use-aethex-toast.ts
Builder.io 67cf45ffbc Coerce remaining toast variants (hooks)
cgen-d8d51c7853bf45f2988ae84a6a1fb3b4
2025-10-14 03:57:05 +00:00

87 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { toast as baseToast } from "@/components/ui/use-toast";
interface AethexToastOptions {
title?: string;
description?: string;
duration?: number;
}
export const useAethexToast = () => {
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);
};
const success = (options: AethexToastOptions) => {
return baseToast({
title: `${options.title || "Success"}`,
description: normalize(options.description),
duration: options.duration || 5000,
variant: "success" as any,
});
};
const error = (options: AethexToastOptions) => {
return baseToast({
title: `${options.title || "Error"}`,
description: normalize(options.description),
duration: options.duration || 5000,
variant: "destructive",
});
};
const warning = (options: AethexToastOptions) => {
return baseToast({
title: `⚠️ ${options.title || "Warning"}`,
description: normalize(options.description),
duration: options.duration || 5000,
variant: "warning" as any,
});
};
const info = (options: AethexToastOptions) => {
return baseToast({
title: ` ${options.title || "Information"}`,
description: normalize(options.description),
duration: options.duration || 5000,
variant: "info" as any,
});
};
const aethex = (options: AethexToastOptions) => {
return baseToast({
title: `${options.title || "AeThex OS"}`,
description: options.description,
duration: options.duration || 6000,
variant: "aethex" as any,
});
};
const system = (message: string) => {
return baseToast({
title: "🔧 AeThex OS",
description: message,
duration: 4000,
variant: "aethex" as any,
});
};
return {
success,
error,
warning,
info,
aethex,
system,
toast: baseToast,
};
};