-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
517 lines (496 loc) · 22.6 KB
/
index.html
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
<!DOCTYPE html>
<html>
<head>
<title>Responsive Nav</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
:root {
--space-xs: 0.25rem;
--space-sm: 0.5rem;
--space-md: 0.75rem;
--space-lg: 1.25rem;
--space-xl: 2rem;
--space-xxl: 3.25rem;
--space-xxxl: 5.25rem;
--pink-100: #FFF5F7;
--pink-200: #FED7E2;
--pink-300: #FBB6CE;
--pink-400: #F687B3;
--pink-500: #ED64A6;
--pink-600: #D53F8C;
--pink-700: #B83280;
--gray-100: #F7FAFC;
--gray-300: #E2E8F0;
--gray-900: #1A202C;
--black: #000;
--red-100: #FFF5F5;
--red-200: #FED7D7;
--red-300: #FEB2B2;
--red-400: #FC8181;
--red-500: #F56565;
--red-600: #E53E3E;
--red-700:#C53030;
--green-100: #F0FFF4;
--green-200: #C6F6D5;
--green-300: #9AE6B4;
--green-400: #68D391;
--green-500: #48BB78;
--green-600: #38A169;
--green-700: #2F855A;
--teal-100: #E6FFFA;
--teal-200: #B2F5EA;
--teal-300: #81E6D9;
--teal-400: #4FD1C5;
--teal-500: #38B2AC;
--teal-600: #319795;
--teal-700: #2C7A7B;
--indigo-100: #EBF4FF;
--indigo-200: #C3DAFE;
--indigo-300: #A3BFFA;
--indigo-400: #7F9CF5;
--indigo-500: #667EEA;
--indigo-600: #5A67D8;
--indigo-700: #4C51BF;
--purple-100: #FAF5FF;
--purple-200: #E9D8FD;
--purple-300: #D6BCFA;
--purple-400: #B794F4;
--purple-500: #9F7AEA;
--purple-600: #805AD5;
--purple-700: #6B46C1;
--font-size-sm: 1rem;
--font-size-base: 1.25rem;
--font-size-lg: 2rem;
--container-width: 40rem;
--primary-100: var(--pink-100);
--primary-200: var(--pink-200);
--primary-300: var(--pink-300);
--primary-400: var(--pink-400);
--primary-500: var(--pink-500);
--primary-600: var(--pink-600);
--primary-700: var(--pink-700);
}
/* CSS Reset & Defaults */
* {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
}
button {
border: 0;
background-color: transparent;
font-size: inherit;
font-family: inherit;
}
button:focus {
outline: 2px solid var(--primary-600);
outline-offset: -2px;
}
body {
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
font-size: var(--font-size-base);
display: grid;
grid-template-areas:
"navbar"
"main";
}
body > nav {
grid-area: navbar;
}
body > main {
grid-area: main;
}
/* Icon Styles */
.icon, .fa-primary {
color: var(--primary-300);
}
.fa-secondary {
color: var(--black);
}
.icon {
min-height: 1rem;
min-width: 1rem;
max-width: 2rem;
max-height: 2rem;
width: 2rem;
height: 2rem;
}
/* Navbar Styles */
.nav {
width: 100%;
display: flex;
align-items: center;
background-color: white;
}
.nav li {
list-style-type: none;
}
.nav-item {
padding: var(--space-md);
padding-bottom: var(--space-sm);
display: flex;
align-items: center;
justify-content: center;
flex-grow: 1;
flex-wrap: wrap;
color: var(--gray-900);
border-color: transparent;
border-style: solid;
border-width: 0;
border-bottom-width: var(--space-xs);
}
.nav-item[aria-describedby=current] {
border-color: var(--primary-200);
}
.nav-item:hover {
background-color: var(--primary-100);
border-color: var(--primary-300);
}
.nav-item > * {
margin: 0 var(--space-xs);
}
/* For Phones */
/* For Choice of Breakpoint read: https://www.freecodecamp.org/news/the-100-correct-way-to-do-css-breakpoints-88d6a5ba1862/ */
@media (max-width: 599px) {
body {
grid-template-areas:
"main"
"navbar";
grid-template-rows: 1fr auto;
min-height: 100vh;
}
body > nav {
position: sticky;
bottom: 0;
}
.nav {
border-top: 1px solid var(--gray-300);
flex-wrap: wrap;
}
.nav li {
flex-grow: 1;
}
.nav-item {
flex-direction: column;
}
/*
Only blend in menu if there are more than 4 Navigation items
This works because the rule only is activated when there are
5 navigation items + 1 toggle item = 6 total items
*/
.nav.collapsed :nth-last-child(n+6) ~ .menu-toggle {
display: flex;
}
/*
Hide all except the first three children in the collapsed
menu
*/
.nav.collapsed li:nth-child(3) ~ :not(.menu-toggle) {
display: none;
}
.nav.expanded {
flex-direction: column;
}
.nav.expanded li {
width: 100%;
}
.nav.expanded .menu-toggle {
display: flex;
}
.nav.expanded .nav-item {
flex-direction: row;
flex-basis: 100%;
box-sizing: border-box;
padding: var(--space-md) 0;
border-bottom: 0;
border-left-width: var(--space-sm);
}
.expanded--visible, .expanded--hidden {
display: none;
}
[aria-expanded=false] .expanded--hidden {
display: flex;
}
[aria-expanded=true] .expanded--visible {
display: flex;
}
}
/* For Tablets & Up */
@media (min-width: 600px) {
.nav {
border-bottom: 1px solid var(--gray-300);
}
}
/* Other Styles not relevant for Navbar*/
.svg-definitions {
display: none;
}
.link {
color: var(--primary-600);
display: inline-block;
text-decoration-color: var(--primary-200);
text-decoration-line: underline;
text-decoration-thickness: var(--space-sm);
text-underline-offset: -4px;
text-decoration-skip-ink: none;
}
.link:hover, link:focus {
color: var(--primary-700);
text-decoration-color: var(--primary-300);
}
body {
background-color: var(--gray-100);
}
main {
max-width: var(--container-width);
padding: var(--space-xxxl) var(--space-xl);
margin: auto;
font-weight: lighter;
}
h1 {
font-size: var(--font-size-lg);
}
* + p, * + ul {
margin-top: var(--space-xl);
}
.list {
padding-left: var(--space-lg);
}
.list i {
font-weight: normal;
}
.list li::marker {
color: var(--primary-700);
}
.list li + li {
margin-top: var(--space-lg);
}
.list li p + p {
margin-top: var(--space-xs);
font-size: var(--font-size-sm);
}
.red-theme {
--primary-100: var(--red-100);
--primary-200: var(--red-200);
--primary-300: var(--red-300);
--primary-400: var(--red-400);
--primary-500: var(--red-500);
--primary-600: var(--red-600);
--primary-700: var(--red-700);
}
.green-theme {
--primary-100: var(--green-100);
--primary-200: var(--green-200);
--primary-300: var(--green-300);
--primary-400: var(--green-400);
--primary-500: var(--green-500);
--primary-600: var(--green-600);
--primary-700: var(--green-700);
}
.teal-theme {
--primary-100: var(--teal-100);
--primary-200: var(--teal-200);
--primary-300: var(--teal-300);
--primary-400: var(--teal-400);
--primary-500: var(--teal-500);
--primary-600: var(--teal-600);
--primary-700: var(--teal-700);
}
.indigo-theme {
--primary-100: var(--indigo-100);
--primary-200: var(--indigo-200);
--primary-300: var(--indigo-300);
--primary-400: var(--indigo-400);
--primary-500: var(--indigo-500);
--primary-600: var(--indigo-600);
--primary-700: var(--indigo-700);
}
.purple-theme {
--primary-100: var(--purple-100);
--primary-200: var(--purple-200);
--primary-300: var(--purple-300);
--primary-400: var(--purple-400);
--primary-500: var(--purple-500);
--primary-600: var(--purple-600);
--primary-700: var(--purple-700);
}
</style>
</head>
<body>
<nav>
<ul class="nav" is="nav-bar">
<li>
<a class="nav-item" href="#home"
onclick="addBodyClass()">
<svg class="icon"><use href="#fa-home-heart" xlink:href="#fa-home-heart"></use></svg>
Home
</a>
</li>
<li>
<a class="nav-item" href="#about" aria-describedby="current"
onclick="addBodyClass('red-theme')">
<svg class="icon"><use href="#fa-star-exclamation" xlink:href="#fa-star-exclamation"></use></svg>
About
</a>
</li>
<li>
<a class="nav-item" href="#music"
onclick="addBodyClass('green-theme')">
<svg class="icon"><use href="#fa-cloud-music" xlink:href="#fa-cloud-music"></use></svg>
Music
</a>
</li>
<li>
<a class="nav-item" href="#contact"
onclick="addBodyClass('teal-theme')">
<svg class="icon"><use href="#fa-comment-smile" xlink:href="#fa-comment-smile"></use></svg>
Contact
</a>
</li>
<li>
<a class="nav-item" href="#cat"
onclick="addBodyClass('indigo-theme')">
<svg class="icon"><use href="#fa-cat" xlink:href="#fa-cat"></use></svg>
Cat
</a>
</li>
<li>
<a class="nav-item" href="#alerts"
onclick="addBodyClass('purple-theme')">
<svg class="icon"><use href="#fa-bell-exclamation" xlink:href="#fa-bell-exclamation"></use></svg>
Notifications
</a>
</li>
<li class="menu-toggle" hidden>
<button class="nav-item" aria-expanded="false">
<svg class="icon">
<use class="expanded--visible" href="#fa-times" xlink:href="#fa-times"></use>
<use class="expanded--hidden" href="#fa-bars" xlink:href="#fa-bars"></use>
</svg>
<span class="expanded--visible">Close Menu</span>
<span class="expanded--hidden">Menu</span>
</button>
</li>
</ul>
<div hidden id="current">
Current page
</div>
</nav>
<main>
<section>
<h1>Responsive Mobile Navigation</h1>
<p>
This is an example application to show how to develop a responsive
navbar for an application that is optimized for mobile.
Change the size of your viewport to see it in action! The links and icons
in the navbar are purely for show.
</p>
<p>
I attempt to achieve the following:
</p>
<ul class="list">
<li>Position the navbar <i>near the thumb</i> for mobile devices</li>
<li>
<i>Progressive enhancement</i> – the navbar works without JavaScript
and without CSS and does not hide content
</li>
<li>
<i>focus</i> and <i>hover</i> states for navigation items
</li>
<li>
<p>
Style <i>active</i> item and <i>label it for a screen reader</i>
</p>
<p>
(Tip from <a class="link" href="https://shop.smashingmagazine.com/products/inclusive-design-patterns">
this book
</a>: add a description for a screen reader with <code>aria-describedby</code>
and use this as a hook for CSS styling)
</p>
</li>
<li>
Always have a <i>label for every icon</i>!
</li>
<li>
Only hide navigation items on mobile <i>when absolutely necessary</i>
– the mobile menu is only activated when there are at least five
menu items.
</li>
<li>
A <i>lightweight implementation</i> – I dare you to check how
few KBs this implementation actually has!
</li>
</ul>
<p>
I also chose 600px as the breakpoint to determine if something is a
phone or a tablet.
<a class="link" href="https://www.freecodecamp.org/news/the-100-correct-way-to-do-css-breakpoints-88d6a5ba1862/">
Read this article
</a> to understand why I chose that value.
</p>
<p>
<b>Any comments or suggestions?</b>
</p>
<p>Please feel free to create an issue in
<a class="link" href="https://github.com/joyheron/responsive-nav">
this repository
</a>.
</p>
</section>
</main>
<svg class="svg-definitions" hidden>
<defs>
<svg id="fa-bars" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="bars" class="svg-inline--fa fa-bars fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><g class="fa-group"><path class="fa-secondary" fill="currentColor" d="M16 288h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16z" opacity="0.4"></path><path class="fa-primary" fill="currentColor" d="M432 384H16a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16zm0-320H16A16 16 0 0 0 0 80v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V80a16 16 0 0 0-16-16z"></path></g></svg>
<svg id="fa-bell-exclamation" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="bell-exclamation" class="svg-inline--fa fa-bell-exclamation fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><g class="fa-group"><path class="fa-secondary" fill="currentColor" d="M439.39 362.29c-19.32-20.76-55.47-52-55.47-154.29 0-77.7-54.48-139.9-127.94-155.16V32a32 32 0 1 0-64 0v20.84C118.56 68.1 64.08 130.3 64.08 208c0 102.3-36.15 133.53-55.47 154.29A31.24 31.24 0 0 0 0 384c.11 16.4 13 32 32.1 32h383.8c19.12 0 32-15.6 32.1-32a31.23 31.23 0 0 0-8.61-21.71zM224 352a32 32 0 1 1 32-32 32 32 0 0 1-32 32zm38.2-206.4l-12.8 96a16 16 0 0 1-15.9 14.4h-19a16 16 0 0 1-15.9-14.4l-12.8-96a16.06 16.06 0 0 1 15.9-17.6h44.6a16 16 0 0 1 15.89 17.6z" opacity="0.4"></path><path class="fa-primary" fill="currentColor" d="M160 448a64 64 0 1 0 128 0zm64-160a32 32 0 1 0 32 32 32 32 0 0 0-32-32zm-9.5-32h19a16 16 0 0 0 15.9-14.4l12.8-96a16 16 0 0 0-15.9-17.6h-44.6a16.06 16.06 0 0 0-15.9 17.6l12.8 96a16 16 0 0 0 15.89 14.4z"></path></g></svg>
<svg id="fa-cat" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="cat" class="svg-inline--fa fa-cat fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><g class="fa-group"><path class="fa-secondary" fill="currentColor" d="M448 96h-64l-64-64v134.4a96 96 0 0 0 192 0V32zm-72 80a16 16 0 1 1 16-16 16 16 0 0 1-16 16zm80 0a16 16 0 1 1 16-16 16 16 0 0 1-16 16zm-165.41 16a204.07 204.07 0 0 0-34.59 2.89V272l-43.15-64.73a183.93 183.93 0 0 0-44.37 26.17L192 304l-60.94-30.47L128 272v-80a96.1 96.1 0 0 0-96-96 32 32 0 0 0 0 64 32 32 0 0 1 32 32v256a64.06 64.06 0 0 0 64 64h176a16 16 0 0 0 16-16v-16a32 32 0 0 0-32-32h-32l128-96v144a16 16 0 0 0 16 16h32a16 16 0 0 0 16-16V289.86a126.78 126.78 0 0 1-32 4.54c-61.81 0-113.52-44.05-125.41-102.4z" opacity="0.4"></path><path class="fa-primary" fill="currentColor" d="M376 144a16 16 0 1 0 16 16 16 16 0 0 0-16-16zm80 0a16 16 0 1 0 16 16 16 16 0 0 0-16-16zM131.06 273.53L192 304l-23.52-70.56a192.06 192.06 0 0 0-37.42 40.09zM256 272v-77.11a198.62 198.62 0 0 0-43.15 12.38z"></path></g></svg>
<svg id="fa-cloud-music" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="cloud-music" class="svg-inline--fa fa-cloud-music fa-w-20" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><g class="fa-group"><path class="fa-secondary" fill="currentColor" d="M537.59 226.59a96 96 0 0 0-142.9-114.39A160 160 0 0 0 96 192c0 2.7.09 5.41.19 8.09A144 144 0 0 0 144 480h368a128 128 0 0 0 25.59-253.41zM384 352c0 17.67-21.5 32-48 32s-48-14.33-48-32 21.5-32 48-32a69.82 69.82 0 0 1 16 2v-76.36l-96 37.52V384c0 17.67-21.5 32-48 32s-48-14.33-48-32 21.5-32 48-32a69.82 69.82 0 0 1 16 2V239.25A16 16 0 0 1 235.19 224l128-47.25A16 16 0 0 1 384 192z" opacity="0.4"></path><path class="fa-primary" fill="currentColor" d="M208 352a69.82 69.82 0 0 1 16 2V239.25A16 16 0 0 1 235.19 224l128-47.25A16 16 0 0 1 384 192v160c0 17.67-21.5 32-48 32s-48-14.33-48-32 21.5-32 48-32a69.82 69.82 0 0 1 16 2v-76.36l-96 37.52V384c0 17.67-21.5 32-48 32s-48-14.33-48-32 21.5-32 48-32z"></path></g></svg>
<svg id="fa-comment-smile" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="comment-smile" class="svg-inline--fa fa-comment-smile fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><g class="fa-group"><path class="fa-secondary" fill="currentColor" d="M256 32C114.6 32 0 125.1 0 240c0 49.6 21.4 95 57 130.7C44.5 421.1 2.7 466 2.2 466.5a8 8 0 0 0-1.5 8.7A7.83 7.83 0 0 0 8 480c66.3 0 116-31.8 140.6-51.4A305 305 0 0 0 256 448c141.4 0 256-93.1 256-208S397.4 32 256 32zm64 133.2a26.8 26.8 0 1 1-26.8 26.8 26.8 26.8 0 0 1 26.8-26.8zm-128 0a26.8 26.8 0 1 1-26.8 26.8 26.8 26.8 0 0 1 26.8-26.8zm164.2 140.9a132.32 132.32 0 0 1-200.4 0 16 16 0 1 1 24.3-20.7 100.23 100.23 0 0 0 151.6-.1 16.07 16.07 0 0 1 24.5 20.8z" opacity="0.4"></path><path class="fa-primary" fill="currentColor" d="M320 218.8a26.8 26.8 0 1 0-26.8-26.8 26.8 26.8 0 0 0 26.8 26.8zm-128 0a26.8 26.8 0 1 0-26.8-26.8 26.8 26.8 0 0 0 26.8 26.8zm162.3 64.7a16.11 16.11 0 0 0-22.6 1.8 100.23 100.23 0 0 1-151.6.1 16 16 0 1 0-24.3 20.7 132.32 132.32 0 0 0 200.4 0 16 16 0 0 0-1.9-22.6z"></path></g></svg>
<svg id="fa-home-heart" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="home-heart" class="svg-inline--fa fa-home-heart fa-w-18" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><g class="fa-group"><path class="fa-secondary" fill="currentColor" d="M64.11 311.38V496a16.05 16.05 0 0 0 16 16h416a16.05 16.05 0 0 0 16-16V311.38c-6.7-5.5-44.7-38.31-224-196.4-180.11 158.9-217.6 191.09-224 196.4zm314.1-26.31a60.6 60.6 0 0 1 4.5 89.11L298 459.77a13.94 13.94 0 0 1-19.8 0l-84.7-85.59a60.66 60.66 0 0 1 4.3-89.11c24-20 59.7-16.39 81.6 5.81l8.6 8.69 8.6-8.69c22.01-22.2 57.71-25.81 81.61-5.81z" opacity="0.4"></path><path class="fa-primary" fill="currentColor" d="M378.21 285.07c-23.9-20-59.6-16.39-81.6 5.81l-8.6 8.69-8.6-8.69c-21.9-22.2-57.6-25.81-81.6-5.81a60.66 60.66 0 0 0-4.3 89.11l84.7 85.59a13.94 13.94 0 0 0 19.8 0l84.7-85.59a60.6 60.6 0 0 0-4.5-89.11zm192.6-48.8l-58.7-51.79V48a16 16 0 0 0-16-16h-64a16 16 0 0 0-16 16v51.7l-101.3-89.43a40 40 0 0 0-53.5 0l-256 226a16 16 0 0 0-1.2 22.61l21.4 23.8a16 16 0 0 0 22.6 1.2l229.4-202.2a16.12 16.12 0 0 1 21.2 0L528 284a16 16 0 0 0 22.6-1.21L572 259a16.11 16.11 0 0 0-1.19-22.73z"></path></g></svg>
<svg id="fa-star-exclamation" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="star-exclamation" class="svg-inline--fa fa-star-exclamation fa-w-18" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><g class="fa-group"><path class="fa-secondary" fill="currentColor" d="M528.55 171.5l-146.37-21.3-65.43-132.39c-11.72-23.7-45.68-23.8-57.5 0L193.82 150.2 47.45 171.4c-26.25 3.8-36.77 36.1-17.73 54.6l105.9 103-25.05 145.46c-4.51 26.1 23 46 46.49 33.7L288 439.57l130.94 68.69c23.35 12.3 51-7.5 46.49-33.7l-25.05-145.48 105.9-103c19-18.48 8.52-50.78-17.73-54.58zM288 392a40 40 0 1 1 40.07-40A40 40 0 0 1 288 392zm40.17-223.38l-8 112a8 8 0 0 1-8 7.4h-48.11a8 8 0 0 1-8-7.4l-8-112a8 8 0 0 1 7.39-8.58H320.19a8 8 0 0 1 8 8v.63z" opacity="0.4"></path><path class="fa-primary" fill="currentColor" d="M288 312a40 40 0 1 0 40.07 40A40 40 0 0 0 288 312zm32.16-152H256a8 8 0 0 0-8 8v.62l8 112a8 8 0 0 0 8 7.4h48.09a8 8 0 0 0 8-7.4l8-112a8 8 0 0 0-7.39-8.58z"></path></g></svg>
<svg id="fa-times" aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times" class="svg-inline--fa fa-times fa-w-11" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512"><path fill="currentColor" d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"></path></svg>
</defs>
</svg>
<script src="https://unpkg.com/@ungap/[email protected]/min.js"></script>
<script>
class Navbar extends HTMLUListElement {
connectedCallback () {
console.log("Navbar reporting for duty!")
this.setNavbarState(this.expanded)
this.collapser.addEventListener('click', () => {
this.setNavbarState(!this.expanded)
})
}
setNavbarState (expanded) {
if (expanded) {
this.classList.remove('collapsed')
this.classList.add('expanded')
this.collapser.setAttribute('aria-expanded', 'true')
} else {
this.classList.remove('expanded')
this.classList.add('collapsed')
this.collapser.setAttribute('aria-expanded', 'false')
}
}
get expanded () {
return this.collapser.getAttribute('aria-expanded') === 'true'
}
get collapser () {
return this.querySelector('.menu-toggle button')
}
}
customElements.define('nav-bar', Navbar, { extends: 'ul' })
function addBodyClass (className) {
document.querySelector('body').classList.remove('red-theme')
document.querySelector('body').classList.remove('green-theme')
document.querySelector('body').classList.remove('teal-theme')
document.querySelector('body').classList.remove('indigo-theme')
document.querySelector('body').classList.remove('purple-theme')
if (className) {
document.querySelector('body').classList.add(className)
}
}
</script>
</body>
</html>