Skip to content

Commit 4e1a2f1

Browse files
committed
Sidebar: Add initial collapsible sidebar
1 parent c852b71 commit 4e1a2f1

File tree

4 files changed

+75
-89
lines changed

4 files changed

+75
-89
lines changed

assets/css/v2/style.css

Lines changed: 59 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,14 @@ ol li:last-child {
392392
"content"
393393
"footer";
394394

395-
.sidebar {
396-
display: none;
397-
}
398-
399395
.header__logo {
400396
display: unset;
401397
}
402398

403-
.header__product-selector {
399+
.sidebar,
400+
.header__product-selector,
401+
.header__sidebar__panel,
402+
.header__logo-small {
404403
display: none;
405404
}
406405
}
@@ -525,7 +524,43 @@ ol li:last-child {
525524
margin-top: auto;
526525
}
527526

527+
/* sidebar toggling */
528+
#sidebar-panel:checked ~ .grid-container {
529+
grid-template-columns: 1fr;
530+
grid-template-areas:
531+
"header"
532+
"content"
533+
"footer";
534+
535+
.sidebar {
536+
display: none;
537+
}
538+
539+
.header__sidebar__panel {
540+
display: flex;
541+
align-self: center;
542+
}
543+
}
544+
528545
/* sidebar layout */
546+
547+
.header__sidebar__panel,
548+
.sidebar__panel {
549+
cursor: pointer;
550+
color: var(--color-foreground);
551+
label {
552+
cursor: pointer;
553+
}
554+
555+
:hover {
556+
color: oklch(var(--color-brand));
557+
}
558+
}
559+
560+
.header__sidebar__panel {
561+
display: none;
562+
}
563+
529564
.sidebar {
530565
grid-area: sidebar;
531566
position: fixed;
@@ -548,11 +583,12 @@ ol li:last-child {
548583
.sidebar__header {
549584
display: flex;
550585
align-items: center;
586+
justify-content: space-between;
551587
position: sticky;
552588
top: 0;
553589
background: oklch(var(--color-background));
554590
z-index: 1;
555-
padding: 0 0 0 var(--sidebar-item-padding-lr);
591+
padding: 0 2.25rem 0 var(--sidebar-item-padding-lr);
556592

557593
.sidebar__img {
558594
height: 2rem;
@@ -569,7 +605,19 @@ ol li:last-child {
569605
}
570606
}
571607

608+
/* This is our "mobile" or no sidebar breakpoint */
572609
@media (max-width: 68rem) {
610+
#sidebar-panel:checked ~ .grid-container {
611+
.sidebar {
612+
/* Above search */
613+
z-index: 11;
614+
display: unset;
615+
transform: translateX(0);
616+
border-bottom: 1px solid oklch(var(--color-divider));
617+
height: fit-content;
618+
}
619+
}
620+
573621
.header {
574622
.header__logo-small {
575623
display: unset;
@@ -583,6 +631,11 @@ ol li:last-child {
583631
display: none;
584632
}
585633

634+
.header__sidebar__panel {
635+
display: flex;
636+
align-items: center;
637+
}
638+
586639
.sidebar {
587640
grid-area: sidebar;
588641
position: absolute;
@@ -593,10 +646,6 @@ ol li:last-child {
593646
transform: translateX(-100%);
594647
}
595648

596-
#sidebar-toggle:checked ~ .sidebar {
597-
transform: translateX(0);
598-
}
599-
600649
.sidebar-button {
601650
display: block;
602651
margin-bottom: 1rem;
@@ -802,82 +851,6 @@ main {
802851
margin: 0 var(--space-s) var(--space-s) var(--space-s);
803852
}
804853

805-
@media (max-width: 88rem) {
806-
body:has(.sidebar__mobile-open) {
807-
/* Disable scrolling in main content + hide footer if the sidebar is visible */
808-
overflow-y: hidden;
809-
810-
.sidebar-layout {
811-
position: absolute;
812-
height: 100%;
813-
}
814-
815-
footer {
816-
display: none;
817-
}
818-
819-
.sidebar-layout .sidebar__mobile__toggle {
820-
display: flex;
821-
align-items: center;
822-
position: sticky;
823-
top: 1rem;
824-
margin-top: 2rem;
825-
margin-left: 2rem;
826-
margin-right: 2rem;
827-
padding: 0.5rem;
828-
color: white;
829-
background-color: oklch(var(--color-brand));
830-
}
831-
}
832-
833-
.sidebar__mobile__toggle {
834-
background-color: transparent;
835-
border: none;
836-
837-
.lucide {
838-
margin-right: 1rem;
839-
}
840-
}
841-
842-
.main-layout {
843-
/* Mobile support for sidebar */
844-
display: flex;
845-
flex-direction: column;
846-
position: relative;
847-
848-
.sidebar-layout {
849-
min-height: fit-content;
850-
background: white;
851-
z-index: 999;
852-
width: calc(100% + 4rem);
853-
margin-left: -2rem;
854-
855-
&::before {
856-
display: none;
857-
}
858-
859-
nav {
860-
width: 100%;
861-
display: none;
862-
top: var(--sidebar-mobile-top-displacement);
863-
max-height: calc(100vh - var(--sidebar-mobile-top-displacement));
864-
padding: 0 2rem;
865-
866-
.sidebar__container {
867-
width: 100%;
868-
}
869-
}
870-
}
871-
872-
.content-layout {
873-
.breadcrumb-layout .sidebar__mobile__toggle {
874-
display: inline;
875-
padding: 0;
876-
}
877-
}
878-
}
879-
}
880-
881854
@media (min-width: 88em) {
882855
.header__logo {
883856
display: unset;

layouts/_default/baseof.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
{{ if or ( not hugo.IsServer ) ( not ( in .Site.Params.buildtype "package" ) ) }}
4242
{{ partial "universal-tag.html" . }}
4343
{{ end }}
44+
<input type="checkbox" id="sidebar-panel" class="sidebar-panel" hidden/>
4445
<div class="grid-container">
4546
<aside class="sidebar">
4647
{{ partial "sidebar-v2.html" . }}

layouts/partials/header.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{{ define "header" }}
2+
<div class="header__sidebar__panel">
3+
<label for="sidebar-panel">
4+
{{ partial "lucide" (dict "context" . "icon" "panel-left-open") }}
5+
</label>
6+
</div>
27
<div class="header-container">
38

49
<div class="header__logo">

layouts/partials/sidebar-v2.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@
2323

2424
<div class="sidebar__container">
2525
<div class="sidebar__header">
26-
<a href="{{ .Site.BaseURL | relLangURL }}" alt="NGINX Docs Home">
27-
<img class="sidebar__img" src="{{ "/images/icons/NGINX-Docs-horiz-black-type.svg" | absURL }}" alt="NGINX Docs">
28-
</a>
26+
<div>
27+
<a href="{{ .Site.BaseURL | relLangURL }}" alt="NGINX Docs Home">
28+
<img class="sidebar__img" src="{{ "/images/icons/NGINX-Docs-horiz-black-type.svg" | absURL }}" alt="NGINX Docs">
29+
</a>
30+
</div>
31+
<div class="sidebar__panel">
32+
<label for="sidebar-panel">
33+
{{ partial "lucide" (dict "context" . "icon" "panel-left-close") }}
34+
</label>
35+
</div>
2936
</div>
3037
<div class="sidebar__content">
3138
<a class="skip-link" href="#maincontent">Skip Navigation</a>

0 commit comments

Comments
 (0)