feat: add transition in toasts (#4658)

* feat: add transition in toasts

* feat: toast animation improved

* fix: type check in toast

Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-09-28 19:01:19 +01:00
1 parent 5af20f5a7b
commit 14a6c5a03f
2 files changed
+40 -8

No files matched your search

+25 -8
View File
@@ -1,3 +1,4 @@
import classNames from "classnames";
import { Check, Info } from "react-feather";
import toast from "react-hot-toast";
@@ -5,8 +6,12 @@ export default function showToast(message: string, variant: "success" | "warning
switch (variant) {
case "success":
toast.custom(
() => (
<div className="data-testid-toast-success bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md">
(t) => (
<div
className={classNames(
"data-testid-toast-success bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md",
t.visible && "animate-fade-in-up"
)}>
<Check className="h-4 w-4" />
<p>{message}</p>
</div>
@@ -16,8 +21,12 @@ export default function showToast(message: string, variant: "success" | "warning
break;
case "error":
toast.custom(
() => (
<div className="mb-2 flex h-9 items-center space-x-2 rounded-md bg-red-100 p-3 text-sm font-semibold text-red-900 shadow-md">
(t) => (
<div
className={classNames(
"animate-fade-in-up mb-2 flex h-9 items-center space-x-2 rounded-md bg-red-100 p-3 text-sm font-semibold text-red-900 shadow-md",
t.visible && "animate-fade-in-up"
)}>
<Info className="h-4 w-4" />
<p>{message}</p>
</div>
@@ -27,8 +36,12 @@ export default function showToast(message: string, variant: "success" | "warning
break;
case "warning":
toast.custom(
() => (
<div className="bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md">
(t) => (
<div
className={classNames(
"animate-fade-in-up bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md",
t.visible && "animate-fade-in-up"
)}>
<Info className="h-4 w-4" />
<p>{message}</p>
</div>
@@ -38,8 +51,12 @@ export default function showToast(message: string, variant: "success" | "warning
break;
default:
toast.custom(
() => (
<div className="bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md">
(t) => (
<div
className={classNames(
"animate-fade-in-up bg-brand-500 mb-2 flex h-9 items-center space-x-2 rounded-md p-3 text-sm font-semibold text-white shadow-md",
t.visible && "animate-fade-in-up"
)}>
<Check className="h-4 w-4" />
<p>{message}</p>
</div>