|
1 | | -import { useState, useContext } from "react"; |
| 1 | +import { useState } from "react"; |
2 | 2 | import { Link, useLocation } from "react-router-dom"; |
3 | 3 | import PropTypes from "prop-types"; |
4 | 4 | import Logo from "@/assets/images/logo.svg"; |
5 | 5 | import closeIcon from "@/assets/images/close.svg"; |
6 | 6 | import menuIcon from "@/assets/images/menu.svg"; |
7 | | -import { CursorVariantContext } from "@/context/CursorVariantProvider"; |
8 | 7 |
|
9 | 8 | function Navbar({ links }) { |
10 | 9 | const [isOpen, setIsOpen] = useState(false); |
11 | 10 | const location = useLocation(); |
12 | 11 |
|
13 | | - const { setCursorVariantNone, setCursorVariantDefault } = |
14 | | - useContext(CursorVariantContext); |
| 12 | + const handleLinkClick = () => { |
| 13 | + setIsOpen(false); |
| 14 | + }; |
15 | 15 |
|
16 | 16 | return ( |
17 | | - <nav |
18 | | - className={`shadow-md w-full flex xs:flex-col md:flex-row ${isOpen ? "xs:h-screen" : ""} md:h-full justify-between items-center px-6 bg-secondary-dark`} |
19 | | - > |
20 | | - <div className="flex flex-row justify-between xs:w-full md:w-auto items-center"> |
21 | | - <Link |
22 | | - to="/" |
23 | | - className="cursor-pointer" |
24 | | - onMouseEnter={setCursorVariantNone} |
25 | | - onMouseLeave={setCursorVariantDefault} |
26 | | - > |
27 | | - <img src={Logo} className="w-[10rem]" alt="logo" /> |
28 | | - </Link> |
29 | | - <button |
30 | | - type="button" |
31 | | - onClick={() => setIsOpen(!isOpen)} |
32 | | - className="w-7 h-7 text-white cursor-pointer md:hidden" |
33 | | - > |
34 | | - {isOpen ? ( |
35 | | - <img src={closeIcon} alt="close" /> |
36 | | - ) : ( |
37 | | - <img src={menuIcon} alt="menu" /> |
38 | | - )} |
39 | | - </button> |
40 | | - </div> |
| 17 | + <nav className="shadow-md w-full flex flex-wrap justify-between items-center px-6 bg-secondary-dark relative"> |
| 18 | + <Link to="/" className="cursor-pointer"> |
| 19 | + <img src={Logo} alt="logo" /> |
| 20 | + </Link> |
| 21 | + |
| 22 | + <button |
| 23 | + type="button" |
| 24 | + onClick={() => setIsOpen(!isOpen)} |
| 25 | + className="w-7 h-7 text-white cursor-pointer md:hidden" |
| 26 | + > |
| 27 | + {isOpen ? ( |
| 28 | + <img src={closeIcon} alt="close" /> |
| 29 | + ) : ( |
| 30 | + <img src={menuIcon} alt="menu" /> |
| 31 | + )} |
| 32 | + </button> |
| 33 | + |
41 | 34 | <ul |
42 | 35 | className={` |
43 | | - md:flex pl-0 justify-start md:justify-center md:items-center md:pb-0 md:z-auto left-0 xs:justify-center xs:gap-y-12 |
44 | | - ${isOpen ? "flex flex-col grow" : "hidden"} |
| 36 | + pl-0 justify-start md:justify-center |
| 37 | + md:flex md:items-center md:w-auto w-full md:pb-0 pb-12 md:static |
| 38 | + absolute md:bg-transparent bg-secondary-dark md:z-auto z-50 left-0 |
| 39 | + transition-all duration-500 ease-in ${isOpen ? "top-full" : "top-[-490px]" } |
45 | 40 | `} |
46 | | - onMouseEnter={setCursorVariantNone} |
47 | | - onMouseLeave={setCursorVariantDefault} |
48 | 41 | > |
49 | 42 | {links.map((link) => ( |
50 | 43 | <li |
51 | 44 | key={link.name} |
52 | | - className={` |
53 | | - group font-regular text-white md:my-0 md:ml-8 transition-all hover:text-primary |
54 | | - `} |
| 45 | + className="md:ml-8 md:my-0 my-7 font-semibold relative" |
55 | 46 | > |
56 | | - <Link to={link.path}>{link.name}</Link> |
57 | | - <span |
58 | | - className={`block group-hover:max-w-full transition-all duration-500 h-0.5 bg-primary rounded ${ |
59 | | - location.pathname |
60 | | - .toLowerCase() |
61 | | - .includes(link.path.toLowerCase()) |
62 | | - ? "w-full" |
63 | | - : "max-w-0" |
64 | | - }`} |
65 | | - /> |
| 47 | + <Link |
| 48 | + to={link.path} |
| 49 | + className={` |
| 50 | + text-white text-center block px-3 py-2 relative |
| 51 | + after:content-[''] after:absolute after:bottom-0 after:left-0 after:w-full after:h-0.5 |
| 52 | + after:bg-red-500 after:transition-all after:duration-300 after:scale-x-0 after:origin-left |
| 53 | + hover:after:scale-x-100 |
| 54 | + ${ |
| 55 | + location.pathname |
| 56 | + .toLowerCase() |
| 57 | + .includes(link.path.toLowerCase()) |
| 58 | + ? "w-full" |
| 59 | + : "max-w-0" |
| 60 | + } |
| 61 | + `} |
| 62 | + onClick={handleLinkClick} |
| 63 | + > |
| 64 | + {link.name} |
| 65 | + </Link> |
66 | 66 | </li> |
67 | 67 | ))} |
68 | 68 | </ul> |
|
0 commit comments