105 lines
3.4 KiB
TypeScript
105 lines
3.4 KiB
TypeScript
"use client";
|
|
|
|
import React from "react";
|
|
import { useRef } from "react";
|
|
import { useState, useEffect } from "react";
|
|
// import { useClickAway } from "react-use/lib/useClickAway";
|
|
import { AnimatePresence, motion } from "framer-motion";
|
|
import { Squash as Hamburger } from "hamburger-react";
|
|
import { menuItems } from "@/constants";
|
|
import Link from "next/link";
|
|
import { Button } from "./ui/button";
|
|
import TopNav from "./TopNav";
|
|
import { usePathname } from "next/navigation";
|
|
|
|
// import { routes } from "../routes";
|
|
|
|
export default function NavbarSm() {
|
|
const pathname = usePathname();
|
|
|
|
// useClickAway(ref, () => setOpen(false));
|
|
|
|
const [isOpen, setOpen] = useState(false);
|
|
const ref = useRef(null);
|
|
|
|
// resize
|
|
function getSize() {
|
|
return {
|
|
width: window.innerWidth,
|
|
};
|
|
}
|
|
const [windowSize, setWindowSize] = useState(getSize);
|
|
|
|
useEffect(() => {
|
|
function handleResize() {
|
|
setWindowSize(getSize());
|
|
}
|
|
|
|
window.addEventListener("resize", handleResize);
|
|
return () => window.removeEventListener("resize", handleResize);
|
|
}, [windowSize]);
|
|
|
|
return (
|
|
<>
|
|
<div
|
|
ref={ref}
|
|
className={`md:hidden w-full bg-white z-[100] flex flex-row justify-between items-center px-4
|
|
sticky top-0
|
|
shadow-md`}
|
|
>
|
|
<Hamburger toggled={isOpen} size={20} toggle={setOpen} />
|
|
|
|
{/* <Link href="/Login">
|
|
<Button className=" bg-blue hover:bg-blue/90 rounded-lg text-xs ">
|
|
ورود به پنل کاربری
|
|
</Button>
|
|
</Link> */}
|
|
{window.innerWidth <= 768 ? <TopNav /> : <></>}
|
|
|
|
<AnimatePresence>
|
|
{isOpen && (
|
|
<motion.div
|
|
initial={{ opacity: 0 }}
|
|
animate={{ opacity: 1 }}
|
|
exit={{ opacity: 0 }}
|
|
transition={{ duration: 0.2 }}
|
|
className="fixed z-[100] left-0 shadow-4xl right-0 top-[3rem] p-5 bg-gradient-to-b from-blue to-white border-b border-b-white/20"
|
|
>
|
|
<ul className="grid gap-2 ">
|
|
{menuItems.map((item, idx, array) => {
|
|
// const { Icon } = item;
|
|
const lastItem = array.length - 1;
|
|
return (
|
|
<motion.li
|
|
initial={{ scale: 0, opacity: 0 }}
|
|
animate={{ scale: 1, opacity: 1 }}
|
|
transition={{
|
|
type: "spring",
|
|
stiffness: 260,
|
|
damping: 20,
|
|
delay: 0.1 + idx / 10,
|
|
}}
|
|
key={item.name}
|
|
className=" w-full p-[0.08rem] rounded-xl bg-gradient-to-tr from-neutral-800 via-white to-neutral-700"
|
|
>
|
|
<Link
|
|
onClick={() => setOpen((prev) => !prev)}
|
|
className={`flex items-center justify-between w-full p-3 rounded-xl text-white
|
|
${lastItem === idx ? "bg-yellow" : "bg-blue"} `}
|
|
href={item.href}
|
|
>
|
|
<span className="flex gap-1 text-sm">{item.name}</span>
|
|
{/* <Icon className="text-xl" /> */}
|
|
</Link>
|
|
</motion.li>
|
|
);
|
|
})}
|
|
</ul>
|
|
</motion.div>
|
|
)}
|
|
</AnimatePresence>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|