Skip to content
Merged
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 NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

* Added `input_task_button()`, a replacement for `shiny::actionButton()` that automatically prevents an operation from being submitted multiple times. It does this by, upon click, immediately transitioning to a "Processing..." visual state that does not let the button be clicked again. The button resets to its clickable state automatically after the reactive flush it causes is complete; or, for advanced scenarios, `update_task_button()` can be used to manually control when the button resets.

* Both `card()` and `value_box()` now take an `id` argument that, when provided, is used to report the full screen state of the card or value box to the server. For example, when using `card(id = "my_card", full_screen = TRUE)` you can determine if the card is currently in full screen mode by reading the boolean value of `input$my_card$full_screen`. (#1006)

## Improvements

* `layout_columns()` was rewritten in Typescript as a custom element to improve the portability of the component. (#931)
Expand Down
24 changes: 20 additions & 4 deletions R/card.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#' together into one `wrapper` call (e.g. given `card("a", "b",
#' card_body("c"), "d")`, `wrapper` would be called twice, once with `"a"` and
#' `"b"` and once with `"d"`).
#' @param id Provide a unique identifier for the `card()` or `value_box()` to
#' report its state to Shiny. For example, using `id = "my_card"`, you can
#' observe the card's full screen state with `input$my_card$full_screen`.
#'
#' @return A [htmltools::div()] tag.
#'
Expand Down Expand Up @@ -70,21 +73,34 @@
#' )
#' )
#'
card <- function(..., full_screen = FALSE, height = NULL, max_height = NULL, min_height = NULL, fill = TRUE, class = NULL, wrapper = card_body) {

card <- function(
...,
full_screen = FALSE,
height = NULL,
max_height = NULL,
min_height = NULL,
fill = TRUE,
class = NULL,
wrapper = card_body,
id = NULL
) {
args <- rlang::list2(...)
argnames <- rlang::names2(args)

attribs <- args[nzchar(argnames)]
children <- as_card_items(args[!nzchar(argnames)], wrapper = wrapper)

if (full_screen && is.null(attribs$id)) {
is_shiny_input <- !is.null(id)

if (full_screen && is.null(id)) {
# a11y: full screen cards need an ID for aria-controls on the toggle button
attribs$id <- paste0("bslib-card-", p_randomInt(1000, 10000))
id <- paste0("bslib-card-", p_randomInt(1000, 10000))
}

tag <- div(
id = id,
class = "card bslib-card bslib-mb-spacing",
class = if (is_shiny_input) "bslib-card-input",
style = css(
height = validateCssUnit(height),
max_height = validateCssUnit(max_height),
Expand Down
2 changes: 2 additions & 0 deletions R/value-box.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ value_box <- function(
max_height = NULL,
fill = TRUE,
class = NULL,
id = NULL,
theme_color = deprecated()
) {
dots <- separate_arguments(...)
Expand Down Expand Up @@ -158,6 +159,7 @@ value_box <- function(
class,
if (!is.null(showcase)) showcase_layout$class
),
id = id,
full_screen = full_screen,
height = height,
max_height = max_height,
Expand Down
39 changes: 29 additions & 10 deletions inst/components/dist/components.js

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

6 changes: 3 additions & 3 deletions inst/components/dist/components.js.map

Large diffs are not rendered by default.

Loading