Skip to content

ENH: manage sidebars on small screens #726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7e286ff
manage primary sidebar
12rambau Jun 12, 2022
aa1b564
customize the color of the arrow
12rambau Jun 12, 2022
fdb0e44
hide the arrow when not needed
12rambau Jun 12, 2022
38b37a8
deal with secondary sidebar
12rambau Jun 12, 2022
19546f2
keep the parameter of the secondary sidebar
12rambau Jun 12, 2022
a4b1828
toggle without js
12rambau Jun 20, 2022
2a4d0cd
tune btn rendering
12rambau Jun 21, 2022
e835a9f
change alignement and font size
12rambau Jun 21, 2022
b74cd04
change pcursor style
12rambau Jun 21, 2022
35eaf63
cleaning
12rambau Jun 21, 2022
e07a165
reintroduce bd-toc
12rambau Jun 21, 2022
5f6c6d2
use bootstrap zindex varables
12rambau Jun 21, 2022
c687c64
overlap on top of the header
12rambau Jun 21, 2022
a367772
reintroduce the toc_width behaviour
12rambau Jun 21, 2022
d3f245d
reduce font size
12rambau Jun 22, 2022
75ba580
use variables to control sidebars
12rambau Jun 22, 2022
4cff4b0
cleaning
12rambau Jun 22, 2022
b91ba97
cleaning
12rambau Jun 22, 2022
9cf8076
add the sidebars button in the article header
12rambau Jun 22, 2022
09a919a
inverse toggle sides
12rambau Jun 22, 2022
bdab3b6
dimmed the rendering of the header article
12rambau Jun 23, 2022
594891b
change navbar collapside color
12rambau Jun 23, 2022
cdf1960
update the tests
12rambau Jun 24, 2022
a092734
Merge branch 'main' into sidebars
12rambau Jun 24, 2022
abf8ddc
update test no-sidebar
12rambau Jun 24, 2022
981095b
Update src/pydata_sphinx_theme/assets/styles/sections/_header_article…
12rambau Jun 26, 2022
cd9dba4
Update src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html
12rambau Jun 26, 2022
ea9c59f
remove duplication
12rambau Jun 26, 2022
d745f4c
widden the drawers
12rambau Jun 26, 2022
882b3ed
Merge branch 'main' into sidebars
12rambau Jul 2, 2022
1e85c84
Make the mobile sidebar drawers work
choldgraf Jul 7, 2022
221705c
Merge commit
choldgraf Jul 7, 2022
3220cab
Cleaning up sidebar behavior
choldgraf Jul 7, 2022
3690f39
Fix sidebars
choldgraf Jul 7, 2022
7b49fc2
fix tests
12rambau Jul 8, 2022
0f38ec8
Clean up CSS
choldgraf Jul 8, 2022
cd5a789
Merge branch 'main' into sidebars
choldgraf Jul 8, 2022
cd165d3
Fix random scss bug
choldgraf Jul 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
}

html_sidebars = {
"index": ["search-field"],
"contribute/index": [
"sidebar-nav-bs",
"custom-template",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
}

// inline the element in the navbar as long as they fit and use display block when collapsing
// One breakpoint less than $breakpoint-header. See variables/_layout.scss for more info.
@include media-breakpoint-down(md) {
flex-direction: row;

Expand Down
35 changes: 30 additions & 5 deletions src/pydata_sphinx_theme/assets/styles/components/_toc-inpage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,34 @@
}
}

.toc-entry > .nav-link.active {
font-weight: 600;
color: var(--pst-color-primary);
background-color: transparent;
border-left: 2px solid var(--pst-color-primary);
// Each entry of the in-page TOC
.toc-entry {
display: block;

a.nav-link {
display: block;
padding: 0.125rem 0;

// Padding w/ negative margin so the top TOC item highligh overlaps w/ the TOC border
padding-left: 1rem;
margin-left: -1rem;
color: var(--pst-color-text-muted);

&:hover {
color: var(--pst-color-primary);
text-decoration: none;
}

&.active {
font-weight: 600;
color: var(--pst-color-primary);
background-color: transparent;
border-left: 2px solid var(--pst-color-primary);
}
}
}

// Each successive nested item will be a bit smaller
nav.page-toc ul > li {
font-size: 0.95em;
}
2 changes: 2 additions & 0 deletions src/pydata_sphinx_theme/assets/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ $grid-breakpoints: (
@import "./sections/footer";
@import "./sections/footer-article";
@import "./sections/header";
@import "./sections/header-article";
@import "./sections/sidebar-primary";
@import "./sections/sidebar-secondary";
@import "./sections/sidebar-toggle";

// Re-usable components across the theme
@import "./components/icon-links";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
justify-content: center;
text-align: center;
padding: 0.5rem 12.5%; // Horizontal padding so the width is 75%
// One breakpoint less than $breakpoint-header. See variables/_layout.scss for more info.
@include media-breakpoint-down(md) {
// Announcements can take a bit more width on mobile
padding: 0.5rem 2%;
Expand Down
13 changes: 9 additions & 4 deletions src/pydata_sphinx_theme/assets/styles/sections/_article.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
.bd-content {
display: flex;
flex-direction: column;

// Max-width is slightly more than the W3 since our docs often have images.
// We shoot for about 100 characters per line instead of 80.
// ref: https://www.w3.org/WAI/tutorials/page-structure/styling/#line-length
max-width: 60em;
overflow-x: auto; // Prevent wide content from pushing off the secondary sidebar
// Give a bit more vertical spacing on wide screens
padding: 3rem 1.5rem 2rem 3rem;
@include media-breakpoint-down(md) {
padding: 3rem 1rem 1rem 1rem;
padding: 1rem;

.bd-article {
// Give a bit more verticle spacing on wide screens
@include media-breakpoint-up($breakpoint-sidebar-secondary) {
padding-top: 2rem;
padding-left: 2rem;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.bd-header-article__inner {
min-height: var(--pst-header-article-height);
display: flex;
align-items: center;
padding: 0 0.5rem;

.bd-header-article__end {
margin-left: auto;
}

// We hide this at the secondary breakpoint because no buttons are present here
@include media-breakpoint-up($breakpoint-sidebar-secondary) {
display: none;
}
}

// Toggle labels
label {
&.sidebar-toggle {
display: flex;
cursor: pointer;
font-size: 1.2rem;
align-items: center;
color: var(--pst-color-muted);
}

// Flip the icon right-to-left on the left side
&.primary-toggle {
transform: scale(-1, 1);
}
}
17 changes: 5 additions & 12 deletions src/pydata_sphinx_theme/assets/styles/sections/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
gap: 0.5rem;
}

// Note: breakpoint-down *starts at the next-highest level*
// So media-breakpoint-down(md) triggers the behavior at lg
// ref: https://github.com/twbs/bootstrap/pull/29148 (it is changed in BS5)
// One breakpoint less than $breakpoint-header. See variables/_layout.scss for more info.
@include media-breakpoint-down(md) {
// Make it scrollable with a max height on mobile in cases there are many items
max-height: 90vh;
Expand All @@ -57,12 +55,12 @@
.bd-header.navbar-light#navbar-main {
// Overrides bootstrap
background: var(--pst-color-on-background) !important;
box-shadow: 0 0.125rem 0.25rem 0 var(--pst-color-shadow); //rgba(0, 0, 0, 0.11);
box-shadow: 0 0.125rem 0.25rem 0 var(--pst-color-shadow);

.navbar-nav {
display: flex;

@include media-breakpoint-up(lg) {
@include media-breakpoint-up($breakpoint-header) {
// Add a gap on wider screens, on narrow screens we are vertical + already have padding
gap: 1rem;
// Center align on wide screens so the dropdown button is centered properly
Expand Down Expand Up @@ -108,7 +106,7 @@
}

// On wide screens, the dropdown becomes a pop-up menu
@include media-breakpoint-up(lg) {
@include media-breakpoint-up($breakpoint-header) {
height: 2.2rem; // Slight hack to make this aligned with navbar links

button {
Expand All @@ -133,17 +131,12 @@
}
}

// overwrite bootstrap coloring
.bd-header#navbar-main {
background-color: var(--pst-color-navbar-background) !important;
}

.navbar-header a {
padding: 0 15px;
}

// inline the element in the navbar as long as they fit and use display block when collapsing
@include media-breakpoint-up(md) {
@include media-breakpoint-up($breakpoint-header) {
.navbar-center-item {
display: inline-block;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
* The primary sidebar on the left.
* e.g., between-pages navigation.
*/

.bd-sidebar-primary {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm +1 on this, but just a note that this will be a breaking change so we should note it in the release notes

padding-top: 1em;
overflow-y: auto;
display: flex;
flex-direction: column;

@include media-breakpoint-up(md) {
border-right: 1px solid var(--pst-color-border);
position: sticky;
top: var(--pst-header-height);
z-index: 1000;
max-height: calc(100vh - var(--pst-header-height));
}
max-height: calc(100vh - var(--pst-header-height));
position: sticky;
top: var(--pst-header-height);
@include make-col(3);

// Borders padding and whitespace
padding: 2rem 1rem 1rem 1rem;
border-right: 1px solid var(--pst-color-border);
background-color: var(--pst-color-background);
overflow-y: auto;

@include scrollbar-style();

Expand All @@ -40,14 +42,13 @@
}
}
}
// Navigation item chevrons
label {
position: absolute;
top: 0;
right: 0;
// height: var(--sidebar-item-height);
height: 30px;
width: 30px;
// width: var(--sidebar-expander-width);

cursor: pointer;

Expand Down Expand Up @@ -86,6 +87,11 @@
/* Between-page links and captions */
nav.bd-links {
font-size: var(--pst-sidebar-primary-font-size);
margin-right: -1rem;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@12rambau do you remember why you styled nav.bd-links (the nav element containing the section navigation links) to have margin-right: -1rem? (Aside: can you tell me what the bd- prefix means?)

I can plainly see and understand why you set the negative -1rem margin for the in-page TOC in the right sidebar (it's so that the vertical notch that indicates the current section is aligned properly), but so far I haven't been able to figure out what the -1rem margin is doing for the left sidebar. (On the left sidebar, the current section notches are not aligned to any vertical line.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bd- prefix is the bootstrap one that they use usually in their demo examples. it's a very old issue but for the release of version 1 we would like to get rid of them #37.

About the -1rem I guess the only way to find out is to remove it 😄


@include media-breakpoint-up($breakpoint-sidebar-primary) {
display: block;
}

ul {
list-style: none;
Expand All @@ -98,7 +104,7 @@ nav.bd-links {

li > a {
display: block;
padding: 0.25rem 1.5rem;
padding: 0.25rem 0;
color: var(--pst-color-text-muted);

&:hover {
Expand Down Expand Up @@ -134,7 +140,6 @@ nav.bd-links {
position: relative;
margin-top: 1.25em;
margin-bottom: 0.5em;
padding: 0 1.5rem;
color: var(--pst-color-text-base);
&:first-child {
margin-top: 0;
Expand All @@ -159,18 +164,6 @@ nav.bd-links {
}
}

// Top-level between-page toc container
.bd-links {
padding-top: 1rem;
padding-bottom: 1rem;
margin-right: -15px;
margin-left: -15px;

@include media-breakpoint-up(md) {
display: block;
}
}

////////////////////////////////////////////////////////////////////////////////
// Togglable expand/collapse
////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,48 @@
* Secondary sidebar on the right.
* e.g., in-page table of contents.
*/
// Each TOC item is wrapped in this
.tocsection {
padding-left: 10px;
border-left: 1px solid var(--pst-color-border);
padding: 0.3rem 1.5rem;

i {
padding-right: 0.5rem;
}
}

// The list of in-page TOC
.section-nav {
padding-left: 0;
border-left: 1px solid var(--pst-color-border);
border-bottom: none;

ul {
padding-left: 1rem;
}
}

.bd-sidebar-secondary {
-ms-flex-order: 2;
display: flex;
order: 2;
max-height: calc(100vh - 5rem);
overflow-y: auto;
top: var(--pst-header-height);
flex-direction: column;
position: sticky;
top: var(--pst-header-height);
max-height: calc(100vh - var(--pst-header-height));

padding: 2rem 1rem 1rem 1rem;
@include make-col(2);

// Color and border
background-color: var(--pst-color-background);
overflow-y: auto;

.onthispage {
color: var(--pst-color-text-base);
}

@include scrollbar-style();
}

// Each entry of the in-page TOC
.toc-entry {
display: block;

a {
display: block;
padding: 0.125rem 1.5rem;
color: var(--pst-color-text-muted);

@include media-breakpoint-up(xl) {
padding-right: 0;
}

&:hover {
color: var(--pst-color-primary);
text-decoration: none;
}
// Each TOC item is wrapped in this
.toc-item {
padding: 0.3rem 0.5rem;
@include media-breakpoint-up($breakpoint-sidebar-secondary) {
border-left: 1px solid var(--pst-color-border);
padding-left: 1rem;
}
}

/* adjust toc font sizes to improve overview */
.toc-h2 {
font-size: 0.85rem;
}

.toc-h3 {
font-size: 0.75rem;
}

.toc-h4 {
font-size: 0.65rem;
i {
padding-right: 0.5rem;
}
}

// Other components of the in-page TOC
.editthispage {
padding-top: 2rem;
// The list of in-page TOC
.section-nav {
padding-left: 0;
margin-bottom: 1rem; // A little extra space before the buttons
border-bottom: none;

a {
color: var(--pst-color-primary);
ul {
padding-left: 1rem;
}
}
Loading