import classNames from "classnames";
import type { ToastOptions, Toast } from "react-hot-toast";
import toast from "react-hot-toast";
import { Icon } from "../..";
type IToast = {
message: string;
toastVisible: boolean;
toastId: string;
onClose: (toastId: string) => void;
};
export const SuccessToast = ({ message, toastVisible, onClose, toastId }: IToast) => (
);
export const ErrorToast = ({ message, toastVisible, onClose, toastId }: IToast) => (
);
export const WarningToast = ({ message, toastVisible, onClose, toastId }: IToast) => (
);
export const DefaultToast = ({ message, toastVisible, onClose, toastId }: IToast) => (
);
const TOAST_VISIBLE_DURATION = 6000;
type ToastVariants = "success" | "warning" | "error";
export function showToast(
message: string,
variant: ToastVariants,
// Options or duration (duration for backwards compatibility reasons)
options: number | ToastOptions = TOAST_VISIBLE_DURATION
) {
//
const _options: ToastOptions = typeof options === "number" ? { duration: options } : options;
if (!_options.duration) _options.duration = TOAST_VISIBLE_DURATION;
if (!_options.position) _options.position = "bottom-center";
const onClose = (toastId: string) => {
toast.remove(toastId);
};
const toastElements: { [x in ToastVariants]: (t: Toast) => JSX.Element } = {
success: (t) => (
),
error: (t) => ,
warning: (t) => (
),
};
return toast.custom(
toastElements[variant] ||
((t) => ),
_options
);
}