Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/warm-zoos-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@nextui-org/accordion": patch
"@nextui-org/modal": patch
"@nextui-org/navbar": patch
"@nextui-org/popover": patch
"@nextui-org/ripple": patch
"@nextui-org/tabs": patch
"@nextui-org/tooltip": patch
---

Changes the motion important to the more lightweight m component in framer motion to only load the required features.
50 changes: 27 additions & 23 deletions packages/components/accordion/src/accordion-item.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {forwardRef} from "@nextui-org/system";
import {useMemo, ReactNode} from "react";
import {ChevronIcon} from "@nextui-org/shared-icons";
import {AnimatePresence, motion, useWillChange} from "framer-motion";
import {AnimatePresence, LazyMotion, domAnimation, m, useWillChange} from "framer-motion";
import {TRANSITION_VARIANTS} from "@nextui-org/framer-transitions";

import {UseAccordionItemProps, useAccordionItem} from "./use-accordion-item";
Expand Down Expand Up @@ -53,31 +53,35 @@ const AccordionItem = forwardRef<"button", AccordionItemProps>((props, ref) => {
}

return keepContentMounted ? (
<motion.section
key="accordion-content"
animate={isOpen ? "enter" : "exit"}
exit="exit"
initial="exit"
style={{overflowY: "hidden", willChange}}
variants={TRANSITION_VARIANTS.collapse}
{...motionProps}
>
<div {...getContentProps()}>{children}</div>
</motion.section>
<LazyMotion features={domAnimation}>
<m.section
key="accordion-content"
animate={isOpen ? "enter" : "exit"}
exit="exit"
initial="exit"
style={{overflowY: "hidden", willChange}}
variants={TRANSITION_VARIANTS.collapse}
{...motionProps}
>
<div {...getContentProps()}>{children}</div>
</m.section>
</LazyMotion>
) : (
<AnimatePresence initial={false}>
{isOpen && (
<motion.section
key="accordion-content"
animate="enter"
exit="exit"
initial="exit"
style={{overflowY: "hidden", willChange}}
variants={TRANSITION_VARIANTS.collapse}
{...motionProps}
>
<div {...getContentProps()}>{children}</div>
</motion.section>
<LazyMotion features={domAnimation}>
<m.section
key="accordion-content"
animate="enter"
exit="exit"
initial="exit"
style={{overflowY: "hidden", willChange}}
variants={TRANSITION_VARIANTS.collapse}
{...motionProps}
>
<div {...getContentProps()}>{children}</div>
</m.section>
</LazyMotion>
)}
</AnimatePresence>
);
Expand Down
40 changes: 22 additions & 18 deletions packages/components/modal/src/modal-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {DismissButton} from "@react-aria/overlays";
import {TRANSITION_VARIANTS} from "@nextui-org/framer-transitions";
import {CloseIcon} from "@nextui-org/shared-icons";
import {RemoveScroll} from "react-remove-scroll";
import {motion} from "framer-motion";
import {domAnimation, LazyMotion, m} from "framer-motion";
import {useDialog} from "@react-aria/dialog";
import {mergeProps} from "@react-aria/utils";
import {HTMLNextUIProps} from "@nextui-org/system";
Expand Down Expand Up @@ -78,13 +78,15 @@ const ModalContent = forwardRef<"div", ModalContentProps, KeysToOmit>((props, _)
}

return (
<motion.div
animate="enter"
exit="exit"
initial="exit"
variants={TRANSITION_VARIANTS.fade}
{...(getBackdropProps() as HTMLMotionProps<"div">)}
/>
<LazyMotion features={domAnimation}>
<m.div
animate="enter"
exit="exit"
initial="exit"
variants={TRANSITION_VARIANTS.fade}
{...(getBackdropProps() as HTMLMotionProps<"div">)}
/>
</LazyMotion>
);
}, [backdrop, disableAnimation, getBackdropProps]);

Expand All @@ -95,16 +97,18 @@ const ModalContent = forwardRef<"div", ModalContentProps, KeysToOmit>((props, _)
{disableAnimation ? (
<div className={slots.wrapper({class: classNames?.wrapper})}>{content}</div>
) : (
<motion.div
animate="enter"
className={slots.wrapper({class: classNames?.wrapper})}
exit="exit"
initial="exit"
variants={scaleInOut}
{...motionProps}
>
{content}
</motion.div>
<LazyMotion features={domAnimation}>
<m.div
animate="enter"
className={slots.wrapper({class: classNames?.wrapper})}
exit="exit"
initial="exit"
variants={scaleInOut}
{...motionProps}
>
{content}
</m.div>
</LazyMotion>
)}
</RemoveScroll>
</div>
Expand Down
40 changes: 21 additions & 19 deletions packages/components/navbar/src/navbar-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {forwardRef, HTMLNextUIProps} from "@nextui-org/system";
import {useDOMRef} from "@nextui-org/react-utils";
import {clsx, dataAttr} from "@nextui-org/shared-utils";
import {AnimatePresence, HTMLMotionProps, motion} from "framer-motion";
import {AnimatePresence, domAnimation, HTMLMotionProps, LazyMotion, m} from "framer-motion";
import {mergeProps} from "@react-aria/utils";
import {ReactElement, useCallback} from "react";
import {RemoveScroll} from "react-remove-scroll";
Expand Down Expand Up @@ -61,24 +61,26 @@ const NavbarMenu = forwardRef<"ul", NavbarMenuProps>((props, ref) => {
<AnimatePresence mode="wait">
{isMenuOpen ? (
<MenuWrapper>
<motion.ul
ref={domRef}
layoutScroll
animate="enter"
className={slots.menu?.({class: styles})}
data-open={dataAttr(isMenuOpen)}
exit="exit"
initial="exit"
style={{
// @ts-expect-error
"--navbar-height": height,
...style,
}}
variants={menuVariants}
{...mergeProps(motionProps, otherProps)}
>
{children}
</motion.ul>
<LazyMotion features={domAnimation}>
<m.ul
ref={domRef}
layoutScroll
animate="enter"
className={slots.menu?.({class: styles})}
data-open={dataAttr(isMenuOpen)}
exit="exit"
initial="exit"
style={{
// @ts-expect-error
"--navbar-height": height,
...style,
}}
variants={menuVariants}
{...mergeProps(motionProps, otherProps)}
>
{children}
</m.ul>
</LazyMotion>
</MenuWrapper>
) : null}
</AnimatePresence>
Expand Down
20 changes: 11 additions & 9 deletions packages/components/navbar/src/navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {forwardRef} from "@nextui-org/system";
import {pickChildren} from "@nextui-org/react-utils";
import {motion} from "framer-motion";
import {LazyMotion, domAnimation, m} from "framer-motion";
import {mergeProps} from "@react-aria/utils";

import {hideOnScrollVariants} from "./navbar-transitions";
Expand Down Expand Up @@ -31,14 +31,16 @@ const Navbar = forwardRef<"div", NavbarProps>((props, ref) => {
return (
<NavbarProvider value={context}>
{context.shouldHideOnScroll ? (
<motion.nav
animate={context.isHidden ? "hidden" : "visible"}
initial={false}
variants={hideOnScrollVariants}
{...mergeProps(context.getBaseProps(), context.motionProps)}
>
{content}
</motion.nav>
<LazyMotion features={domAnimation}>
<m.nav
animate={context.isHidden ? "hidden" : "visible"}
initial={false}
variants={hideOnScrollVariants}
{...mergeProps(context.getBaseProps(), context.motionProps)}
>
{content}
</m.nav>
</LazyMotion>
) : (
<Component {...context.getBaseProps()}>{content}</Component>
)}
Expand Down
46 changes: 25 additions & 21 deletions packages/components/popover/src/free-solo-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import * as React from "react";
import {DismissButton, Overlay} from "@react-aria/overlays";
import {forwardRef} from "@nextui-org/system";
import {HTMLMotionProps, motion} from "framer-motion";
import {domAnimation, HTMLMotionProps, LazyMotion, m} from "framer-motion";
import {mergeProps} from "@react-aria/utils";
import {getTransformOrigins} from "@nextui-org/aria-utils";
import {TRANSITION_VARIANTS} from "@nextui-org/framer-transitions";
Expand Down Expand Up @@ -39,19 +39,21 @@ const FreeSoloPopoverWrapper = ({
return disableAnimation ? (
<div {...otherProps}>{children}</div>
) : (
<motion.div
animate="enter"
exit="exit"
initial="initial"
style={{
...style,
...getTransformOrigins(placement === "center" ? "top" : placement),
}}
variants={TRANSITION_VARIANTS.scaleSpringOpacity}
{...mergeProps(otherProps, motionProps)}
>
{children}
</motion.div>
<LazyMotion features={domAnimation}>
<m.div
animate="enter"
exit="exit"
initial="initial"
style={{
...style,
...getTransformOrigins(placement === "center" ? "top" : placement),
}}
variants={TRANSITION_VARIANTS.scaleSpringOpacity}
{...mergeProps(otherProps, motionProps)}
>
{children}
</m.div>
</LazyMotion>
);
};

Expand Down Expand Up @@ -87,13 +89,15 @@ const FreeSoloPopover = forwardRef<"div", FreeSoloPopoverProps>((props, ref) =>
}

return (
<motion.div
animate="enter"
exit="exit"
initial="exit"
variants={TRANSITION_VARIANTS.fade}
{...(getBackdropProps() as HTMLMotionProps<"div">)}
/>
<LazyMotion features={domAnimation}>
<m.div
animate="enter"
exit="exit"
initial="exit"
variants={TRANSITION_VARIANTS.fade}
{...(getBackdropProps() as HTMLMotionProps<"div">)}
/>
</LazyMotion>
);
}, [backdrop, disableAnimation, getBackdropProps]);

Expand Down
44 changes: 24 additions & 20 deletions packages/components/popover/src/popover-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {DOMAttributes, ReactNode, useMemo, useRef} from "react";
import {forwardRef} from "@nextui-org/system";
import {DismissButton} from "@react-aria/overlays";
import {TRANSITION_VARIANTS} from "@nextui-org/framer-transitions";
import {motion} from "framer-motion";
import {m, domAnimation, LazyMotion} from "framer-motion";
import {useDialog} from "@react-aria/dialog";
import {mergeProps} from "@react-aria/utils";
import {HTMLNextUIProps} from "@nextui-org/system";
Expand Down Expand Up @@ -69,13 +69,15 @@ const PopoverContent = forwardRef<"div", PopoverContentProps>((props, _) => {
}

return (
<motion.div
animate="enter"
exit="exit"
initial="exit"
variants={TRANSITION_VARIANTS.fade}
{...(getBackdropProps() as HTMLMotionProps<"div">)}
/>
<LazyMotion features={domAnimation}>
<m.div
animate="enter"
exit="exit"
initial="exit"
variants={TRANSITION_VARIANTS.fade}
{...(getBackdropProps() as HTMLMotionProps<"div">)}
/>
</LazyMotion>
);
}, [backdrop, disableAnimation, getBackdropProps]);

Expand All @@ -86,18 +88,20 @@ const PopoverContent = forwardRef<"div", PopoverContentProps>((props, _) => {
{disableAnimation ? (
content
) : (
<motion.div
animate="enter"
exit="exit"
initial="initial"
style={{
...getTransformOrigins(placement === "center" ? "top" : placement),
}}
variants={TRANSITION_VARIANTS.scaleSpringOpacity}
{...motionProps}
>
{content}
</motion.div>
<LazyMotion features={domAnimation}>
<m.div
animate="enter"
exit="exit"
initial="initial"
style={{
...getTransformOrigins(placement === "center" ? "top" : placement),
}}
variants={TRANSITION_VARIANTS.scaleSpringOpacity}
{...motionProps}
>
{content}
</m.div>
</LazyMotion>
)}
</RemoveScroll>
</div>
Expand Down
Loading