28 lines
902 B
TypeScript
28 lines
902 B
TypeScript
import { toast, type ToastOptions } from "react-toastify";
|
|
|
|
export const useToast = () => {
|
|
const showToast = (message: string, options?: ToastOptions) => {
|
|
toast.dismiss();
|
|
const baseStyle: React.CSSProperties = {
|
|
whiteSpace: "nowrap",
|
|
overflow: "hidden",
|
|
textOverflow: "ellipsis",
|
|
};
|
|
toast(message, {
|
|
...options,
|
|
style: { ...baseStyle, ...(options?.style || {}) },
|
|
});
|
|
};
|
|
|
|
const toastSuccess = (msg: string, opts?: ToastOptions) =>
|
|
showToast(msg, { ...opts, type: "success" });
|
|
const toastError = (msg: string, opts?: ToastOptions) =>
|
|
showToast(msg, { ...opts, type: "error" });
|
|
const toastInfo = (msg: string, opts?: ToastOptions) =>
|
|
showToast(msg, { ...opts, type: "info" });
|
|
const toastWarning = (msg: string, opts?: ToastOptions) =>
|
|
showToast(msg, { ...opts, type: "warning" });
|
|
|
|
return { showToast, toastSuccess, toastError, toastInfo, toastWarning };
|
|
};
|