diff --git a/.changeset/friendly-balloons-rest.md b/.changeset/friendly-balloons-rest.md new file mode 100644 index 0000000000..397ef5eaf7 --- /dev/null +++ b/.changeset/friendly-balloons-rest.md @@ -0,0 +1,5 @@ +--- +"@heroui/toast": patch +--- + +- Use LazyMotion and AnimatePresence in ToastProvider to support exit animations. diff --git a/packages/components/toast/src/toast-provider.tsx b/packages/components/toast/src/toast-provider.tsx index 38bff01db1..fd5df4b764 100644 --- a/packages/components/toast/src/toast-provider.tsx +++ b/packages/components/toast/src/toast-provider.tsx @@ -1,9 +1,12 @@ import {ToastOptions, ToastQueue, useToastQueue} from "@react-stately/toast"; import {useProviderContext} from "@heroui/system"; +import {AnimatePresence, LazyMotion} from "framer-motion"; import {RegionProps, ToastRegion} from "./toast-region"; import {ToastProps, ToastPlacement} from "./use-toast"; +const loadFeatures = () => import("framer-motion").then((res) => res.domMax); + let globalToastQueue: ToastQueue | null = null; interface ToastProviderProps { @@ -37,20 +40,22 @@ export const ToastProvider = ({ const globalContext = useProviderContext(); const disableAnimation = disableAnimationProp ?? globalContext?.disableAnimation ?? false; - if (toastQueue.visibleToasts.length == 0) { - return null; - } - return ( - + + + {toastQueue.visibleToasts.length > 0 ? ( + + ) : null} + + ); }; diff --git a/packages/components/toast/src/toast.tsx b/packages/components/toast/src/toast.tsx index 372f24b6e2..273ef89e65 100644 --- a/packages/components/toast/src/toast.tsx +++ b/packages/components/toast/src/toast.tsx @@ -7,14 +7,12 @@ import { SuccessIcon, WarningIcon, } from "@heroui/shared-icons"; -import {AnimatePresence, m, LazyMotion} from "framer-motion"; +import {m} from "framer-motion"; import {cloneElement, isValidElement} from "react"; import {Spinner} from "@heroui/spinner"; import {UseToastProps, useToast} from "./use-toast"; -const loadFeatures = () => import("framer-motion").then((res) => res.domMax); - export interface ToastProps extends UseToastProps {} const iconMap = { @@ -108,21 +106,17 @@ const Toast = forwardRef<"div", ToastProps>((props, ref) => { {disableAnimation ? ( toastContent ) : ( - - - - - {toastContent} - - - - + + + {toastContent} + + )} );