Repository navigation
Expand file tree
/
Copy pathAppHeader.tsx
More file actions
452 lines (435 loc) · 15 KB
/
Copy pathAppHeader.tsx
File metadata and controls
452 lines (435 loc) · 15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
import { useState } from 'react';
import { Link, NavLink, useLocation } from 'react-router';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import {
Sheet,
SheetContent,
SheetDescription,
SheetHeader,
SheetTitle,
SheetTrigger,
} from '@/components/ui/sheet';
import { Separator } from '@/components/ui/separator';
import { SearchBox } from '@/components/SearchBox';
import { GitHubIcon } from '@/components/icons/GitHubIcon';
import { SlackIcon } from '@/components/icons/SlackIcon';
import { useAuth } from '@/hooks/useAuth';
const GITHUB_URL = 'https://github.com/CodeForPhilly';
function ChevronDownIcon() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<polyline points="6 9 12 15 18 9" />
</svg>
);
}
function MenuIcon() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<line x1="4" y1="12" x2="20" y2="12" />
<line x1="4" y1="6" x2="20" y2="6" />
<line x1="4" y1="18" x2="20" y2="18" />
</svg>
);
}
function AuthControls({ mobile = false }: { mobile?: boolean }) {
const { person, loading, signOut } = useAuth();
if (loading) {
return (
<div
className={`h-8 ${mobile ? 'w-full' : 'w-20'} bg-muted animate-pulse rounded`}
aria-hidden="true"
/>
);
}
if (!person) {
return (
<Button asChild size={mobile ? 'default' : 'sm'} className={mobile ? 'w-full' : ''}>
<Link to="/login">Sign in</Link>
</Button>
);
}
const avatarLetter = person.fullName.charAt(0).toUpperCase();
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="sm"
className={`flex items-center gap-2 ${mobile ? 'w-full justify-start' : ''}`}
aria-label={`Account menu for ${person.fullName}`}
>
{person.avatarUrl ? (
<img
src={person.avatarUrl}
alt=""
className="w-6 h-6 rounded-full"
/>
) : (
<span className="w-6 h-6 rounded-full bg-primary text-primary-foreground text-xs flex items-center justify-center">
{avatarLetter}
</span>
)}
<span className="hidden sm:inline">{person.fullName}</span>
<ChevronDownIcon />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem asChild>
<Link to={`/members/${person.slug}`}>My profile</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link to="/account">Account settings</Link>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem asChild>
<Link to={`/projects?memberSlug=${person.slug}`}>My projects</Link>
</DropdownMenuItem>
<DropdownMenuSeparator />
{(person.accountLevel === 'staff' ||
person.accountLevel === 'administrator') && (
<>
<DropdownMenuItem asChild>
<Link to="/tags?staff=true">Manage tags</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link to="/admin/members">Members roster</Link>
</DropdownMenuItem>
<DropdownMenuItem disabled>Recent staff actions</DropdownMenuItem>
<DropdownMenuSeparator />
</>
)}
{person.accountLevel === 'administrator' && (
<>
<DropdownMenuItem asChild>
<Link to="/members?staff=true&accountLevel=all">
Manage members
</Link>
</DropdownMenuItem>
<DropdownMenuSeparator />
</>
)}
<DropdownMenuItem onClick={() => void signOut()}>
Sign out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}
function AboutDropdown() {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
{/* No aria-label: the visible "About" text is the accessible name. */}
<Button variant="ghost" size="sm" className="flex items-center gap-1">
About <ChevronDownIcon />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem asChild>
<Link to="/pages/mission">Mission</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link to="/pages/leadership">Leadership</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link to="/pages/code-of-conduct">Code of Conduct</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link to="/pages/hackathons">Hackathons</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link to="/sponsor">Sponsor</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<a href="mailto:hello@codeforphilly.org">Contact</a>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}
// `block` so each link fills its row: inside the sheet's <li>s an inline
// anchor would shrink the tap target to the width of its text.
const navLinkClass = ({ isActive }: { isActive: boolean }) =>
`block text-sm font-medium transition-colors hover:text-primary ${
isActive ? 'text-primary' : 'text-muted-foreground'
}`;
function SlackLink() {
return (
// A plain anchor: /chat is a server redirect the router can't resolve
// (specs/screens/chat.md).
<Button asChild variant="ghost" size="icon-sm">
<a
href="/chat"
target="_blank"
rel="noopener noreferrer"
aria-label="Join Code for Philly on Slack (opens in new tab)"
>
<SlackIcon />
</a>
</Button>
);
}
function GitHubLink() {
return (
<Button asChild variant="ghost" size="icon-sm">
<a
href={GITHUB_URL}
target="_blank"
rel="noopener noreferrer"
aria-label="Code for Philly on GitHub (opens in new tab)"
>
<GitHubIcon />
</a>
</Button>
);
}
export function AppHeader() {
const location = useLocation();
// The sheet is open only for the location it was opened at, so any
// client-side navigation — a NavLink or Enter in the inline search —
// closes it without per-item onClick closers. Derived during render
// rather than synced in an effect (react-hooks/set-state-in-effect).
const [openedAtKey, setOpenedAtKey] = useState<string | null>(null);
const mobileOpen = openedAtKey === location.key;
const setMobileOpen = (open: boolean) =>
setOpenedAtKey(open ? location.key : null);
return (
<header className="sticky top-0 z-40 w-full border-b border-border bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 shadow-sm print:hidden">
<div className="container mx-auto flex h-14 items-center px-4 gap-4">
{/* Wordmark — always visible. The horizontal lockup includes
the icon + text, so no separate text node is needed. */}
<Link
to="/"
className="flex items-center shrink-0"
aria-label="Code for Philly home"
>
<img
src="/img/logo-horizontal.svg"
alt="Code for Philly"
className="h-12 w-auto"
/>
</Link>
{/* Desktop content cluster. The parent gap is the only source of
spacing between children — no per-child margins. */}
{/* A nav is a list of destinations — the <ul>/<li> is what tells a
screen reader how many there are and where you are in them. The
flex/gap spacing moves to the <ul>; the <li>s contribute none. */}
<nav
aria-label="Primary navigation"
className="hidden lg:block ml-4 flex-1"
>
<ul className="flex items-center gap-2">
<li>
<NavLink to="/projects" className={navLinkClass}>
Projects
</NavLink>
</li>
<li>
<NavLink to="/events" className={navLinkClass}>
Events
</NavLink>
</li>
<li>
<NavLink to="/help-wanted" className={navLinkClass}>
Help Wanted
</NavLink>
</li>
<li>
<NavLink to="/members" className={navLinkClass}>
Members
</NavLink>
</li>
<li>
<AboutDropdown />
</li>
</ul>
</nav>
{/* Desktop utility cluster: Slack, GitHub, search, auth, then the Volunteer
CTA pinned rightmost (specs/behaviors/app-shell.md). */}
<nav
aria-label="Utility"
className="hidden lg:flex items-center gap-2 ml-auto"
>
<SlackLink />
<GitHubLink />
<SearchBox />
<AuthControls />
<Button
asChild
size="sm"
className="bg-green-600 hover:bg-green-700 text-white"
>
<NavLink to="/volunteer">Volunteer</NavLink>
</Button>
</nav>
{/* Mobile: auth + hamburger */}
<div className="flex lg:hidden items-center gap-2 ml-auto">
<AuthControls />
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
<SheetTrigger asChild>
{/* No aria-expanded here — Radix's Dialog.Trigger supplies it. */}
<Button
variant="ghost"
size="sm"
aria-label="Open navigation menu"
>
<MenuIcon />
</Button>
</SheetTrigger>
<SheetContent side="right">
{/* SheetHeader/SheetTitle carry the panel's own padding and give
the underlying Radix dialog its accessible name; the
visually-hidden description satisfies aria-describedby. */}
<SheetHeader className="pb-0">
<SheetTitle>Menu</SheetTitle>
<SheetDescription className="sr-only">
Site navigation
</SheetDescription>
</SheetHeader>
{/* min-h-0 + overflow-y-auto so the list stays reachable on
short viewports instead of overflowing the panel. */}
{/* Three lists with the separators and the group heading
between them, rather than one list interrupted by
non-list children. The nav keeps the flex column so the
gap-2 rhythm between groups is unchanged. */}
<nav
aria-label="Mobile navigation"
className="flex flex-col gap-2 px-4 min-h-0 overflow-y-auto"
>
<ul className="flex flex-col gap-2">
<li>
<NavLink to="/projects" className={navLinkClass}>
Projects
</NavLink>
</li>
<li>
<NavLink to="/events" className={navLinkClass}>
Events
</NavLink>
</li>
<li>
<NavLink to="/help-wanted" className={navLinkClass}>
Help Wanted
</NavLink>
</li>
<li>
<NavLink to="/members" className={navLinkClass}>
Members
</NavLink>
</li>
</ul>
<Separator />
{/* SheetTitle ("Menu") renders a Radix DialogTitle, i.e. an
h2 — so this group label is an h3, not a styled <p>. */}
<h3 className="text-xs text-muted-foreground font-medium uppercase tracking-wide">
About
</h3>
<ul className="flex flex-col gap-2">
<li>
<NavLink to="/pages/mission" className={navLinkClass}>
Mission
</NavLink>
</li>
<li>
<NavLink to="/pages/leadership" className={navLinkClass}>
Leadership
</NavLink>
</li>
<li>
<NavLink to="/pages/code-of-conduct" className={navLinkClass}>
Code of Conduct
</NavLink>
</li>
<li>
<NavLink to="/pages/hackathons" className={navLinkClass}>
Hackathons
</NavLink>
</li>
<li>
<NavLink to="/sponsor" className={navLinkClass}>
Sponsor
</NavLink>
</li>
<li>
<a
href="mailto:hello@codeforphilly.org"
className="block text-sm font-medium text-muted-foreground hover:text-primary"
onClick={() => setMobileOpen(false)}
>
Contact
</a>
</li>
</ul>
<Separator />
<ul className="flex flex-col gap-2">
<li>
<a
href="/chat"
target="_blank"
rel="noopener noreferrer"
className="block text-sm font-medium text-muted-foreground hover:text-primary"
onClick={() => setMobileOpen(false)}
>
Slack
<span className="sr-only"> (opens in new tab)</span>
</a>
</li>
<li>
<a
href={GITHUB_URL}
target="_blank"
rel="noopener noreferrer"
className="block text-sm font-medium text-muted-foreground hover:text-primary"
onClick={() => setMobileOpen(false)}
>
GitHub
<span className="sr-only"> (opens in new tab)</span>
</a>
</li>
<li>
<NavLink to="/volunteer" className={navLinkClass}>
Volunteer
</NavLink>
</li>
</ul>
</nav>
<Separator />
<div className="px-4 pb-4">
<SearchBox inline />
</div>
</SheetContent>
</Sheet>
</div>
</div>
</header>
);
}