1- import { useState } from "react" ;
1+ import React , { useState } from "react" ;
22import { Link , useLocation } from "react-router-dom" ;
33import PropTypes from "prop-types" ;
44import Logo from "@/assets/images/logo.svg" ;
@@ -9,47 +9,60 @@ function Navbar({ links }) {
99 const [ isOpen , setIsOpen ] = useState ( false ) ;
1010 const location = useLocation ( ) ;
1111
12+ const handleLinkClick = ( ) => {
13+ setIsOpen ( false ) ;
14+ } ;
15+
1216 return (
13- < nav className = " shadow-md w-full flex justify-between items-center px-6 bg-secondary-dark" >
17+ < nav className = "shadow-md w-full flex flex-wrap justify-between items-center px-6 bg-secondary-dark relative " >
1418 < Link to = "/" className = "cursor-pointer" >
1519 < img src = { Logo } alt = "logo" />
1620 </ Link >
1721
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+
1834 < ul
1935 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" }
36+ md:flex md:items -center md:w-auto w-full md:pb-0 pb-12 md:static
37+ absolute md:bg-transparent bg-secondary-dark md:z-auto z-50 left-0
38+ transition-all duration-500 ease-in ${ isOpen ? 'top-full' : 'top-[-490px]' }
2339 ` }
2440 >
2541 { links . map ( ( link ) => (
2642 < li
2743 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- ` }
44+ className = "md:ml-8 md:my-0 my-7 font-semibold relative"
3745 >
38- < Link to = { link . path } > { link . name } </ Link >
46+ < Link
47+ to = { link . path }
48+ className = { `
49+ text-white text-center block px-3 py-2 relative
50+ after:content-[''] after:absolute after:bottom-0 after:left-0 after:w-full after:h-0.5
51+ after:bg-red-500 after:transition-all after:duration-300 after:scale-x-0 after:origin-left
52+ hover:after:scale-x-100
53+ ${
54+ location . pathname . toLowerCase ( ) . includes ( link . path . toLowerCase ( ) )
55+ ? "after:scale-x-100"
56+ : ""
57+ }
58+ ` }
59+ onClick = { handleLinkClick }
60+ >
61+ { link . name }
62+ </ Link >
3963 </ li >
4064 ) ) }
4165 </ 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 >
5366 </ nav >
5467 ) ;
5568}
@@ -59,8 +72,8 @@ Navbar.propTypes = {
5972 PropTypes . shape ( {
6073 name : PropTypes . string . isRequired ,
6174 path : PropTypes . string . isRequired ,
62- } ) ,
75+ } )
6376 ) . isRequired ,
6477} ;
6578
66- export default Navbar ;
79+ export default Navbar ;
0 commit comments