Skip to content

Commit 35bb829

Browse files
committed
Fixing up header and sidebar javascript
1 parent 20ff972 commit 35bb829

File tree

15 files changed

+141
-220
lines changed

15 files changed

+141
-220
lines changed

docs/demo/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ See the sections to the left and below to explore.
1010
:caption: Real-world examples
1111

1212
gallery
13-
pydata
1413
example_pandas
1514

1615

src/pydata_sphinx_theme/assets/scripts/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ function addModeListener() {
8484
setTheme(document.documentElement.dataset.mode);
8585

8686
// Attach event handlers for toggling themes colors
87-
const btn = document.getElementById("theme-switch");
88-
if (btn != null) {
89-
btn.addEventListener("click", cycleMode);
90-
}
87+
document.querySelectorAll(".theme-switch-button").forEach((el) => {
88+
el.addEventListener("click", cycleMode);
89+
});
9190
}
9291

9392
/*******************************************************************************

src/pydata_sphinx_theme/assets/styles/components/_navbar-links.scss

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,66 @@
22
* Navigation links within a navbar
33
*/
44
.navbar-nav {
5-
// Navigation links
6-
li a.nav-link {
7-
color: var(--pst-color-text-muted);
5+
ul {
6+
display: block;
7+
list-style: none;
88

9-
&:hover {
10-
color: var(--pst-color-primary);
9+
// Reduce padding of nested `ul` items a bit
10+
ul {
11+
padding: 0 0 0 1rem;
1112
}
13+
}
14+
15+
// Default link styles
16+
li {
17+
display: flex;
18+
flex-direction: column;
19+
20+
a {
21+
color: var(--pst-color-text-muted);
22+
padding-top: 0.25rem;
23+
padding-bottom: 0.25rem;
24+
&:hover {
25+
color: var(--pst-color-primary);
26+
border-style: none;
27+
text-decoration-line: none;
28+
}
1229

13-
&:focus {
30+
&:focus {
31+
color: var(--pst-color-primary);
32+
}
33+
}
34+
35+
// Active page is always highlighted
36+
&.current a {
37+
font-weight: 600;
1438
color: var(--pst-color-primary);
1539
}
1640
}
1741

18-
> .active > .nav-link {
19-
font-weight: 600;
20-
color: var(--pst-color-primary);
42+
/**
43+
* Togglable expand/collapse
44+
* This is only applicable to the primary sidebar which has these checkboxes
45+
*/
46+
.toctree-checkbox {
47+
position: absolute;
48+
display: none;
49+
}
50+
51+
.toctree-checkbox {
52+
~ ul {
53+
display: none;
54+
}
55+
~ label i {
56+
transform: rotate(0deg);
57+
}
58+
}
59+
.toctree-checkbox:checked {
60+
~ ul {
61+
display: block;
62+
}
63+
~ label i {
64+
transform: rotate(180deg);
65+
}
2166
}
2267
}

src/pydata_sphinx_theme/assets/styles/components/_switcher-theme.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// the icons for theme change
2-
#theme-switch {
2+
.theme-switch-button {
33
// to overide bootstrap settings
44
border-color: var(--pst-color-on-background);
55
padding: 0.25rem 0.5rem;
@@ -20,12 +20,12 @@
2020
}
2121
}
2222

23-
html[data-mode="auto"] #theme-switch a[data-mode="auto"] {
23+
html[data-mode="auto"] .theme-switch-button a[data-mode="auto"] {
2424
display: block;
2525
}
26-
html[data-mode="light"] #theme-switch a[data-mode="light"] {
26+
html[data-mode="light"] .theme-switch-button a[data-mode="light"] {
2727
display: block;
2828
}
29-
html[data-mode="dark"] #theme-switch a[data-mode="dark"] {
29+
html[data-mode="dark"] .theme-switch-button a[data-mode="dark"] {
3030
display: block;
3131
}

src/pydata_sphinx_theme/assets/styles/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ $grid-breakpoints: (
4747
// Re-usable components across the theme
4848
@import "./components/icon-links";
4949
@import "./components/header/header-logo";
50+
@import "./components/navbar-links";
5051
@import "./components/prev-next";
5152
@import "./components/search";
5253
@import "./components/switcher-theme";

src/pydata_sphinx_theme/assets/styles/sections/_header-article.scss

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,4 @@
77
.bd-header-article__end {
88
margin-left: auto;
99
}
10-
11-
// We hide this at the secondary breakpoint because no buttons are present here
12-
@include media-breakpoint-up($breakpoint-sidebar-secondary) {
13-
display: none;
14-
}
15-
}
16-
17-
// Toggle labels
18-
label {
19-
&.sidebar-toggle {
20-
display: flex;
21-
cursor: pointer;
22-
font-size: 1.2rem;
23-
align-items: center;
24-
color: var(--pst-color-muted);
25-
}
26-
27-
// Flip the icon right-to-left on the left side
28-
&.primary-toggle {
29-
transform: scale(-1, 1);
30-
}
3110
}
Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
.navbar {
1+
/**
2+
* The header at the top of the page.
3+
*/
4+
5+
// If we want the shadow to only point downward in the future, set
6+
// box-shadow to: 0 0.125rem 0.25rem -0.125rem rgba(0, 0, 0, 0.11);
7+
.bd-header {
28
position: sticky;
9+
top: 0;
10+
z-index: $zindex-fixed;
11+
12+
// Overrides bootstrap
13+
background: var(--pst-color-on-background) !important;
14+
box-shadow: 0 0.125rem 0.25rem 0 var(--pst-color-shadow);
15+
316
min-height: var(--pst-header-height);
417
width: 100%;
518
padding: 0.5rem 0;
@@ -12,10 +25,13 @@
1225
padding-right: 1rem;
1326
}
1427

15-
#navbar-collapsible {
16-
// Remove padding because we inherit padding from the parent container
17-
padding-left: 0;
18-
padding-right: 0;
28+
// Hide the header items on mobile
29+
.navbar-header-items {
30+
display: none;
31+
@include media-breakpoint-up($breakpoint-sidebar-primary) {
32+
display: inherit;
33+
padding: 0;
34+
}
1935
}
2036

2137
#navbar-end,
@@ -37,37 +53,6 @@
3753
gap: 0.5rem;
3854
}
3955

40-
// One breakpoint less than $breakpoint-header. See variables/_layout.scss for more info.
41-
@include media-breakpoint-down(md) {
42-
// Make it scrollable with a max height on mobile in cases there are many items
43-
max-height: 90vh;
44-
overflow-y: visible;
45-
@include scrollbar-style;
46-
47-
// If we're expanded, then make it possible to scroll if overflow
48-
&.shown {
49-
overflow-y: auto;
50-
}
51-
52-
button.navbar-toggler {
53-
border-color: var(--pst-color-text-muted);
54-
color: var(--pst-color-text-muted);
55-
}
56-
}
57-
58-
label {
59-
// Override a bootstrap default
60-
margin-bottom: 0;
61-
}
62-
}
63-
64-
// If we want the shadow to only point downward in the future, set
65-
// box-shadow to: 0 0.125rem 0.25rem -0.125rem rgba(0, 0, 0, 0.11);
66-
.bd-header.navbar-light#navbar-main {
67-
// Overrides bootstrap
68-
background: var(--pst-color-on-background) !important;
69-
box-shadow: 0 0.125rem 0.25rem 0 var(--pst-color-shadow);
70-
7156
.navbar-nav {
7257
display: flex;
7358
align-items: center;
@@ -83,6 +68,7 @@
8368
.dropdown-menu {
8469
z-index: $zindex-popover;
8570
box-shadow: 0 0 0.3rem 0.1rem var(--pst-color-shadow);
71+
background-color: var(--pst-color-on-background);
8672
padding: 0.5rem 1rem;
8773
margin: 0.5rem 0;
8874
min-width: 20rem;
@@ -96,30 +82,51 @@
9682
}
9783
}
9884

99-
.navbar-header a {
100-
padding: 0 15px;
101-
}
102-
10385
// inline the element in the navbar as long as they fit and use display block when collapsing
104-
@include media-breakpoint-up($breakpoint-header) {
105-
.navbar-center-item {
106-
display: inline-block;
107-
}
108-
}
109-
110-
.toc-entry > .nav-link.active {
111-
font-weight: 600;
112-
color: var(--pst-color-primary);
113-
background-color: transparent;
114-
border-left: 2px solid var(--pst-color-primary);
115-
}
116-
117-
.nav-link:hover {
118-
border-style: none;
86+
.navbar-center-item {
87+
display: inline-block;
11988
}
12089

12190
#navbar-main-elements li.nav-item i {
12291
font-size: 0.7rem;
12392
padding-left: 2px;
12493
vertical-align: middle;
12594
}
95+
96+
/**
97+
* Showing and hiding the sidebar toggle buttons and header items
98+
*/
99+
// Hide the header items on mobile
100+
.bd-header {
101+
// Toggle labels
102+
label {
103+
&.sidebar-toggle {
104+
display: flex;
105+
cursor: pointer;
106+
font-size: 1.2rem;
107+
align-items: center;
108+
color: var(--pst-color-muted);
109+
margin-bottom: 0;
110+
}
111+
112+
&.primary-toggle {
113+
@include media-breakpoint-up($breakpoint-sidebar-primary) {
114+
display: none;
115+
}
116+
}
117+
118+
&.secondary-toggle {
119+
@include media-breakpoint-up($breakpoint-sidebar-secondary) {
120+
display: none;
121+
}
122+
}
123+
}
124+
125+
// Hide the navbar header items on mobile because they're in the sidebar
126+
.navbar-header-items {
127+
display: none;
128+
@include media-breakpoint-up($breakpoint-sidebar-primary) {
129+
display: inherit;
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)