Skip to content

Commit 4a54807

Browse files
committed
Sidebar: Mobile support
1 parent 70798f3 commit 4a54807

File tree

5 files changed

+153
-5
lines changed

5 files changed

+153
-5
lines changed

assets/css/v2/style.css

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
--sidebar-line-box-left: 12px;
9292
--sidebar-width: 22rem;
9393
--sidebar-line-width: 11.5px;
94+
--sidebar-mobile-top-displacement: 5rem;
9495
--side-gutter-width: 20rem;
9596
--table-top-bottom-spacing: 1rem;
9697
--table-row-space-between: 1.5rem;
@@ -266,6 +267,10 @@ header {
266267
padding: 20px 10px;
267268
}
268269

270+
.nav-item-explore {
271+
margin: 0;
272+
}
273+
269274
.navbar-button {
270275
padding: 0.5rem 0.5rem;
271276
border: none;
@@ -462,6 +467,10 @@ nav {
462467
position: relative;
463468
z-index: 2;
464469
min-height: 74vh;
470+
471+
.sidebar__mobile__toggle {
472+
display: none;
473+
}
465474
}
466475

467476
.sidebar-layout::before {
@@ -525,8 +534,84 @@ nav {
525534
column-gap: var(--grid-column-gutter);
526535
}
527536

528-
.sidebar-layout {
529-
display: none;
537+
.content-layout .breadcrumb-layout {
538+
position: sticky;
539+
top: 0;
540+
z-index: 3;
541+
}
542+
543+
body:has(.sidebar__mobile-open) {
544+
/* Disable scrolling in main content + hide footer if the sidebar is visible */
545+
overflow-y: hidden;
546+
547+
.sidebar-layout {
548+
position: absolute;
549+
height: 100%;
550+
}
551+
552+
footer {
553+
display: none;
554+
}
555+
556+
.sidebar-layout .sidebar__mobile__toggle {
557+
display: flex;
558+
align-items: center;
559+
position: sticky;
560+
top: 1rem;
561+
margin-top: 2rem;
562+
margin-left: 2rem;
563+
margin-right: 2rem;
564+
padding: 0.5rem;
565+
color: white;
566+
background-color: oklch(var(--color-brand));
567+
}
568+
}
569+
570+
.sidebar__mobile__toggle {
571+
background-color: transparent;
572+
border: none;
573+
574+
.lucide {
575+
margin-right: 1rem;
576+
}
577+
}
578+
579+
.main-layout {
580+
/* Mobile support for sidebar */
581+
display: flex;
582+
flex-direction: column;
583+
position: relative;
584+
585+
.sidebar-layout {
586+
min-height: fit-content;
587+
background: white;
588+
z-index: 999;
589+
width: calc(100% + 4rem);
590+
margin-left: -2rem;
591+
592+
&::before {
593+
display: none;
594+
}
595+
596+
nav {
597+
width: 100%;
598+
display: none;
599+
top: var(--sidebar-mobile-top-displacement);
600+
max-height: calc(100vh - var(--sidebar-mobile-top-displacement));
601+
padding: 0 2rem;
602+
603+
.sidebar__container {
604+
width: 100%;
605+
}
606+
}
607+
}
608+
609+
.content-layout {
610+
.breadcrumb-layout .sidebar__mobile__toggle {
611+
display: inline;
612+
padding: 0;
613+
}
614+
}
530615
}
531616

532617
main {
@@ -933,6 +1018,10 @@ button:has(~ .product-selector[style*="none"]) > .product-selector-button-icon {
9331018
}
9341019
}
9351020

1021+
nav.sidebar.sidebar__mobile-open {
1022+
display: block;
1023+
}
1024+
9361025
/* MARK: Content
9371026
*/
9381027

@@ -941,6 +1030,18 @@ p {
9411030
line-height: 1.5rem;
9421031
}
9431032

1033+
.breadcrumb-layout {
1034+
position: relative;
1035+
background-color: white;
1036+
width: calc(100% + 4rem);
1037+
margin-left: -2rem;
1038+
padding: 1rem 2rem;
1039+
1040+
.sidebar__mobile__toggle {
1041+
display: none;
1042+
}
1043+
}
1044+
9441045
.breadcrumb {
9451046
color: var(--color-foreground);
9461047
text-decoration: none;

assets/js/sidebar-v2.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
document.addEventListener('click', (e) => {
22
const toggle = e.target.closest('.sidebar__toggle');
3+
const sidebarMobileToggle = e.target.closest('.sidebar__mobile__toggle');
34
if (toggle) {
45
const chevron = toggle.querySelector('.sidebar__chevron');
56
const expanded = toggle.getAttribute('aria-expanded') === 'true';
@@ -14,5 +15,48 @@ document.addEventListener('click', (e) => {
1415
if (chevron) {
1516
chevron.classList.toggle('sidebar__chevron--open', !expanded);
1617
}
18+
} else if (sidebarMobileToggle) {
19+
// Show the sidebar
20+
const sidebar = document.getElementById('sidebar-v2');
21+
const expanded =
22+
sidebarMobileToggle.getAttribute('aria-expanded') === 'true';
23+
24+
if (!expanded) {
25+
sidebar.classList.add('sidebar__mobile-open');
26+
} else {
27+
sidebar.classList.remove('sidebar__mobile-open');
28+
}
29+
30+
// Set the aria for all the toggle buttons so they are in lockstep
31+
const toggleButtons = document.getElementsByClassName(
32+
'sidebar__mobile__toggle'
33+
);
34+
for (const button of [...toggleButtons]) {
35+
button.setAttribute('aria-expanded', String(!expanded));
36+
}
1737
}
1838
});
39+
40+
const debounce = (callback, wait) => {
41+
let timeoutId = null;
42+
return (...args) => {
43+
window.clearTimeout(timeoutId);
44+
timeoutId = window.setTimeout(() => {
45+
callback(...args);
46+
}, wait);
47+
};
48+
};
49+
50+
window.addEventListener(
51+
'resize',
52+
debounce(() => {
53+
const sidebar = document.getElementById('sidebar-v2');
54+
55+
if (
56+
window.innerWidth > 88 * 16 &&
57+
sidebar.classList.contains('sidebar__mobile-open')
58+
) {
59+
sidebar.classList.remove('sidebar__mobile-open');
60+
}
61+
}, 200)
62+
);

layouts/_default/docs.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@
6969

7070
<section class="main-layout">
7171
<div class="sidebar-layout" id="sidebar-layout">
72-
<nav data-mf="true" id="sidebar-v2" class="sidebar" style="display:none;">
72+
<button class="sidebar__mobile__toggle" aria-expanded="false" data-mf="true">{{ partial "lucide" (dict "context" . "icon" "x")}}Close</button>
73+
<nav data-mf="true" id="sidebar-v2" class="sidebar">
7374
{{ partial "sidebar-v2.html" . }}
7475
</nav>
7576
</div>
7677

7778
<section id="maincontent" class="content-layout">
7879
<div data-cms-edit="content" class="text-content">
79-
<section class="breadcrumb-layout" data-mf="true" style="display: none;">
80+
<section class="breadcrumb-layout wide" data-mf="true" style="display: none;">
8081
{{ if not .IsHome }}
8182
{{ if not (in .Params.display_breadcrumb "false" ) }}
8283
{{ partial "breadcrumb" .}}

layouts/_default/list.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
<main class="content col d-block align-top content-has-toc" role="main" data-mf="true" style="display: none">
1414
<section class="main-layout">
1515
<div class="sidebar-layout" id="sidebar-layout">
16+
<button class="sidebar__mobile__toggle" aria-expanded="false" data-mf="true">{{ partial "lucide" (dict "context" . "icon" "x")}}Close</button>
1617
<nav data-mf="true" id="sidebar-v2" class="sidebar" style="display:none;">
1718
{{ partial "sidebar-v2.html" . }}
1819
</nav>
1920
</div>
2021

2122
<section id="maincontent" class="content-layout" data-mf="true" style="display: none">
2223
<div data-cms-edit="content" class="text-content list-page">
23-
<section class="breadcrumb-layout">
24+
<section class="breadcrumb-layout wide">
2425
{{ if not .IsHome }}
2526
{{ if not (in .Params.display_breadcrumb "false" ) }}
2627
{{ partial "breadcrumb" .}}

layouts/partials/breadcrumb.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<nav aria-label="breadcrumb" class="breadcrumb navbar">
22
<div class="nav flex-md-row">
33
<ol class="breadcrumb">
4+
<button class="sidebar__mobile__toggle" aria-expanded="false" data-mf="true">{{ partial "lucide" (dict "context" . "icon" "align-justify") }}</button>
45
<li><a href="/" alt="NGINX Docs Home">Home</a></li>
56
{{- define "breadcrumb" -}}
67
{{- with .Parent -}}

0 commit comments

Comments
 (0)