|
1 | | -import { useState } from "react"; |
| 1 | +import { useState, useContext } 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"; |
7 | 8 |
|
8 | 9 | function Navbar({ links }) { |
9 | 10 | const [isOpen, setIsOpen] = useState(false); |
10 | 11 | const location = useLocation(); |
11 | 12 |
|
| 13 | + const { setCursorVariantNone, setCursorVariantDefault } = |
| 14 | + useContext(CursorVariantContext); |
| 15 | + |
12 | 16 | const handleLinkClick = () => { |
13 | 17 | setIsOpen(false); |
14 | 18 | }; |
15 | 19 |
|
16 | 20 | return ( |
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 | | - |
| 21 | + <nav |
| 22 | + 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`} |
| 23 | + > |
| 24 | + <div className="flex flex-row justify-between xs:w-full md:w-auto items-center"> |
| 25 | + <Link |
| 26 | + to="/" |
| 27 | + className="cursor-pointer" |
| 28 | + onMouseEnter={setCursorVariantNone} |
| 29 | + onMouseLeave={setCursorVariantDefault} |
| 30 | + > |
| 31 | + <img src={Logo} className="w-[10rem]" alt="logo" /> |
| 32 | + </Link> |
| 33 | + <button |
| 34 | + type="button" |
| 35 | + onClick={() => setIsOpen(!isOpen)} |
| 36 | + className="w-7 h-7 text-white cursor-pointer md:hidden" |
| 37 | + > |
| 38 | + {isOpen ? ( |
| 39 | + <img src={closeIcon} alt="close" /> |
| 40 | + ) : ( |
| 41 | + <img src={menuIcon} alt="menu" /> |
| 42 | + )} |
| 43 | + </button> |
| 44 | + </div> |
34 | 45 | <ul |
35 | 46 | className={` |
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]" } |
| 47 | + 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 |
| 48 | + ${isOpen ? "flex flex-col grow" : "hidden"} |
40 | 49 | `} |
| 50 | + onMouseEnter={setCursorVariantNone} |
| 51 | + onMouseLeave={setCursorVariantDefault} |
41 | 52 | > |
42 | 53 | {links.map((link) => ( |
43 | 54 | <li |
44 | 55 | key={link.name} |
45 | | - className="md:ml-8 md:my-0 my-7 font-semibold relative" |
| 56 | + className={` |
| 57 | + group font-regular text-white text-center md:my-0 md:ml-8 transition-all hover:text-primary |
| 58 | + `} |
46 | 59 | > |
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 | | - > |
| 60 | + <Link to={link.path} onClick={handleLinkClick}> |
64 | 61 | {link.name} |
65 | 62 | </Link> |
| 63 | + <span |
| 64 | + className={`block group-hover:max-w-full transition-all duration-500 h-0.5 bg-primary rounded ${ |
| 65 | + location.pathname |
| 66 | + .toLowerCase() |
| 67 | + .includes(link.path.toLowerCase()) |
| 68 | + ? "w-full" |
| 69 | + : "max-w-0" |
| 70 | + }`} |
| 71 | + ></span> |
66 | 72 | </li> |
67 | 73 | ))} |
68 | 74 | </ul> |
|
0 commit comments