|
1 | 1 | import { Link } from "react-router-dom";
|
2 |
| -import React, { useContext } from "react"; |
| 2 | +import React, { useContext, useState } from "react"; |
| 3 | +import ReactDOM from "react-dom"; |
| 4 | + |
| 5 | +import HamburgerMenu from "../../Assets/Icons/hamburger-menu.svg"; |
| 6 | +import MobileMenu from "../MobileMenu/MobileMenu"; |
3 | 7 |
|
4 | 8 | import AuthContext from "../../Contexts/AuthContext";
|
5 | 9 |
|
6 | 10 | const Navbar = () => {
|
7 | 11 | const authCtx = useContext(AuthContext);
|
| 12 | + const [showMenu, setShowMenu] = useState(false); |
8 | 13 |
|
9 | 14 | return (
|
10 |
| - <nav className="bg-black-light z-10 w-full py-2 flex flex-row items-center sticky top-0 justify-between shadow-md"> |
11 |
| - <Link |
12 |
| - to="/" |
13 |
| - className="bg-red-primary block no-underline rounded-r-full w-fit pl-12 pr-6 py-2" |
14 |
| - > |
15 |
| - <img |
16 |
| - src="/background/headericon.png" |
17 |
| - className="h-[30px] w-auto" |
18 |
| - alt="icon" |
19 |
| - /> |
20 |
| - </Link> |
21 |
| - <div className="flex flex-row gap-12 pr-12 items-center"> |
22 |
| - <div className="flex flex-row gap-5"> |
23 |
| - <Link |
24 |
| - className="text-gray-300 hover:text-white hover:underline transition-all duration-150" |
25 |
| - to="/" |
26 |
| - > |
27 |
| - Beranda |
28 |
| - </Link> |
29 |
| - <Link |
30 |
| - className="text-gray-300 hover:text-white hover:underline transition-all duration-150" |
31 |
| - to="/competition" |
32 |
| - > |
33 |
| - Kompetisi |
34 |
| - </Link> |
35 |
| - <Link |
36 |
| - className="text-gray-300 hover:text-white hover:underline transition-all duration-150" |
37 |
| - to="/team" |
38 |
| - > |
39 |
| - Tim |
40 |
| - </Link> |
41 |
| - <Link |
42 |
| - className="text-gray-300 hover:text-white hover:underline transition-all duration-150" |
43 |
| - to="/settings" |
44 |
| - > |
45 |
| - Setting |
46 |
| - </Link> |
| 15 | + <> |
| 16 | + {showMenu && |
| 17 | + ReactDOM.createPortal( |
| 18 | + <MobileMenu setShowMenu={setShowMenu} />, |
| 19 | + document.getElementById("mobile-menu") |
| 20 | + )} |
| 21 | + <nav className="bg-black-light z-10 w-full py-2 flex flex-row items-center sticky top-0 justify-between shadow-md"> |
| 22 | + <div |
| 23 | + onClick={() => setShowMenu((prev) => !prev)} |
| 24 | + className="bg-red-primary no-underline cursor-pointer rounded-r-full w-fit pl-4 xs:pl-12 pr-6 py-2 block sm:hidden" |
| 25 | + > |
| 26 | + <img src={HamburgerMenu} alt="menu" className="w-8 h-auto" /> |
47 | 27 | </div>
|
48 |
| - <div className="flex flex-row gap-5 items-center"> |
49 |
| - {authCtx.userData ? ( |
50 |
| - <> |
51 |
| - <Link |
52 |
| - className="font-bold text-white hover:underline transition-all duration-150" |
53 |
| - to="/settings" |
54 |
| - > |
55 |
| - {authCtx.userData.name} |
56 |
| - </Link> |
57 |
| - <p |
58 |
| - className="font-bold text-white hover:underline transition-all duration-150" |
59 |
| - onClick={() => authCtx.logout()} |
60 |
| - > |
61 |
| - Logout |
62 |
| - </p> |
63 |
| - </> |
64 |
| - ) : ( |
65 |
| - <> |
66 |
| - <Link |
67 |
| - className="font-bold text-white hover:underline transition-all duration-150" |
68 |
| - to="/" |
69 |
| - > |
70 |
| - Akun |
71 |
| - </Link> |
72 |
| - <Link |
73 |
| - className="font-bold transition-all duration-150 bg-red-primary text-white border-2 border-transparent hover:bg-red-700 hover:border-red-primary-semibold block px-5 py-1 rounded-full" |
74 |
| - to="/login" |
75 |
| - > |
76 |
| - Login |
77 |
| - </Link> |
78 |
| - </> |
79 |
| - )} |
| 28 | + <Link |
| 29 | + to="/" |
| 30 | + className="bg-red-primary no-underline rounded-r-full w-fit pl-4 xs:pl-12 pr-6 py-2 hidden sm:block" |
| 31 | + > |
| 32 | + <img |
| 33 | + src="/background/headericon.png" |
| 34 | + className="h-[30px] w-auto" |
| 35 | + alt="icon" |
| 36 | + /> |
| 37 | + </Link> |
| 38 | + <div className="flex flex-row gap-12 pr-12 items-center "> |
| 39 | + <div className="hidden sm:flex flex-row gap-5 "> |
| 40 | + <Link |
| 41 | + className="text-gray-300 hover:text-white hover:underline transition-all duration-150" |
| 42 | + to="/" |
| 43 | + > |
| 44 | + Beranda |
| 45 | + </Link> |
| 46 | + <Link |
| 47 | + className="text-gray-300 hover:text-white hover:underline transition-all duration-150" |
| 48 | + to="/competition" |
| 49 | + > |
| 50 | + Kompetisi |
| 51 | + </Link> |
| 52 | + <Link |
| 53 | + className="text-gray-300 hover:text-white hover:underline transition-all duration-150" |
| 54 | + to="/team" |
| 55 | + > |
| 56 | + Tim |
| 57 | + </Link> |
| 58 | + <Link |
| 59 | + className="text-gray-300 hover:text-white hover:underline transition-all duration-150" |
| 60 | + to="/settings" |
| 61 | + > |
| 62 | + Settings |
| 63 | + </Link> |
| 64 | + </div> |
| 65 | + <div className="hidden sm:flex flex-row gap-5 items-center"> |
| 66 | + {authCtx.userData ? ( |
| 67 | + <> |
| 68 | + <Link |
| 69 | + className="font-bold text-white hover:underline transition-all duration-150" |
| 70 | + to="/settings" |
| 71 | + > |
| 72 | + {authCtx.userData.name} |
| 73 | + </Link> |
| 74 | + <p |
| 75 | + className="font-bold text-white hover:underline transition-all duration-150" |
| 76 | + onClick={() => authCtx.logout()} |
| 77 | + > |
| 78 | + Logout |
| 79 | + </p> |
| 80 | + </> |
| 81 | + ) : ( |
| 82 | + <> |
| 83 | + <Link |
| 84 | + className="font-bold text-white hover:underline transition-all duration-150" |
| 85 | + to="/" |
| 86 | + > |
| 87 | + Akun |
| 88 | + </Link> |
| 89 | + <Link |
| 90 | + className="font-bold transition-all duration-150 bg-red-primary text-white border-2 border-transparent hover:bg-red-700 hover:border-red-primary-semibold block px-5 py-1 rounded-full" |
| 91 | + to="/login" |
| 92 | + > |
| 93 | + Login |
| 94 | + </Link> |
| 95 | + </> |
| 96 | + )} |
| 97 | + </div> |
80 | 98 | </div>
|
81 |
| - </div> |
82 |
| - </nav> |
| 99 | + </nav> |
| 100 | + </> |
83 | 101 | );
|
84 | 102 | };
|
85 | 103 |
|
|
0 commit comments