|
1 | | -import React, { useEffect, useState } from 'react'; |
2 | | -import Link from 'next/link'; |
| 1 | +'use client' |
| 2 | + |
| 3 | +import React from 'react' |
| 4 | +import Link from 'next/link' |
| 5 | +import { Menu, X } from 'lucide-react' |
| 6 | +import { Button } from '@/components/ui/button' |
3 | 7 | import Logo from '../Logo/Logo'; |
4 | 8 |
|
5 | | -import { ABOUT, CONTACT, EVENTS, HOME } from '../../util/routeConstants'; |
6 | | -import LinkButton from '../LinkButton/LinkButton'; |
7 | | -import DropdownMenu from './DropdownMenu'; |
| 9 | +const menuItems = [ |
| 10 | + { name: 'Home', to: '/' }, |
| 11 | + { name: 'Community', to: '/community' }, |
| 12 | + { name: 'Workshops & Events', to: '/events' }, |
| 13 | + { name: 'Resources', to: '/resources' }, |
| 14 | + { name: 'Contribute', to: '/contribute' }, |
| 15 | + { name: 'About Us', to: '/about' }, |
| 16 | +] |
8 | 17 |
|
9 | | -export default function Navbar() { |
10 | | - const [screenWidth, setScreenWidth] = useState<number | null>(null); |
11 | 18 |
|
12 | | - const breakpoint = 768; |
| 19 | +export default function Navbar() { |
| 20 | + const [menuState, setMenuState] = React.useState(false) |
13 | 21 |
|
14 | | - useEffect(() => { |
15 | | - setScreenWidth(window.innerWidth); |
| 22 | + return ( |
| 23 | + <header> |
| 24 | + <nav |
| 25 | + data-state={menuState ? 'active' : undefined} |
| 26 | + className="fixed z-20 w-full border-b border-dashed bg-white backdrop-blur md:relative dark:bg-zinc-950/50 lg:dark:bg-transparent" |
| 27 | + > |
| 28 | + <div className="m-auto max-w-5xl px-6"> |
| 29 | + <div className="flex flex-wrap items-center justify-between gap-6 py-3 lg:gap-0 lg:py-4"> |
| 30 | + <div className="flex w-full justify-between lg:w-auto"> |
| 31 | + <Link href="/" aria-label="Go home" className="block"> |
| 32 | + <Logo size={60} /> |
| 33 | + </Link> |
16 | 34 |
|
17 | | - const handleResize = () => setScreenWidth(window.innerWidth); |
| 35 | + <button |
| 36 | + onClick={() => setMenuState(!menuState)} |
| 37 | + aria-label={menuState ? 'Close Menu' : 'Open Menu'} |
| 38 | + className="relative z-20 -m-2.5 -mr-4 block cursor-pointer p-2.5 lg:hidden" |
| 39 | + > |
| 40 | + <Menu |
| 41 | + className={`m-auto size-6 duration-200 ${ |
| 42 | + menuState ? 'rotate-180 scale-0 opacity-0' : '' |
| 43 | + }`} |
| 44 | + /> |
| 45 | + <X |
| 46 | + className={`absolute inset-0 m-auto size-6 duration-200 ${ |
| 47 | + menuState ? 'rotate-0 scale-100 opacity-100' : '-rotate-180 scale-0 opacity-0' |
| 48 | + }`} |
| 49 | + /> |
| 50 | + </button> |
| 51 | + </div> |
18 | 52 |
|
19 | | - window.addEventListener('resize', handleResize); |
| 53 | + <div |
| 54 | + className={`bg-background ${ |
| 55 | + menuState ? 'block' : 'hidden' |
| 56 | + } lg:flex mb-6 w-full flex-wrap items-center justify-end space-y-8 rounded-3xl border p-6 shadow-2xl shadow-zinc-300/20 md:flex-nowrap lg:m-0 lg:w-fit lg:gap-6 lg:space-y-0 lg:border-transparent lg:bg-transparent lg:p-0 lg:shadow-none dark:shadow-none dark:lg:bg-transparent`} |
| 57 | + > |
| 58 | + <div className="lg:pr-4"> |
| 59 | + <ul className="space-y-6 text-base lg:flex lg:gap-8 lg:space-y-0 lg:text-sm"> |
| 60 | + {menuItems.map((item, index) => ( |
| 61 | + <li key={index}> |
| 62 | + <Link |
| 63 | + href={item.to} |
| 64 | + className="text-black hover:text-accent-foreground block duration-150" |
| 65 | + > |
| 66 | + {item.name} |
| 67 | + </Link> |
| 68 | + </li> |
| 69 | + ))} |
| 70 | + </ul> |
| 71 | + </div> |
| 72 | + |
| 73 | + <div className="flex w-full flex-col space-y-3 sm:flex-row sm:gap-3 sm:space-y-0 md:w-fit lg:border-l lg:pl-6"> |
| 74 | + <Button asChild size="sm" className="bg-blue-600 text-white hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-600 px-4 py-2 rounded-md inline-flex justify-center"> |
| 75 | + <a href="https://bit.ly/joinreactdevske" target="_blank" |
| 76 | + rel="noopener noreferrer" |
| 77 | + > |
| 78 | + Join the Community |
| 79 | + </a> |
| 80 | + </Button> |
| 81 | + |
| 82 | + </div> |
20 | 83 |
|
21 | | - return () => window.removeEventListener('resize', handleResize); |
22 | | - }, []); |
23 | 84 |
|
24 | | - if (!screenWidth) return null; |
25 | | - return ( |
26 | | - <header className="lg:pl-[49px] fixed top-0 backdrop-blur-md w-full bg-black text-white justify-between bg-opacity-50 z-10"> |
27 | | - <nav className="nav py-2 md:py-4 md:pl-5 flex flex-row justify-between md:justify-around px-4 items-center"> |
28 | | - <div className=""> |
29 | | - <Link href={HOME}> |
30 | | - <a> |
31 | | - <Logo size={60} /> |
32 | | - </a> |
33 | | - </Link> |
34 | | - </div> |
35 | | - {screenWidth > breakpoint && ( |
36 | | - <div className=""> |
37 | | - <ul className="font-montserrat text-base text-white flex flex-row justify-between items-center md:space-x-[30px]"> |
38 | | - <a href={ABOUT}> |
39 | | - <li>About us</li> |
40 | | - </a> |
41 | | - <a href={EVENTS}> |
42 | | - <li>Events</li> |
43 | | - </a> |
44 | | - <a href={CONTACT}> |
45 | | - <li>Contact</li> |
46 | | - </a> |
47 | | - </ul> |
| 85 | + </div> |
48 | 86 | </div> |
49 | | - )} |
50 | | - {screenWidth > breakpoint && ( |
51 | | - <div> |
52 | | - <LinkButton |
53 | | - className="flex justify-center items-center bg-[#EC0505] w-[203px] h-[46px] rounded-md text-base text-white font-montserrat font-bold" |
54 | | - href="https://bit.ly/joinreactdevske" |
55 | | - target="_blank" |
56 | | - rel="noopener noreferrer" |
57 | | - > |
58 | | - Join Community |
59 | | - </LinkButton> |
60 | | - </div> |
61 | | - )} |
62 | | - {screenWidth <= breakpoint && <DropdownMenu />} |
| 87 | + </div> |
63 | 88 | </nav> |
64 | 89 | </header> |
65 | | - ); |
| 90 | + ) |
66 | 91 | } |
0 commit comments