From 79779e5166b6f56fed9d0ed987fa2316115338e9 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Wed, 28 Jun 2023 21:51:53 +0530 Subject: [PATCH] fix: Toast is removed using onClick (#9832) * toaster is removed using onclick * Apply suggestions from code review * Update showToast.tsx --------- Co-authored-by: Peer Richelsen Co-authored-by: Peer Richelsen --- packages/ui/components/toast/showToast.tsx | 52 +++++++++++++++------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/packages/ui/components/toast/showToast.tsx b/packages/ui/components/toast/showToast.tsx index 16b43a9f5b..3a1d17a737 100644 --- a/packages/ui/components/toast/showToast.tsx +++ b/packages/ui/components/toast/showToast.tsx @@ -6,14 +6,16 @@ import { Check, Info } from "../icon"; type IToast = { message: string; toastVisible: boolean; + onClose: () => void; }; -export const SuccessToast = ({ message, toastVisible }: IToast) => ( +export const SuccessToast = ({ message, toastVisible, onClose }: IToast) => (
+ toastVisible && "animate-fade-in-up cursor-pointer" + )} + onClick={onClose}> @@ -21,12 +23,13 @@ export const SuccessToast = ({ message, toastVisible }: IToast) => (
); -export const ErrorToast = ({ message, toastVisible }: IToast) => ( +export const ErrorToast = ({ message, toastVisible, onClose }: IToast) => (
+ toastVisible && "animate-fade-in-up cursor-pointer" + )} + onClick={onClose}> @@ -34,12 +37,13 @@ export const ErrorToast = ({ message, toastVisible }: IToast) => (
); -export const WarningToast = ({ message, toastVisible }: IToast) => ( +export const WarningToast = ({ message, toastVisible, onClose }: IToast) => (
+ toastVisible && "animate-fade-in-up cursor-pointer" + )} + onClick={onClose}> @@ -47,12 +51,13 @@ export const WarningToast = ({ message, toastVisible }: IToast) => (
); -export const DefaultToast = ({ message, toastVisible }: IToast) => ( +export const DefaultToast = ({ message, toastVisible, onClose }: IToast) => (
+ toastVisible && "animate-fade-in-up cursor-pointer" + )} + onClick={onClose}> @@ -67,14 +72,29 @@ export function showToast( variant: "success" | "warning" | "error", duration = TOAST_VISIBLE_DURATION ) { + const onClose = () => { + toast.dismiss(); + }; switch (variant) { case "success": - return toast.custom((t) => , { duration }); + return toast.custom( + (t) => , + { duration } + ); case "error": - return toast.custom((t) => , { duration }); + return toast.custom( + (t) => , + { duration } + ); case "warning": - return toast.custom((t) => , { duration }); + return toast.custom( + (t) => , + { duration } + ); default: - return toast.custom((t) => , { duration }); + return toast.custom( + (t) => , + { duration } + ); } }