From 10406b0e7a310931f0604efdf470ca038aac383c Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Wed, 13 Dec 2023 23:42:00 -0800 Subject: [PATCH 01/24] Add input_task_button, an actionButton with busy state --- DESCRIPTION | 1 + NAMESPACE | 3 + R/buttons.R | 106 ++++++++++++++ inst/components/dist/web-components.js | 135 ++++++++++++++++-- inst/components/dist/web-components.js.map | 8 +- inst/components/dist/web-components.min.js | 24 ++-- .../components/dist/web-components.min.js.map | 8 +- man/input_task_button.Rd | 67 +++++++++ srcts/src/components/webcomponents/index.ts | 23 +-- .../components/webcomponents/taskButton.ts | 82 +++++++++++ 10 files changed, 418 insertions(+), 39 deletions(-) create mode 100644 R/buttons.R create mode 100644 man/input_task_button.Rd create mode 100644 srcts/src/components/webcomponents/taskButton.ts diff --git a/DESCRIPTION b/DESCRIPTION index e502fdca3..3c7fd554b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -124,6 +124,7 @@ Collate: 'bs-theme-update.R' 'bs-theme.R' 'bslib-package.R' + 'buttons.R' 'card.R' 'deprecated.R' 'files.R' diff --git a/NAMESPACE b/NAMESPACE index 6713dea1d..97feb79a4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -76,8 +76,10 @@ export(font_collection) export(font_face) export(font_google) export(font_link) +export(icon_spinner) export(input_dark_mode) export(input_switch) +export(input_task_button) export(is.card_item) export(is_bs_theme) export(is_fill_carrier) @@ -142,6 +144,7 @@ export(toggle_tooltip) export(tooltip) export(update_popover) export(update_switch) +export(update_task_button) export(update_tooltip) export(value_box) export(value_box_theme) diff --git a/R/buttons.R b/R/buttons.R new file mode 100644 index 000000000..35dc51da7 --- /dev/null +++ b/R/buttons.R @@ -0,0 +1,106 @@ +button_spec <- function(label, icon, disabled = c(FALSE, TRUE)) { + structure( + list(label = label, icon = icon, disabled = disabled), + class = c("button_spec", "list") + ) +} + +apply_button_spec <- function(status, value, defaults, ...) { + if (is.character(value) || is.null(value)) { + value <- list(label = value) + } + resolved <- defaults + resolved[names(value)] <- value + + tagList( + tags$span(slot=paste0(status, "-icon"), + resolved[["icon"]] + ), + tags$span(slot=paste0(status, "-label"), + resolved[["label"]] + ) + ) +} + +#' Button for launching longer-running operations +#' +#' `input_task_button` is a button whose value is initially zero, and increments +#' by one each time it is pressed. It is similar to [shiny::actionButton()], +#' except that upon click, it puts itself into a busy state that prevents the +#' user from clicking it again. `update_task_button(id, busy = FALSE)` must be +#' called from the server function to re-enable the button. +#' +#' @param id The `input` slot that will be used to access the value. +#' @param label The label of the button while it is in ready (clickable) state; +#' usually a string. +#' @param icon An optional icon to display next to the label while the button is +#' in ready state. See [fontawesome::fa_i()]. +#' @param busy_label The label of the button while it is busy. +#' @param busy_icon The icon to display while the button is busy. By default, a +#' spinning "chasing arrows" icon is used. +#' @param type One of the Bootstrap theme colors (`"primary"`, `"default"`, +#' `"secondary"`, `"success"`, `"danger"`, `"warning"`, `"info"`, `"light"`, +#' `"dark"`), or `NULL` to leave off the Bootstrap-specific button CSS classes +#' altogether. +#' @param ... Named arguments become attributes to include on the `