-
I am trying to combine Framer Motion with this wonderful UI framework. Right now I am working on a main site navigation which is been built around the Accordion ( Instead of using CSS animation I do like to animate the list and the items using Framer Motion. I wrapped the whole export function Navigation({ children }: NavigationProps) {
return (
<AnimatePresence>
<AccordionRoot className={rootClass} type="multiple">
{children}
</AccordionRoot>
</AnimatePresence>
)
} My thinking process was to build on the export function NavigationList({ children }: NavigationListProps) {
return (
<AccordionContent className={listClass} asChild forceMount>
<motion.div animate={{ opacity: 1 }} exit={{ opacity: 0 }}>
{children}
</motion.div>
</AccordionContent>
)
} I played around with I guess from what I understand from Framer Motion some kind of state information would be helpful: export function NavigationList({ children }: NavigationListProps) {
return (
<AccordionContent className={listClass} asChild forceMount>
{(closed) => closed ? null : <motion.div animate={{ opacity: 1 }} exit={{ opacity: 0 }}>
{children}
</motion.div>}
</AccordionContent>
)
} That would be the approach I imagine when using render props. Is there any alternative to this right now? Thanks for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, you'll need to derive the state manually to feed to framer, you can use the controlled props ( Something like this using https://codesandbox.io/s/framer-motion-accordion-9nup9l?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
Yes, you'll need to derive the state manually to feed to framer, you can use the controlled props (
value
,onValueChange
) to do so.Something like this using
AnimatePresence
would work (though you can share and consume the accordion value viacontext
or however else you prefer)https://codesandbox.io/s/framer-motion-accordion-9nup9l?file=/src/App.js