-
Notifications
You must be signed in to change notification settings - Fork 59
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
Make sidebar()
's collapse icon configurable
#830
base: main
Are you sure you want to change the base?
Conversation
899330e
to
5fc280e
Compare
cf72028
to
e0f6f13
Compare
e0f6f13
to
1e2e4dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I realized we need to include aria-label
on this button, which brings up the label we use for the toggle. I think we should go ahead and also make this configurable with a collapse_label
argument.
I completely recognize that Given this, what if we were to encapsulate the collapse options into a single function, like Such a function might look like this. Its arguments consult global options that can be set individually and it returns a named list so that we could have sidebar_collapse_options <- function(
icon = getOption("bslib.sidebar.collapse_icon", NULL),
label = getOption("bslib.sidebar.collapse_label", "Toggle Sidebar"),
...
) {
opts <- list(icon = icon, label = label)
names(opts) <- paste0("bslib.sidebar.collapse_", names(opts))
class(opts) <- c("sidebar_collapse", "bslib_options")
opts
}
sidebar_collapse_options()
#> $bslib.sidebar.collapse_icon
#> NULL
#>
#> $bslib.sidebar.collapse_label
#> [1] "Toggle Sidebar"
#>
#> attr(,"class")
#> [1] "sidebar_collapse" "bslib_options" The list names are a little verbose, but that's to support passing options(
sidebar_collapse_options(
icon = bsicons::bs_icon("sliders"),
label = "Toggle settings"
)
)
getOption("bslib.sidebar.collapse_icon")
#> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" class="bi bi-sliders " style="height:1em;width:1em;fill:currentColor;vertical-align:-0.125em;" aria-hidden="true" role="img" ><path fill-rule="evenodd" d="M11.5 2a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zM9.05 3a2.5 2.5 0 0 1 4.9 0H16v1h-2.05a2.5 2.5 0 0 1-4.9 0H0V3h9.05zM4.5 7a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zM2.05 8a2.5 2.5 0 0 1 4.9 0H16v1H6.95a2.5 2.5 0 0 1-4.9 0H0V8h2.05zm9.45 4a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zm-2.45 1a2.5 2.5 0 0 1 4.9 0H16v1h-2.05a2.5 2.5 0 0 1-4.9 0H0v-1h9.05z"></path></svg>
sidebar_collapse_options()
#> $bslib.sidebar.collapse_icon
#> <svg ... >
#>
#> $bslib.sidebar.collapse_label
#> [1] "Toggle settings"
#>
#> attr(,"class")
#> [1] "sidebar_collapse" "bslib_options" This is also what I'm envisioning for |
sidebar()
's collapse icon configurable; change default back to chevron-leftsidebar()
's collapse icon configurable
For posterity, I'm in agreement that we need a way to customize the label (mainly for internationalization purposes), but I'm not convinced the cost of adding That said, I do, in general, like the idea, and I'd probably be in favor of adopting it for And, since it seems logical to consider this in tandem with |
For example: