|
1 | | -// import React from 'react'; |
2 | | -import { Link } from "react-router-dom"; |
3 | | -// import { Bars3BottomRightIcon, XMarkIcon } from "@heroicons/react/24/solid"; |
4 | 1 | import { useState } from "react"; |
| 2 | +import { Link, useLocation } from "react-router-dom"; |
| 3 | +import PropTypes from "prop-types"; |
5 | 4 | import Logo from "@/assets/images/logo.svg"; |
| 5 | +import closeIcon from "@/assets/images/close.svg"; |
| 6 | +import menuIcon from "@/assets/images/menu.svg"; |
| 7 | + |
| 8 | +function Navbar({ links }) { |
| 9 | + const [isOpen, setIsOpen] = useState(false); |
| 10 | + const location = useLocation(); |
6 | 11 |
|
7 | | -const links = [ |
8 | | - { name: "About Us", path: "#" }, |
9 | | - { name: "Our Team", path: "#" }, |
10 | | - { name: "Gallery", path: "#" }, |
11 | | - { name: "Contact", path: "#" }, |
12 | | - { name: "Projects", path: "#" }, |
13 | | -]; |
14 | | -function Header () { |
15 | | - const [activeLink, setActiveLink] = useState(null); |
16 | | -// const [isOpen, _ ] = useState(false); |
17 | 12 | return ( |
18 | | - <div className="shadow-md w-full fixed top-0 left-0"> |
19 | | - <div className="md:px-10 py-4 px-7 md:flex justify-between items-center bg-black "> |
20 | | - <div className="flex text-2x1 cursor-pointer items-center gap-2"> |
21 | | - {/* <logo/> */} |
22 | | - <img src={Logo} alt="logo" className="w-22 h-22" /> |
23 | | - </div> |
24 | | - |
25 | | - <Link |
26 | | - to='/' |
27 | | - className="w-7 h-7 text-white absolute right-8 top-6 cursor-pointer md:hidden" |
28 | | - > |
29 | | - {/* {isOpen ? <XMarkIcon /> : <Bars3BottomRightIcon />} */} |
30 | | - </Link> |
31 | | - |
32 | | - <ul |
33 | | - className={`md:flex md:items-center md:pb-0 pb-12 absolute md:static md:z-auto z-[-1] left-0 w-full md:w-auto md:pl-0 pl-9 transition-all duration-500 ease-in `} |
34 | | - > |
35 | | - {links.map((link, index) => ( |
36 | | - <li |
37 | | - key={link.name} |
38 | | - className={`font-semibold my-7 md:my-0 md:ml-8 ${activeLink === index ? "hover:border-b-2 border-red-500" : ""}`} |
39 | | - > |
40 | | - <Link to={link.path} className="hover:border-b-2 border-white transition-all duration-300 ease-in-out" onClick={() => setActiveLink(index)}>{link.name}</Link> |
41 | | - </li> |
42 | | - |
43 | | - |
44 | | - ))} |
45 | | - </ul> |
46 | | - </div> |
47 | | - </div> |
| 13 | + <nav className=" shadow-md w-full flex justify-between items-center px-6 bg-secondary-dark"> |
| 14 | + <Link to="/" className="cursor-pointer"> |
| 15 | + <img src={Logo} alt="logo" /> |
| 16 | + </Link> |
| 17 | + |
| 18 | + <ul |
| 19 | + className={` |
| 20 | + md:flex pl-0 justify-start md:justify-center md:items-center md:pb-0 md:z-auto left-0 |
| 21 | + transition-all duration-500 ease-in |
| 22 | + ${isOpen ? "flex flex-col " : "hidden"} |
| 23 | + `} |
| 24 | + > |
| 25 | + {links.map((link) => ( |
| 26 | + <li |
| 27 | + key={link.name} |
| 28 | + className={` |
| 29 | + font-semibold text-white md:my-0 md:ml-8 |
| 30 | + border-b-2 |
| 31 | + ${ |
| 32 | + location.pathname .toLowerCase().includes(link.path.toLowerCase()) |
| 33 | + ? "border-red-500 hover:border-red-700" |
| 34 | + : "border-transparent hover:border-red-500" |
| 35 | + } |
| 36 | + `} |
| 37 | + > |
| 38 | + <Link to={link.path}>{link.name}</Link> |
| 39 | + </li> |
| 40 | + ))} |
| 41 | + </ul> |
| 42 | + <button |
| 43 | + type="button" |
| 44 | + onClick={() => setIsOpen(!isOpen)} |
| 45 | + className="w-7 h-7 text-white cursor-pointer md:hidden" |
| 46 | + > |
| 47 | + {isOpen ? ( |
| 48 | + <img src={closeIcon} alt="close" /> |
| 49 | + ) : ( |
| 50 | + <img src={menuIcon} alt="menu" /> |
| 51 | + )} |
| 52 | + </button> |
| 53 | + </nav> |
48 | 54 | ); |
| 55 | +} |
| 56 | + |
| 57 | +Navbar.propTypes = { |
| 58 | + links: PropTypes.arrayOf( |
| 59 | + PropTypes.shape({ |
| 60 | + name: PropTypes.string.isRequired, |
| 61 | + path: PropTypes.string.isRequired, |
| 62 | + }), |
| 63 | + ).isRequired, |
49 | 64 | }; |
50 | 65 |
|
51 | | -export default Header; |
| 66 | +export default Navbar; |
0 commit comments