Spaces:
Sleeping
Sleeping
File size: 3,164 Bytes
d97b8f9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | import { toast } from "@/hooks/use-toast";
import { toast as sonnerToast } from "sonner";
type ToastOptions = {
title: string;
description?: string;
duration?: number;
};
// Base styles for all toasts
const baseToastStyles = "p-4 rounded-lg border shadow-lg font-medium";
/**
* Enhanced toast utilities for consistent toast styling across the application
*/
export const toastUtils = {
/**
* Show a success toast message
*/
success: (options: ToastOptions) => {
return toast({
title: options.title,
description: options.description,
duration: options.duration || 5000,
className: `${baseToastStyles} bg-green-50 border-green-200 text-green-800 dark:bg-green-950 dark:border-green-800 dark:text-green-200`,
});
},
/**
* Show an error toast message
*/
error: (options: ToastOptions) => {
return toast({
title: options.title,
description: options.description,
duration: options.duration || 6000, // Longer duration for errors
className: `${baseToastStyles} bg-red-50 border-red-200 text-red-800 dark:bg-red-950 dark:border-red-800 dark:text-red-200`,
variant: "destructive",
});
},
/**
* Show a warning toast message
*/
warning: (options: ToastOptions) => {
return toast({
title: options.title,
description: options.description,
duration: options.duration || 5000,
className: `${baseToastStyles} bg-yellow-50 border-yellow-200 text-yellow-800 dark:bg-yellow-950 dark:border-yellow-800 dark:text-yellow-200`,
});
},
/**
* Show an info toast message
*/
info: (options: ToastOptions) => {
return toast({
title: options.title,
description: options.description,
duration: options.duration || 4000,
className: `${baseToastStyles} bg-blue-50 border-blue-200 text-blue-800 dark:bg-blue-950 dark:border-blue-800 dark:text-blue-200`,
});
},
/**
* Show a default toast message
*/
default: (options: ToastOptions) => {
return toast({
title: options.title,
description: options.description,
duration: options.duration || 5000,
className: baseToastStyles,
});
},
};
/**
* Simplified toast utility function that works with Sonner toast
* @param type The type of toast: success, error, warning, info
* @param title The toast title
* @param message Optional toast message
*/
export const showToast = (
type: "success" | "error" | "warning" | "info",
title: string,
message?: string
) => {
switch (type) {
case "success":
sonnerToast.success(title, {
description: message,
});
break;
case "error":
sonnerToast.error(title, {
description: message,
});
break;
case "warning":
sonnerToast.warning(title, {
description: message,
});
break;
case "info":
sonnerToast.info(title, {
description: message,
});
break;
default:
sonnerToast(title, {
description: message,
});
}
}; |