-
Notifications
You must be signed in to change notification settings - Fork 5
/
mega-nav.tsx
383 lines (367 loc) · 17.3 KB
/
mega-nav.tsx
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
import { Fragment, useCallback, useState } from "react";
import { Dialog, Popover, Transition, Disclosure } from "@headlessui/react";
import {
Bars3Icon,
ChevronDownIcon,
ChevronUpIcon,
XMarkIcon,
} from "@heroicons/react/24/solid";
import clsx from "clsx";
import Container from "./container";
import Link from "next/link";
import { kebabCase, map, size } from "lodash";
import { Navigation, SubNav, SubNavWithName } from "@/lib/navigation";
import { useTranslation } from "next-i18next";
import { PartialBy, PickPartial } from "@/utils";
import VaultsLogo from "./vaults-logo";
interface MobileSubnavP {
subnav: PartialBy<
PickPartial<SubNav, "labelKey" | "items" | "href" | "name">,
"labelKey" | "name"
>;
onLinkClick: Function;
}
function MobileSubnavPlain({ subnav, onLinkClick }: MobileSubnavP) {
const { t } = useTranslation("common");
return (
<div>
<p
id={`mobile-${kebabCase(subnav.labelKey)}-heading`}
className="text-stone-100 font-bold"
>
<Link
href={subnav.href}
className="block p-4 hover:bg-stone-400/5"
onClick={() => onLinkClick()}
>
{subnav.name || t(subnav.labelKey as string)}
</Link>
</p>
</div>
);
}
function MobileSubnavWithItems({ subnav, onLinkClick }: MobileSubnavP) {
const { t } = useTranslation("common");
return (
<Disclosure as="div" className="bg-stone-400/10 flex flex-col">
{({ open }) => (
<>
<Disclosure.Button className="bg-stone-400/10 hover:bg-stone-400/20 text-left flex items-center gap-1 p-4 ">
{subnav.name || t(subnav.labelKey as string)}
{open ? (
<ChevronUpIcon className="h-4 w-4" />
) : (
<ChevronDownIcon className="h-4 w-4" />
)}
</Disclosure.Button>
<Disclosure.Panel as="ul" className="ps-2">
{subnav.items?.map((item) => (
<li key={item?.name} className="flex flex-col">
<MobileSubnav
onLinkClick={onLinkClick}
subnav={item as SubNavWithName}
/>
</li>
)) ?? null}
</Disclosure.Panel>
</>
)}
</Disclosure>
);
}
function MobileSubnav({ subnav, onLinkClick }: MobileSubnavP) {
const Component =
size(subnav.items) > 0 ? MobileSubnavWithItems : MobileSubnavPlain;
return <Component subnav={subnav} onLinkClick={onLinkClick} />;
}
export default function MegaNav({ navigation }: { navigation: Navigation }) {
const [open, setOpen] = useState(false);
const { t } = useTranslation("common");
const handleToggleOpen = useCallback(() => {
setOpen(!open);
}, [open]);
return (
<div className="bg-stone-950">
<Transition.Root show={open} as={Fragment}>
<Dialog as="div" className="relative lg:hidden" onClose={setOpen}>
<Transition.Child
as={Fragment}
enter="transition-opacity ease-linear duration-300"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="transition-opacity ease-linear duration-300"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<div className="fixed top-14 left-0 right-0 bottom-0 bg-black bg-opacity-50" />
</Transition.Child>
<div className="fixed top-14 left-0 right-0 bottom-0 flex">
<Transition.Child
as={Fragment}
enter="transition ease-in-out duration-300 transform"
enterFrom="-translate-x-full"
enterTo="translate-x-0"
leave="transition ease-in-out duration-300 transform"
leaveFrom="translate-x-0"
leaveTo="-translate-x-full"
>
<Dialog.Panel className="relative flex w-full max-w-xs flex-col overflow-y-auto bg-stone-950 border-r border-stone-800 pb-12 shadow-xl">
{map(navigation.main, (navItem) => (
<Disclosure
as="div"
key={navItem.labelKey}
className="text-white flex flex-col border-t border-stone-800 font-serif font-bold"
>
{({ open }) => (
<>
<Disclosure.Button className="text-left flex items-center gap-1 p-4 bg-stone-900">
{t(navItem.labelKey)}
{open ? (
<ChevronUpIcon className="h-4 w-4" />
) : (
<ChevronDownIcon className="h-4 w-4" />
)}
</Disclosure.Button>
<Disclosure.Panel className="p-0 bg-stone-900 flex flex-col">
{map(navItem.subnavs, (subnav) => (
<MobileSubnav
onLinkClick={() => setOpen(false)}
key={subnav.href}
subnav={subnav}
/>
))}
</Disclosure.Panel>
</>
)}
</Disclosure>
))}
<div className="flex flex-col border-t border-stone-800 py-2">
{navigation.pages.map((page) => (
<div
key={page.labelKey}
className="flow-root font-bold font-serif"
>
{page.href ? (
<Link
className="flex p-4 items-center text-stone-200 hover:bg-stone-800 transition-colors"
href={page.href}
onClick={() => setOpen(false)}
>
{t(page.labelKey)}
</Link>
) : (
<span className="flex p-4 items-center text-stone-600 cursor-not-allowed">
{t(page.labelKey)}
</span>
)}
</div>
))}
</div>
<div className="flex-1 flex-col">
<a
href="https://pelgranepress.com/product-category/d20-games/archmage-engine/13th-age/"
className="flex items-center bg-gradient-to-bl from-transparent to-amber-600 bg-amber-500 shadow-md shadow-amber-800 text-white p-4 focus:bg-amber-400 hover:bg-amber-400 transition-colors font-bold font-serif"
>
{t("nav.buy-13th-age-label")}
</a>
</div>
</Dialog.Panel>
</Transition.Child>
</div>
</Dialog>
</Transition.Root>
<div className="relative">
<nav aria-label="Top">
<div className="bg-stone-950 px-4 lg:px-8 shadow h-14 flex items-center">
<Container className="flex-1">
<div className="flex py-1 lg:py-2 items-center justify-start gap-8">
<div className="flex lg:hidden">
<button
type="button"
className="text-stone-300"
onClick={handleToggleOpen}
>
<span className="sr-only">
{open
? t("nav.close-menu-label")
: t("nav.open-menu-label")}
</span>
{open ? (
<XMarkIcon className="h-6 w-6" aria-hidden="true" />
) : (
<Bars3Icon className="h-6 w-6" aria-hidden="true" />
)}
</button>
</div>
<div className="hidden lg:flex lg:items-center">
<Link href="/" className="text-white">
<span className="sr-only">13 Vaults</span>
<VaultsLogo
variant="full"
className="hidden h-6 sm:block"
/>
</Link>
</div>
<div className="hidden h-full lg:flex gap-8 flex-1">
<Popover.Group>
<div className="flex h-full justify-center space-x-8">
{navigation.main.map((mainNav) => (
<Popover key={mainNav.labelKey} className="flex">
{({ open }) => (
<>
<div className="relative flex">
<Popover.Button
className={clsx(
open
? "border-teal-600 text-teal-600"
: "border-transparent text-stone-200 hover:text-stone-300",
"font-serif font-bold relative items-center gap-1 -mb-px flex border-b-2 pt-px transition-colors duration-200 ease-out"
)}
>
{t(mainNav.labelKey)}
{open ? (
<ChevronUpIcon className="h-4 w-4" />
) : (
<ChevronDownIcon className="h-4 w-4" />
)}
</Popover.Button>
</div>
<Transition
as={Fragment}
enter="transition ease-out duration-200"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="transition ease-in duration-150"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<Popover.Panel className="absolute inset-x-0 top-full text-stone-300">
<div
className="absolute inset-0 top-1/2 bg-stone-950 shadow"
aria-hidden="true"
/>
<div className="relative bg-stone-950 border-y border-stone-800 px-8">
<Container>
<div className="grid grid-cols-1 items-start gap-y-10 gap-x-8 py-6">
<div className="grid grid-cols-5 gap-y-10 gap-x-8">
{map(
mainNav.subnavs,
(mainNavItem) => (
<div
key={mainNavItem.labelKey}
className={clsx({
"col-span-2":
mainNavItem.large,
})}
>
<Popover.Button
as={Link}
id={`desktop-featured-heading-${kebabCase(
mainNavItem.labelKey
)}`}
className="font-bold font-serif text-stone-200 border-b-2 hover:text-teal-400 focus:text-teal-400 border-transparent focus:hover:border-teal-400 hover:border-teal-400"
href={mainNavItem.href}
>
{t(mainNavItem.labelKey)}
</Popover.Button>
<ul
role="list"
aria-labelledby={`desktop-featured-heading-${kebabCase(
mainNavItem.labelKey
)}`}
className={clsx(
"mt-6 grid gap-1 sm:mt-4",
mainNavItem.large
? "grid-cols-2"
: "grid-cols-1"
)}
>
{map(
mainNavItem.items,
(subNav) => (
<li key={subNav.name}>
<Popover.Button
as={Link}
href={subNav.href}
className="border-b-2 hover:text-teal-400 focus:text-teal-400 border-transparent focus:hover:border-teal-400 hover:border-teal-400"
>
{subNav.name}
</Popover.Button>
</li>
)
)}
</ul>
</div>
)
)}
</div>
</div>
</Container>
</div>
</Popover.Panel>
</Transition>
</>
)}
</Popover>
))}
</div>
</Popover.Group>
<div className="flex flex-1 gap-8 justify-between">
<div className="flex gap-8 font-bold">
{navigation.pages.map((page) =>
page.href ? (
<Link
key={page.href}
href={page.href}
className="font-bold font-serif items-center -mb-px flex pt-px transition-colors duration-200 ease-out text-stone-200 border-b-2 hover:text-teal-600 focus:text-teal-600 border-transparent focus:hover:border-teal-600 hover:border-teal-600"
>
{t(page.labelKey)}
</Link>
) : (
<span
key={page.labelKey}
className="font-bold font-serif flex items-center text-stone-600 cursor-not-allowed"
>
{t(page.labelKey)}
</span>
)
)}
</div>
<div className="flex gap-2">
<a
href="https://pelgranepress.com/product-category/d20-games/archmage-engine/13th-age/"
className="relative group shadow-md border border-amber-400 shadow-amber-800"
>
<div
role="presentation"
className="absolute -inset-[3px] border border-amber-400"
/>
<div
role="presentation"
className="absolute rotate-45 top-0 left-1/2 -translate-x-1/2 h-full aspect-square bg-amber-500 border border-amber-400 group-focus:bg-amber-400 group-hover:bg-amber-400 transition-colors"
/>
<span className="text-shadow relative inline-block bg-gradient-to-bl bg-amber-500 text-white font-serif font-bold px-2 py-1 group-focus:bg-amber-400 group-hover:bg-amber-400 transition-colors">
{t("nav.buy-13th-age-label")}
</span>
</a>
</div>
</div>
</div>
<div className="lg:hidden mx-auto text-white absolute inset-0 grid place-content-center pointer-events-none">
<Link href="/" className="pointer-events-auto">
<span className="sr-only">13 Vaults</span>
<VaultsLogo className="h-6 sm:hidden" variant="small" />
<VaultsLogo
className="hidden h-6 sm:block"
variant="full"
/>
</Link>
</div>
</div>
</Container>
</div>
</nav>
</div>
</div>
);
}