4
0
forked from crowetic/commerce

Changes mobile menu animation to be consistent with cart animation. (#1015)

This commit is contained in:
Michael Novotny 2023-05-11 12:53:04 -07:00 committed by GitHub
parent a5e799b16e
commit a0c0d10fae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
'use client'; 'use client';
import { Dialog } from '@headlessui/react'; import { Dialog } from '@headlessui/react';
import { motion } from 'framer-motion'; import { AnimatePresence, motion } from 'framer-motion';
import Link from 'next/link'; import Link from 'next/link';
import { usePathname, useSearchParams } from 'next/navigation'; import { usePathname, useSearchParams } from 'next/navigation';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
@ -42,19 +42,37 @@ export default function MobileMenu({ menu }: { menu: Menu[] }) {
> >
<MenuIcon className="h-6" /> <MenuIcon className="h-6" />
</button> </button>
<AnimatePresence initial={false}>
{mobileMenuIsOpen && (
<Dialog <Dialog
as={motion.div}
initial="closed"
animate="open"
exit="closed"
key="dialog"
static
open={mobileMenuIsOpen} open={mobileMenuIsOpen}
onClose={() => { onClose={() => {
setMobileMenuIsOpen(false); setMobileMenuIsOpen(false);
}} }}
className="relative z-50" className="relative z-50"
> >
<motion.div
variants={{
open: { opacity: 1, backdropFilter: 'blur(0.5px)' },
closed: { opacity: 0, backdropFilter: 'blur(0px)' }
}}
className="fixed inset-0 bg-black/30"
aria-hidden="true"
/>
<div className="fixed inset-0 flex justify-end" data-testid="mobile-menu"> <div className="fixed inset-0 flex justify-end" data-testid="mobile-menu">
<Dialog.Panel <Dialog.Panel
as={motion.div} as={motion.div}
variants={{ variants={{
open: { opacity: 1 } open: { translateX: 0 },
closed: { translateX: '-100%' }
}} }}
transition={{ type: 'spring', bounce: 0, duration: 0.3 }}
className="flex w-full flex-col bg-white pb-6 dark:bg-black" className="flex w-full flex-col bg-white pb-6 dark:bg-black"
> >
<div className="p-4"> <div className="p-4">
@ -93,6 +111,8 @@ export default function MobileMenu({ menu }: { menu: Menu[] }) {
</Dialog.Panel> </Dialog.Panel>
</div> </div>
</Dialog> </Dialog>
)}
</AnimatePresence>
</> </>
); );
} }