|
1 | 1 | import DarkModeSwitch from "./DarkModeSwitch"; |
2 | 2 | import GitHub from "./ui/GitHubMark"; |
3 | | -import { Link } from "@tanstack/react-router"; |
4 | | -import { useWindowSize } from "~/hooks/useWindowSize"; |
| 3 | +import { Link, useLocation } from "@tanstack/react-router"; |
5 | 4 | import { Popover } from "radix-ui"; |
6 | 5 | import { MenuIcon, HomeIcon } from "lucide-react"; |
7 | 6 | import { Route as ProjectsRoute } from "~/routes/projects.index"; |
8 | 7 | import { Route as BlogRoute } from "~/routes/blog.index"; |
9 | 8 | import { Route as AboutRoute } from "~/routes/about"; |
10 | 9 | import { cn } from "~/utils/utils"; |
| 10 | +import { useEffect, useState } from "react"; |
11 | 11 |
|
12 | 12 | export interface NavbarProps { |
13 | 13 | height: string; |
@@ -37,142 +37,145 @@ const navStyles = { |
37 | 37 | }; |
38 | 38 |
|
39 | 39 | export default function Navbar() { |
40 | | - const { width } = useWindowSize(); |
| 40 | + const [isOpen, setIsOpen] = useState(false); |
| 41 | + const pathname = useLocation().pathname; |
| 42 | + |
| 43 | + useEffect(() => { |
| 44 | + setIsOpen(false); |
| 45 | + }, [pathname]); |
| 46 | + |
41 | 47 | return ( |
42 | 48 | <div className={navStyles.container}> |
43 | | - {width >= 768 ? ( |
44 | | - <nav |
45 | | - className={cn( |
46 | | - navStyles.nav, |
47 | | - "justify-between grid px-5 grid-cols-3 max-w-6xl" |
48 | | - )} |
| 49 | + <nav |
| 50 | + className={cn( |
| 51 | + navStyles.nav, |
| 52 | + "justify-between px-5 grid-cols-3 max-w-6xl hidden md:grid" |
| 53 | + )} |
| 54 | + > |
| 55 | + <Link |
| 56 | + to="/" |
| 57 | + activeProps={{ className: navStyles.active }} |
| 58 | + inactiveProps={{ className: navStyles.inactive }} |
| 59 | + activeOptions={{ exact: true }} |
| 60 | + className="flex cursor-pointer items-center justify-center px-1 py-0 m-0 size-[3rem] rounded-full bg-transparent shadow-none border-solid focus-visible:ring-1 focus-visible:ring-blue-500 hover:bg-gray-600/20" |
| 61 | + resetScroll |
| 62 | + aria-label="Home page link" |
49 | 63 | > |
| 64 | + <HomeIcon className="p-0" size={32} aria-label="Home icon" /> |
| 65 | + </Link> |
| 66 | + <div className="align-middle grow-0 flex px-5"> |
| 67 | + <Link |
| 68 | + to={BlogRoute.to} |
| 69 | + activeProps={{ className: navStyles.active }} |
| 70 | + inactiveProps={{ className: navStyles.inactive }} |
| 71 | + className={navStyles.button} |
| 72 | + resetScroll |
| 73 | + > |
| 74 | + Blog |
| 75 | + </Link> |
| 76 | + <Link |
| 77 | + to={ProjectsRoute.to} |
| 78 | + activeProps={{ className: navStyles.active }} |
| 79 | + inactiveProps={{ className: navStyles.inactive }} |
| 80 | + className={navStyles.button} |
| 81 | + resetScroll |
| 82 | + > |
| 83 | + Projects |
| 84 | + </Link> |
| 85 | + <Link |
| 86 | + to={AboutRoute.to} |
| 87 | + activeProps={{ className: navStyles.active }} |
| 88 | + inactiveProps={{ className: navStyles.inactive }} |
| 89 | + className={navStyles.button} |
| 90 | + resetScroll |
| 91 | + > |
| 92 | + About |
| 93 | + </Link> |
| 94 | + </div> |
| 95 | + <div className="flex items-center justify-end grow-0"> |
| 96 | + <div className="px-2"> |
| 97 | + <GitHub githubLink={"https://github.com/andrew-s28/"} /> |
| 98 | + </div> |
| 99 | + <div className="px-2"> |
| 100 | + <DarkModeSwitch /> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + </nav> |
| 104 | + <nav className={cn(navStyles.nav, "flex justify-center md:hidden")}> |
| 105 | + <div className="flex items-center justify-between w-full px-2"> |
50 | 106 | <Link |
51 | 107 | to="/" |
52 | 108 | activeProps={{ className: navStyles.active }} |
53 | 109 | inactiveProps={{ className: navStyles.inactive }} |
54 | 110 | activeOptions={{ exact: true }} |
55 | 111 | className="flex cursor-pointer items-center justify-center px-1 py-0 m-0 size-[3rem] rounded-full bg-transparent shadow-none border-solid focus-visible:ring-1 focus-visible:ring-blue-500 hover:bg-gray-600/20" |
56 | 112 | resetScroll |
57 | | - aria-label="Home page link" |
58 | 113 | > |
59 | | - <HomeIcon className="p-0" size={32} aria-label="Home icon" /> |
| 114 | + <HomeIcon className="p-0" size={32} /> |
60 | 115 | </Link> |
61 | | - <div className="align-middle grow-0 flex px-5"> |
62 | | - <Link |
63 | | - to={BlogRoute.to} |
64 | | - activeProps={{ className: navStyles.active }} |
65 | | - inactiveProps={{ className: navStyles.inactive }} |
66 | | - className={navStyles.button} |
67 | | - resetScroll |
68 | | - > |
69 | | - Blog |
70 | | - </Link> |
71 | | - <Link |
72 | | - to={ProjectsRoute.to} |
73 | | - activeProps={{ className: navStyles.active }} |
74 | | - inactiveProps={{ className: navStyles.inactive }} |
75 | | - className={navStyles.button} |
76 | | - resetScroll |
77 | | - > |
78 | | - Projects |
79 | | - </Link> |
80 | | - <Link |
81 | | - to={AboutRoute.to} |
82 | | - activeProps={{ className: navStyles.active }} |
83 | | - inactiveProps={{ className: navStyles.inactive }} |
84 | | - className={navStyles.button} |
85 | | - resetScroll |
86 | | - > |
87 | | - About |
88 | | - </Link> |
89 | | - </div> |
90 | | - <div className="flex items-center justify-end grow-0"> |
91 | | - <div className="px-2"> |
92 | | - <GitHub githubLink={"https://github.com/andrew-s28/"} /> |
93 | | - </div> |
94 | | - <div className="px-2"> |
95 | | - <DarkModeSwitch /> |
96 | | - </div> |
97 | | - </div> |
98 | | - </nav> |
99 | | - ) : ( |
100 | | - <nav className={cn(navStyles.nav, "flex justify-center")}> |
101 | | - <div className="flex items-center justify-between w-full px-2"> |
102 | | - <Link |
103 | | - to="/" |
104 | | - activeProps={{ className: navStyles.active }} |
105 | | - inactiveProps={{ className: navStyles.inactive }} |
106 | | - activeOptions={{ exact: true }} |
107 | | - className="flex cursor-pointer items-center justify-center px-1 py-0 m-0 size-[3rem] rounded-full bg-transparent shadow-none border-solid focus-visible:ring-1 focus-visible:ring-blue-500 hover:bg-gray-600/20" |
108 | | - resetScroll |
109 | | - > |
110 | | - <HomeIcon className="p-0" size={32} /> |
111 | | - </Link> |
112 | 116 |
|
113 | | - <div className="align-middle justify-center grow-0 px-4"> |
114 | | - <Popover.Root> |
115 | | - <Popover.Trigger className="flex items-center justify-center h-full cursor-pointer outline-0 focus-visible:ring-1 focus-visible:ring-blue-500"> |
116 | | - <div className="flex items-center justify-center h-full cursor-pointer outline-0 focus-visible:ring-1 focus-visible:ring-blue-500"> |
117 | | - <MenuIcon className="w-full" size={32} /> |
118 | | - <span className="sr-only">Toggle menu</span> |
119 | | - </div> |
120 | | - </Popover.Trigger> |
121 | | - <Popover.Portal> |
122 | | - <Popover.Content |
123 | | - className="w-64 bg-dawn-pink-100 dark:bg-night-sky-950 p-2 rounded-lg shadow-xl z-50 border-night-sky-950 dark:border-dawn-pink-100 border-2" |
124 | | - sideOffset={5} |
125 | | - > |
126 | | - <div className="flex flex-col space-y-1"> |
127 | | - <Link |
128 | | - to={BlogRoute.to} |
129 | | - className="px-4 py-2 hover:bg-muted rounded-md text-center" |
130 | | - activeProps={{ |
131 | | - className: |
132 | | - "font-bold bg-dawn-pink-300 dark:bg-night-sky-900", |
133 | | - }} |
134 | | - resetScroll |
135 | | - > |
136 | | - Blog |
137 | | - </Link> |
138 | | - <Link |
139 | | - to={ProjectsRoute.to} |
140 | | - className="px-4 py-2 hover:bg-muted rounded-md text-center" |
141 | | - activeProps={{ |
142 | | - className: |
143 | | - "font-bold bg-dawn-pink-300 dark:bg-night-sky-900", |
144 | | - }} |
145 | | - resetScroll |
146 | | - > |
147 | | - Projects |
148 | | - </Link> |
149 | | - <Link |
150 | | - to={AboutRoute.to} |
151 | | - className="px-4 py-2 hover:bg-muted rounded-md text-center" |
152 | | - activeProps={{ |
153 | | - className: |
154 | | - "font-bold bg-dawn-pink-300 dark:bg-night-sky-900", |
155 | | - }} |
156 | | - resetScroll |
157 | | - > |
158 | | - About |
159 | | - </Link> |
160 | | - <div className="px-2 flex items-center justify-center"> |
161 | | - <GitHub githubLink={"https://github.com/andrew-s28/"} /> |
162 | | - <DarkModeSwitch /> |
163 | | - </div> |
| 117 | + <div className="align-middle justify-center grow-0 px-4"> |
| 118 | + <Popover.Root open={isOpen} onOpenChange={setIsOpen}> |
| 119 | + <Popover.Trigger className="flex items-center justify-center h-full cursor-pointer outline-0 focus-visible:ring-1 focus-visible:ring-blue-500"> |
| 120 | + <div className="flex items-center justify-center h-full cursor-pointer outline-0 focus-visible:ring-1 focus-visible:ring-blue-500"> |
| 121 | + <MenuIcon className="w-full" size={32} /> |
| 122 | + <span className="sr-only">Toggle menu</span> |
| 123 | + </div> |
| 124 | + </Popover.Trigger> |
| 125 | + <Popover.Portal> |
| 126 | + <Popover.Content |
| 127 | + className="w-64 bg-dawn-pink-100 dark:bg-night-sky-950 p-2 rounded-lg shadow-xl z-50 border-night-sky-950 dark:border-dawn-pink-100 border-2" |
| 128 | + sideOffset={5} |
| 129 | + > |
| 130 | + <div className="flex flex-col space-y-1"> |
| 131 | + <Link |
| 132 | + to={BlogRoute.to} |
| 133 | + className="px-4 py-2 hover:bg-muted rounded-md text-center" |
| 134 | + activeProps={{ |
| 135 | + className: |
| 136 | + "font-bold bg-dawn-pink-300 dark:bg-night-sky-900", |
| 137 | + }} |
| 138 | + resetScroll |
| 139 | + > |
| 140 | + Blog |
| 141 | + </Link> |
| 142 | + <Link |
| 143 | + to={ProjectsRoute.to} |
| 144 | + className="px-4 py-2 hover:bg-muted rounded-md text-center" |
| 145 | + activeProps={{ |
| 146 | + className: |
| 147 | + "font-bold bg-dawn-pink-300 dark:bg-night-sky-900", |
| 148 | + }} |
| 149 | + resetScroll |
| 150 | + > |
| 151 | + Projects |
| 152 | + </Link> |
| 153 | + <Link |
| 154 | + to={AboutRoute.to} |
| 155 | + className="px-4 py-2 hover:bg-muted rounded-md text-center" |
| 156 | + activeProps={{ |
| 157 | + className: |
| 158 | + "font-bold bg-dawn-pink-300 dark:bg-night-sky-900", |
| 159 | + }} |
| 160 | + resetScroll |
| 161 | + > |
| 162 | + About |
| 163 | + </Link> |
| 164 | + <div className="px-2 flex items-center justify-center"> |
| 165 | + <GitHub githubLink={"https://github.com/andrew-s28/"} /> |
| 166 | + <DarkModeSwitch /> |
164 | 167 | </div> |
165 | | - <Popover.Arrow |
166 | | - height={10} |
167 | | - className="dark:fill-dawn-pink-100 fill-night-sky-950" |
168 | | - /> |
169 | | - </Popover.Content> |
170 | | - </Popover.Portal> |
171 | | - </Popover.Root> |
172 | | - </div> |
| 168 | + </div> |
| 169 | + <Popover.Arrow |
| 170 | + height={10} |
| 171 | + className="dark:fill-dawn-pink-100 fill-night-sky-950" |
| 172 | + /> |
| 173 | + </Popover.Content> |
| 174 | + </Popover.Portal> |
| 175 | + </Popover.Root> |
173 | 176 | </div> |
174 | | - </nav> |
175 | | - )} |
| 177 | + </div> |
| 178 | + </nav> |
176 | 179 | </div> |
177 | 180 | ); |
178 | 181 | } |
0 commit comments