Skip to content
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

fix(page_sidebar): Improve page sidebar and mobile flow behavior #908

Merged
merged 18 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
5 changes: 3 additions & 2 deletions R/page.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ page_fillable <- function(
theme = theme,
lang = lang,
class = "bslib-page-fill bslib-gap-spacing",
class = if (!fillable_mobile) "bslib-flow-mobile",
style = css(
padding = validateCssPadding(padding),
gap = validateCssUnit(gap),
"--bslib-page-fill-mobile-height" = if (fillable_mobile) "100%" else "auto"
gap = validateCssUnit(gap)
),
...,
tags$head(tags$style("html { height: 100%; }")),
Expand Down Expand Up @@ -277,6 +277,7 @@ page_sidebar <- function(
fillable = fillable,
border = FALSE,
border_radius = FALSE,
# tags$main(..., as_fill_carrier()),
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
...
)
)
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion inst/components/dist/components.css

Large diffs are not rendered by default.

49 changes: 47 additions & 2 deletions inst/components/scss/page_fillable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,52 @@
}

@include media-breakpoint-down(sm) {
.bslib-page-fill {
height: var(--bslib-page-fill-mobile-height, auto);
.bslib-flow-mobile {
&:not(.bslib-page-sidebar) {
> .html-fill-item {
flex: 0 0 auto;
}
}

&.bslib-page-sidebar > .bslib-sidebar-layout {
> .main > .html-fill-item {
flex: 0 0 auto;
}

&:not(.sidebar-right) {
> .main {
padding-left: var(--_padding-icon);
}
> .collapse-toggle {
left: calc(var(--_icon-size) / 2);
}
}
&.sidebar-right {
> .main {
padding-right: var(--_padding-icon);
}
> .collapse-toggle {
right: calc(var(--_icon-size) / 2);
}
}
}
}
}

@include media-breakpoint-down(sm) {
.bslib-flow-sm > .html-fill-item {
flex: 0 0 auto;
}
}

@include media-breakpoint-down(md) {
.bslib-flow-md > .html-fill-item {
flex: 0 0 auto;
}
}

@include media-breakpoint-down(lg) {
.bslib-flow-lg > .html-fill-item {
flex: 0 0 auto;
gadenbuie marked this conversation as resolved.
Show resolved Hide resolved
}
}
14 changes: 5 additions & 9 deletions inst/components/scss/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--_icon-size)), var(--_sideba
--_toggle-transform: var(--bslib-collapse-toggle-transform, 0deg);
--_toggle-transition-easing: var(--bslib-sidebar-toggle-transition-easing, cubic-bezier(1, 0, 0, 1));
--_toggle-right-transform: var(--bslib-collapse-toggle-right-transform, 180deg);
--_toggle-position-y: calc(var(--_js-toggle-count-this-side, 0) * calc(var(--_icon-size) + var(--_padding)) + var(--_icon-size, 1rem) / 2);
--_toggle-position-x: calc(-2.5 * var(--_icon-size) - var(--bs-card-border-width, 1px));
--_max-height-mobile: var(--bslib-sidebar-max-height-mobile);
--_column-main: minmax(0, 1fr);
// Calculate the height of all toggle buttons in nested sidebar layouts
Expand Down Expand Up @@ -72,8 +74,6 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--_icon-size)), var(--_sideba

> .sidebar {
grid-column: 1 / 2;
width: 100%;
height: 100%;
border-right: var(--_vert-border);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should bring back the width: 100%

Copy link
Member Author

Choose a reason for hiding this comment

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

I checked all of our rules and .sidebar always has both grid-column and grid-row properties, which drive the height and width of the sidebar container. I'm comfortable with both being redundant, but happy to leave width for now if you want.

border-top-right-radius: 0;
border-bottom-right-radius: 0;
Expand Down Expand Up @@ -257,16 +257,12 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--_icon-size)), var(--_sideba
> .collapse-toggle {
color: var(--_main-fg);
// The CSS variable (set via JS) is here to help avoid overlapping toggles
top: calc(
var(--_js-toggle-count-this-side, 0) *
calc(var(--_icon-size) +
var(--_padding)
) + var(--_icon-size, 1rem) / 2);
right: calc(-2.5 * var(--_icon-size) - var(--bs-card-border-width, 1px));
top: var(--_toggle-position-y);
right: var(--_toggle-position-x);
}

&.sidebar-right > .collapse-toggle {
left: calc(-2.5 * var(--_icon-size) - var(--bs-card-border-width, 1px));
left: var(--_toggle-position-x);
right: unset;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
renderTags(page_sidebar("main", title = "Title", sidebar = sidebar(open = "always")))$
html
Output
<body class="bslib-page-fill bslib-gap-spacing bslib-page-sidebar html-fill-container" style="padding:0px;gap:0px;--bslib-page-fill-mobile-height:auto;">
<body class="bslib-page-fill bslib-gap-spacing bslib-flow-mobile bslib-page-sidebar html-fill-container" style="padding:0px;gap:0px;">
<h1 class="bslib-page-title">Title</h1>
<div class="bslib-sidebar-layout bslib-mb-spacing html-fill-item" data-bslib-sidebar-border="false" data-bslib-sidebar-border-radius="false" data-bslib-sidebar-init="TRUE" data-bslib-sidebar-open="always" data-require-bs-caller="layout_sidebar()" data-require-bs-version="5" style="--_sidebar-width:250px;--_max-height-mobile:250px;">
<div class="main bslib-gap-spacing html-fill-container">main</div>
Expand All @@ -52,7 +52,7 @@
Code
renderTags(page_sidebar("main", title = "Title", sidebar = "side"))$html
Output
<body class="bslib-page-fill bslib-gap-spacing bslib-page-sidebar html-fill-container" style="padding:0px;gap:0px;--bslib-page-fill-mobile-height:auto;">
<body class="bslib-page-fill bslib-gap-spacing bslib-flow-mobile bslib-page-sidebar html-fill-container" style="padding:0px;gap:0px;">
<h1 class="bslib-page-title">Title</h1>
<div class="bslib-sidebar-layout bslib-mb-spacing html-fill-item" data-bslib-sidebar-border="false" data-bslib-sidebar-border-radius="false" data-bslib-sidebar-init="TRUE" data-bslib-sidebar-open="desktop" data-require-bs-caller="layout_sidebar()" data-require-bs-version="5" style="--_sidebar-width:250px;--_max-height-mobile:250px;">
<div class="main bslib-gap-spacing html-fill-container">main</div>
Expand Down