added animation to submenu
This commit is contained in:
parent
c1df68b27a
commit
a3d4f2b11c
@ -3,35 +3,49 @@ import PropTypes from "prop-types";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { AnimatePresence, motion } from "motion/react";
|
||||||
|
|
||||||
function SubMenu({ items, isVisible, onLinkClick }) {
|
function SubMenu({ items, isVisible, onLinkClick }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<div
|
<AnimatePresence mode="popLayout">
|
||||||
className={clsx(
|
{isVisible && (
|
||||||
"absolute left-0 z-50 shadow-sm top-full border-t-3 border-primary dark:border-primary-dark bg-secondary dark:bg-secondary-dark rounded-2xl shadow-surface-variant-dark dark:shadow-primary",
|
<div>
|
||||||
isVisible ? "block" : "hidden"
|
<motion.div
|
||||||
)}
|
className={clsx(
|
||||||
>
|
"absolute left-0 z-50 shadow-sm top-full border-t-3 border-primary dark:border-primary-dark bg-secondary dark:bg-secondary-dark rounded-2xl shadow-surface-variant-dark dark:shadow-primary overflow-hidden"
|
||||||
{items.map((subItem, index) => (
|
)}
|
||||||
<div
|
initial={{ y: 15, opacity: 0 }}
|
||||||
key={index}
|
animate={{ y: 0, opacity: 1 }}
|
||||||
className="px-6 py-2 cursor-pointer text-nowrap hover:bg-white dark:hover:bg-secondary-variant-dark first:rounded-t-2xl second-last:rounded-b-2xl first:pt-4 last:pb-4"
|
exit={{ y: 15, opacity: 0 }}
|
||||||
onClick={onLinkClick}
|
transition={{ duration: 0.4, type: "spring" }}
|
||||||
>
|
>
|
||||||
<Link to={subItem.path}>{t(subItem.name)}</Link>
|
{items.map((subItem, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="px-6 py-2 cursor-pointer text-nowrap dark:hover:bg-secondary-variant-dark first:rounded-t-2xl second-last:rounded-b-2xl first:pt-4 last:pb-4 hover:bg-white"
|
||||||
|
onClick={onLinkClick}
|
||||||
|
>
|
||||||
|
<Link to={subItem.path}>{t(subItem.name)}</Link>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</motion.div>
|
||||||
|
<motion.svg
|
||||||
|
initial={{ y: 15, opacity: 0 }}
|
||||||
|
animate={{ y: 0, opacity: 1 }}
|
||||||
|
exit={{ y: 15, opacity: 0 }}
|
||||||
|
transition={{ duration: 0.4, type: "spring" }}
|
||||||
|
className="absolute top-10 left-6 mt-[-13px] fill-primary dark:fill-primary-dark"
|
||||||
|
width="16"
|
||||||
|
height="13"
|
||||||
|
viewBox="0 0 16 13"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<path d="M6.26795 1C7.03775 -0.333332 8.96225 -0.333334 9.73205 0.999999L14.9282 10C15.698 11.3333 14.7358 13 13.1962 13H2.80385C1.26425 13 0.301996 11.3333 1.0718 10L6.26795 1Z" />
|
||||||
|
</motion.svg>
|
||||||
</div>
|
</div>
|
||||||
))}
|
)}
|
||||||
<svg
|
</AnimatePresence>
|
||||||
className="absolute top-0 left-6 mt-[-13px] fill-primary dark:fill-primary-dark"
|
|
||||||
width="16"
|
|
||||||
height="13"
|
|
||||||
viewBox="0 0 16 13"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
>
|
|
||||||
<path d="M6.26795 1C7.03775 -0.333332 8.96225 -0.333334 9.73205 0.999999L14.9282 10C15.698 11.3333 14.7358 13 13.1962 13H2.80385C1.26425 13 0.301996 11.3333 1.0718 10L6.26795 1Z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,14 +55,20 @@ function MenuBar({ menuItems }) {
|
|||||||
return (
|
return (
|
||||||
<div className="flex justify-between pt-5 pb-2 text-base font-body">
|
<div className="flex justify-between pt-5 pb-2 text-base font-body">
|
||||||
{menuItems.map((item, index) => (
|
{menuItems.map((item, index) => (
|
||||||
<div
|
<div
|
||||||
key={index}
|
key={index}
|
||||||
className="relative pb-3 cursor-pointer"
|
className="relative pb-3 cursor-pointer"
|
||||||
onMouseEnter={() => setActiveMenu(index)}
|
onMouseEnter={() => setActiveMenu(index)}
|
||||||
onMouseLeave={() => setActiveMenu(null)}
|
onMouseLeave={() => setActiveMenu(null)}
|
||||||
>
|
>
|
||||||
<Link to={item.path}>{t(item.name)}</Link>
|
<Link to={item.path}>{t(item.name)}</Link>
|
||||||
{item.submenu.length > 0 && <SubMenu items={item.submenu} isVisible={ activeMenu === index } onLinkClick={() => setActiveMenu(null)}/>}
|
{item.submenu.length > 0 && (
|
||||||
|
<SubMenu
|
||||||
|
items={item.submenu}
|
||||||
|
isVisible={activeMenu === index}
|
||||||
|
onLinkClick={() => setActiveMenu(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user