Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export(toolbar)
export(toolbar_divider)
export(toolbar_input_button)
export(toolbar_input_select)
export(toolbar_input_switch)
export(toolbar_spacer)
export(tooltip)
export(update_code_editor)
Expand All @@ -176,6 +177,7 @@ export(update_switch)
export(update_task_button)
export(update_toolbar_input_button)
export(update_toolbar_input_select)
export(update_toolbar_input_switch)
export(update_tooltip)
export(value_box)
export(value_box_theme)
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
125 changes: 125 additions & 0 deletions R/toolbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,128 @@ toolbar_divider <- function(..., width = NULL, gap = NULL) {
toolbar_spacer <- function() {
div(class = "bslib-toolbar-spacer")
}


#' Toolbar Input Switch
#'
#' @description
#' Create a switch input control suitable for use within a [toolbar()]. This is
#' a convenience wrapper around [input_switch()] with sensible defaults for
#' toolbar contexts.
#'
#' @section Updating toolbar switches:
#'
#' You can dynamically update a toolbar switch using [update_toolbar_input_switch()],
#' which is a convenience wrapper around [update_switch()]. This allows you to
#' update the switch's label and value from the server.
#'
#' For example:
#'
#' ```r
#' library(shiny)
#' library(bslib)
#'
#' ui <- page_fluid(
#' card(
#' card_header(
#' "Settings",
#' toolbar(
#' align = "right",
#' toolbar_input_switch(
#' id = "auto_save",
#' label = "Auto-save",
#' value = FALSE
#' )
#' )
#' ),
#' card_body(
#' actionButton("toggle", "Toggle Auto-save"),
#' verbatimTextOutput("status")
#' )
#' )
#' )
#'
#' server <- function(input, output, session) {
#' output$status <- renderPrint({
#' list(auto_save = input$auto_save)
#' })
#'
#' observeEvent(input$toggle, {
#' update_toolbar_input_switch(
#' "auto_save",
#' value = !input$auto_save
#' )
#' })
#' }
#'
#' shinyApp(ui, server)
#' ```
#'
#' @examplesIf rlang::is_interactive()
#' # Basic toolbar with switches
#' toolbar(
#' align = "right",
#' toolbar_input_switch(id = "notifications", label = "Notifications", value = TRUE),
#' toolbar_divider(),
#' toolbar_input_switch(id = "dark_mode", label = "Dark Mode", value = FALSE)
#' )
#'
#' # Switch in card header
#' card(
#' card_header(
#' "Chart Options",
#' toolbar(
#' align = "right",
#' toolbar_input_switch(id = "show_legend", label = "Show Legend", value = TRUE),
#' toolbar_input_switch(id = "show_grid", label = "Show Grid", value = TRUE)
#' )
#' ),
#' card_body("Chart content here")
#' )
#'
#' # Switch with toolbar_spacer for alignment
#' toolbar(
#' width = "100%",
#' "Enable feature",
#' toolbar_spacer(),
#' toolbar_input_switch(id = "feature", label = "Enable feature", value = FALSE)
#' )
#'
#' @inheritParams input_switch
#'
#' @return Returns a switch input suitable for use in a toolbar.
#'
#' @describeIn toolbar_input_switch Create a toolbar switch input.
#' @family toolbar components
#' @export
toolbar_input_switch <- function(
id,
label = NULL,
value = FALSE
) {
input_switch(
id = id,
label = label,
value = value,
width = NULL
)
}

#' @param session A Shiny session object (the default should almost always be
#' used).
#'
#' @describeIn toolbar_input_switch Update a toolbar switch input.
#' @export
update_toolbar_input_switch <- function(
id,
label = NULL,
value = NULL,
session = get_current_session()
) {
update_switch(
id = id,
label = label,
value = value,
session = session
)
}
2 changes: 1 addition & 1 deletion inst/components/dist/code-editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion inst/components/dist/code-editor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion inst/components/dist/components.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/components/dist/components.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions inst/components/dist/components.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/components/dist/web-components.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading