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
17 changes: 7 additions & 10 deletions R/verbatim_popup.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ verbatim_popup_deps <- function() {
version = utils::packageVersion("teal.widgets"),
package = "teal.widgets",
src = "verbatim-popup",
style = "verbatim-popup.css",
script = "verbatim-popup.js"
)
}
Expand Down Expand Up @@ -42,21 +43,17 @@ verbatim_popup_ui <- function(id, button_label, type = c("button", "link"), ...)
checkmate::assert_string(id)
checkmate::assert_string(button_label)

ui_function <- switch(match.arg(type),
"button" = shiny::actionButton,
"link" = shiny::actionLink
)

ns <- shiny::NS(id)
ui_args <- list(
inputId = ns("button"),
label = button_label
)

shiny::tagList(
verbatim_popup_deps(),
shinyjs::useShinyjs(),
do.call(ui_function, c(ui_args, list(...)))
shiny::actionButton(
inputId = ns("button"),
label = button_label,
class = c("teal-widgets-busy-disable", match.arg(type)),
...
)
)
}

Expand Down
11 changes: 11 additions & 0 deletions inst/verbatim-popup/verbatim-popup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.teal-widgets-busy-disable.link {
color: var(--bs-primary);
background-color: transparent;
border: none;
border-bottom: 2px solid var(--bs-primary-border-subtle);
padding: 0.5rem;
}

.teal-widgets-busy-disable.link:hover {
border-color: var(--bs-primary);
}
9 changes: 9 additions & 0 deletions inst/verbatim-popup/verbatim-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ const copyToClipboard = (elementIdToCopy, onFailure = () => null) => {

document.body.removeChild(textArea);
};

// Primarily added to make sure the user does not open multiple modals when shiny is busy.
// https://github.com/rstudio/shiny/issues/4261
$(document).on("shiny:busy", function () {
$(".teal-widgets-busy-disable").prop("disabled", true);
});
$(document).on("shiny:idle", function () {
$(".teal-widgets-busy-disable").prop("disabled", false);
});
4 changes: 2 additions & 2 deletions tests/testthat/test-verbatim_popup.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ testthat::test_that("verbatim_popup_ui with type 'button' produces a button", {
testthat::expect_true(grepl("^<button ", ui_char))
})

testthat::test_that("verbatim_popup_ui with type 'link' produces a link", {
testthat::test_that("verbatim_popup_ui with type 'link' produces a button with a class link", {
ui_char <- as.character(verbatim_popup_ui(id = "test_id", button_label = "Test button label", type = "link"))
testthat::expect_true(grepl("^<a ", ui_char))
testthat::expect_true(grepl("^<button class=.+\\blink\\b", ui_char))
})
Loading