Skip to content

Commit 8ff537d

Browse files
committed
feat: Support sidebar on mobile
1 parent 666ae45 commit 8ff537d

File tree

5 files changed

+76
-26
lines changed

5 files changed

+76
-26
lines changed

assets/css/v2/style.css

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ h3,
175175
h4,
176176
h5,
177177
h6 {
178-
scroll-margin-top: 1.5rem;
178+
scroll-margin-top: 6.5rem;
179179
}
180180

181181
/* MARK: Header
@@ -364,10 +364,30 @@ nav {
364364
}
365365

366366
.sidebar-layout {
367-
display: flex;
368-
flex-direction: column;
369-
position: relative;
370-
z-index: 2;
367+
grid-column: 1;
368+
position: sticky;
369+
top: 0;
370+
padding: 2rem;
371+
margin-left: -2rem;
372+
background-color: white;
373+
width: calc(100% + 4rem);
374+
z-index: 999;
375+
376+
.sidebar {
377+
justify-content: center;
378+
width: 100%;
379+
}
380+
381+
.scrollbar-container {
382+
display: none;
383+
}
384+
385+
.scrollbar-container,
386+
.product-selector-button {
387+
min-width: 20rem;
388+
max-width: 50rem;
389+
width: 100%;
390+
}
371391
}
372392

373393
#searchbox {
@@ -420,10 +440,6 @@ nav {
420440
grid-template-rows: repeat(2, auto);
421441
column-gap: var(--grid-column-gutter);
422442
}
423-
424-
.sidebar-layout {
425-
display: none;
426-
}
427443
}
428444

429445
@media (min-width: 88em) {
@@ -467,6 +483,17 @@ nav {
467483
.content-layout .side-gutter {
468484
grid-column-start: 2;
469485
}
486+
487+
.sidebar-layout {
488+
display: flex;
489+
flex-direction: column;
490+
position: relative;
491+
z-index: 2;
492+
493+
.scrollbar-container {
494+
display: block !important;
495+
}
496+
}
470497
}
471498

472499
.list-page {
@@ -618,6 +645,10 @@ body:not(:has(.main-layout)) header atomic-search-interface {
618645
body:has(.sidebar-layout) header atomic-search-interface {
619646
display: block;
620647
}
648+
649+
body:has(.sidebar-layout) #sidebar-v2 atomic-search-interface {
650+
display: none;
651+
}
621652
}
622653

623654
@media (max-width: 1023px) {
@@ -1123,6 +1154,13 @@ blockquote p:last-child {
11231154
grid-column: 2 !important;
11241155
align-self: start;
11251156
}
1157+
1158+
.sidebar-layout {
1159+
.scrollbar-container,
1160+
.product-selector-button {
1161+
max-width: 100%;
1162+
}
1163+
}
11261164
}
11271165

11281166
blockquote > div > * {

assets/js/product-selector.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
document.addEventListener('DOMContentLoaded', () => {
2-
const productSelectorContent = document.getElementById('product-selector');
2+
const hideSidebarBreakpoint = 88 * 16;
3+
let productSelectorContent;
4+
5+
if (window.innerWidth < hideSidebarBreakpoint) {
6+
productSelectorContent = document.getElementById('scrollbar-container');
7+
} else {
8+
productSelectorContent = document.getElementById('product-selector');
9+
}
10+
311
const productSelectorButton = document.getElementById(
412
'product-selector-button'
513
);
@@ -21,7 +29,11 @@ document.addEventListener('DOMContentLoaded', () => {
2129

2230
window.addEventListener('click', (event) => {
2331
/* Greedy Logic to hide the product selector when something other than the button is clicked. Assumes everything has an id containing "product-selector" */
24-
if (!event.target.id.includes('product-selector')) {
32+
if (
33+
!event.target.id.includes('product-selector') &&
34+
!event.target.id.includes('collapsible') &&
35+
!event.target.id.includes('toggle')
36+
) {
2537
productSelectorContent.style.display = 'none';
2638
productSelectorButton.classList.remove('remove-bottom-radius');
2739
}

assets/js/sidebar-v2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
document.addEventListener('DOMContentLoaded', () => {
22
function expandToCurrentPage() {
3-
const currentPage = document.getElementById('current-page');
3+
const currentPage = document.getElementById('collapsible-link-current');
44
if (currentPage) {
55
let parentLabel = currentPage.closest('li');
66
while (parentLabel) {

layouts/partials/sidebar-list-pages.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{{ $currentUrl := .currentUrl }}
22
{{ $context := .context }}
3-
<ul class="collapsible-content">
3+
<ul class="collapsible-content" id="collapsible-content">
44
{{ range $context.Pages.ByWeight }}
55
<li>
66
{{ if eq .Kind "section" }}
77
<input type="checkbox" id="toggle-{{ .File.UniqueID }}" class="toggle-checkbox" style="display: none;">
8-
<label for="toggle-{{ .File.UniqueID }}" class="collapsible-header">
8+
<label for="toggle-{{ .File.UniqueID }}" class="collapsible-header" id="collapsible-header">
99
{{ if .Pages }}
10-
<span class="box expand partial-box"></span>
11-
<span class="box opened partial-box"></span>
10+
<span class="box expand partial-box" id="toggle-expand"></span>
11+
<span class="box opened partial-box" id="toggle-opened"></span>
1212
{{ end }}
1313
{{ .Title }}
1414
</label>
1515
{{ partial "sidebar-list-pages.html" (dict "context" . "currentUrl" $currentUrl) }}
1616
{{ else if eq .Kind "page" }}
1717
{{ if eq $currentUrl .Permalink }}
18-
<span class="box current partial" id="current-page"></span>
18+
<span class="box current partial" id="collapsible-link-current"></span>
1919
{{ else }}
20-
<span class="box-link partial"></span>
20+
<span class="box-link partial" id="collapsible-link-option"></span>
2121
{{ end }}
2222
<a href="{{ .Permalink }}" style="{{if eq $currentUrl .Permalink}}font-weight: bold;{{end}}">{{ .Title }} </a>
2323
{{ if eq $currentUrl .Permalink }}

layouts/partials/sidebar-v2.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,26 @@
5757
</div>
5858
{{ end }}
5959
</div>
60-
<div class="scrollbar-container">
60+
<div class="scrollbar-container" id="scrollbar-container">
6161
<div class="sidebar-navigation">
62-
<ul class="parent-collapsible-content">
62+
<ul class="parent-collapsible-content" id="parent-collapsible-content">
6363
{{ range .FirstSection.Pages.ByWeight }}
64-
<li class="parent-collapsible-content-item">
64+
<li class="parent-collapsible-content-item" id="parent-collapsible-content-item">
6565
{{ if eq .Kind "section" }}
6666
<input type="checkbox" id="toggle-{{ .File.UniqueID }}" class="toggle-checkbox" style="display: none;">
67-
<label for="toggle-{{ .File.UniqueID }}" class="collapsible-header">
67+
<label for="toggle-{{ .File.UniqueID }}" class="collapsible-header" id="collapsible-header">
6868
{{ if .Pages }}
69-
<span class="parent-box expand"></span>
70-
<span class="parent-box opened"></span>
69+
<span class="parent-box expand" id="toggle-expand"></span>
70+
<span class="parent-box opened" id="toggle-opened"></span>
7171
{{ end }}
7272
{{ .Title }}
7373
</label>
7474
{{ partial "sidebar-list-pages.html" (dict "context" . "currentUrl" $.Permalink) }}
7575
{{ else if eq .Kind "page" }}
7676
{{ if eq $.Permalink .Permalink }}
77-
<span class="parent-box current"></span>
77+
<span class="parent-box current" id="collapsible-link-current"></span>
7878
{{ else }}
79-
<span class="parent-box-link"></span>
79+
<span class="parent-box-link" id="collapsible-link-option"></span>
8080
{{ end }}
8181
<a href="{{ .Permalink }}" style="{{if eq $.Permalink .Permalink}}font-weight: bold;{{end}}">{{ .Title }} </a>
8282
{{ end }}

0 commit comments

Comments
 (0)