Skip to content

Commit f3d8532

Browse files
gadenbuiecpsievert
andauthored
feat(sidebar): Redesign sidebar toggle and mobile layout (#798)
Co-authored-by: Carson Sievert <[email protected]>
1 parent 7c72c6d commit f3d8532

File tree

12 files changed

+164
-123
lines changed

12 files changed

+164
-123
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
* Improved the style and appearance of the button to enter full screen in `card()`s and `value_box()`es to better adapt to Bootstrap's dark mode. (#780)
3535

36+
* `layout_sidebar()` received a new design. The button to collapse and expand the sidebar now appears at the top edge of the sidebar, and we now use the [arrow-bar-left](https://icons.getbootstrap.com/icons/arrow-bar-left/) icon instead of [chevron-left](https://icons.getbootstrap.com/icons/chevron-left/). On mobile devices, the sidebar now fills the `layout_sidebar()` area as an overlay, rather than expanding from above the main content area. **Note** the `max_mobile_height` argument of `sidebar()` determines the maximum height of the sidebar area on mobile, but it now only applies when `open = "always"`. (#798)
37+
3638
## Bug fixes
3739

3840
* `toggle_switch()` now works correctly when called from within a Shiny module. `update_switch()` worked as expected, but `toggle_switch()` didn't apply the module's namespace to the `id` of the switch to be updated. (#769)

R/sidebar.R

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@
5050
#' color, e.g. setting `bg` chooses an appropriate `fg` color.
5151
#' @param class CSS classes for the sidebar container element, in addition to
5252
#' the fixed `.sidebar` class.
53-
#' @param max_height_mobile The maximum height of the horizontal sidebar when
54-
#' viewed on mobile devices. The default is `250px` unless the sidebar is
55-
#' included in a [layout_sidebar()] with a specified height, in which case
56-
#' the default is to take up no more than 50% of the layout container.
53+
#' @param max_height_mobile A [CSS length unit][htmltools::validateCssUnit()]
54+
#' defining the maximum height of the horizontal sidebar when viewed on mobile
55+
#' devices. Only applies to always-open sidebars that use `open = "always"`,
56+
#' where by default the sidebar container is placed below the main content
57+
#' container on mobile devices.
5758
#' @param gap A [CSS length unit][htmltools::validateCssUnit()] defining the
5859
#' vertical `gap` (i.e., spacing) between adjacent elements provided to `...`.
5960
#' @param padding Padding within the sidebar itself. This can be a numeric
@@ -91,6 +92,11 @@ sidebar <- function(
9192

9293
open <- rlang::arg_match(open)
9394

95+
if (!is.null(max_height_mobile) && open != "always") {
96+
rlang::warn('The `max_height_mobile` argument only applies to when `open = "always"`.')
97+
max_height_mobile <- NULL
98+
}
99+
94100
if (!is.null(id)) {
95101
if (length(id) != 1 || is.na(id) || !nzchar(id)) {
96102
rlang::abort("`id` must be a non-empty, length-1 character string or `NULL`.")
@@ -210,8 +216,6 @@ layout_sidebar <- function(
210216
class = "main",
211217
class = if (fillable) "bslib-gap-spacing",
212218
style = css(
213-
background_color = bg,
214-
color = fg,
215219
padding = validateCssPadding(padding),
216220
gap = validateCssUnit(gap)
217221
),
@@ -237,8 +241,10 @@ layout_sidebar <- function(
237241
`data-bslib-sidebar-border-radius` = if (!is.null(border_radius)) tolower(border_radius),
238242
style = css(
239243
"--bslib-sidebar-width" = sidebar$width,
240-
"--bslib-sidebar-bg" = if (!is.null(sidebar$color$bg)) sidebar$color$bg,
241-
"--bslib-sidebar-fg" = if (!is.null(sidebar$color$fg)) sidebar$color$fg,
244+
"--bslib-sidebar-bg" = sidebar$color$bg,
245+
"--bslib-sidebar-fg" = sidebar$color$fg,
246+
"--bslib-sidebar-main-fg" = fg,
247+
"--bslib-sidebar-main-bg" = bg,
242248
"--bs-card-border-color" = border_color,
243249
height = validateCssUnit(height),
244250
"--bslib-sidebar-max-height-mobile" = max_height_mobile
@@ -291,10 +297,10 @@ sidebar_toggle <- toggle_sidebar
291297

292298
collapse_icon <- function() {
293299
if (!is_installed("bsicons")) {
294-
icon <- "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" class=\"bi bi-chevron-down collapse-icon\" style=\"fill:currentColor;\" aria-hidden=\"true\" role=\"img\" ><path fill-rule=\"evenodd\" d=\"M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z\"></path></svg>"
300+
icon <- "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\" class=\"bi bi-arrow-bar-left collapse-icon\" style=\"fill:currentColor;\" aria-hidden=\"true\" role=\"img\" ><path fill-rule=\"evenodd\" d=\"M12.5 15a.5.5 0 0 1-.5-.5v-13a.5.5 0 0 1 1 0v13a.5.5 0 0 1-.5.5ZM10 8a.5.5 0 0 1-.5.5H3.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L3.707 7.5H9.5a.5.5 0 0 1 .5.5Z\"></path></svg>"
295301
return(HTML(icon))
296302
}
297-
bsicons::bs_icon("chevron-down", class = "collapse-icon", size = NULL)
303+
bsicons::bs_icon("arrow-bar-left", class = "collapse-icon", size = NULL)
298304
}
299305

300306
sidebar_init_js <- function() {

inst/components/dist/sidebar/sidebar.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/components/dist/sidebar/sidebar.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/components/dist/sidebar/sidebar.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/components/dist/sidebar/sidebar.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/components/dist/sidebar/sidebar.min.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)