From 3df9687babf5e32fe52f66b20ddcec615c006858 Mon Sep 17 00:00:00 2001 From: pvictor Date: Sat, 12 Feb 2022 17:05:27 +0100 Subject: [PATCH] bootstrap utilities: b5 compat --- .Rbuildignore | 1 + DESCRIPTION | 2 +- R/bootstrap-utils.R | 53 ++++++++++++++++++++++++++++++++---------- examples/alert.R | 4 ++++ examples/panel.R | 6 +++++ man/bootstrap-utils.Rd | 10 ++++++++ 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 093f7577..a1191712 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -18,3 +18,4 @@ ^\.github$ ^LICENSE\.md$ ^pkgdown$ +^CRAN-SUBMISSION$ diff --git a/DESCRIPTION b/DESCRIPTION index f2ae400c..f24fe771 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: shinyWidgets Title: Custom Inputs Widgets for Shiny -Version: 0.6.4 +Version: 0.6.4.9000 Authors@R: c( person("Victor", "Perrier", email = "victor.perrier@dreamrs.fr", role = c("aut", "cre", "cph")), person("Fanny", "Meyer", role = "aut"), diff --git a/R/bootstrap-utils.R b/R/bootstrap-utils.R index d800cc25..e6e53bae 100644 --- a/R/bootstrap-utils.R +++ b/R/bootstrap-utils.R @@ -46,7 +46,7 @@ panel <- function(..., ) } tags$div( - class = paste0("panel card mb-3 panel-", status), + class = sprintf("panel card mb-3 panel-%1$s border-%1$s", status), heading, body, extra, if (!is.null(footer)) tags$div(class = "panel-footer card-footer", footer) ) @@ -59,18 +59,47 @@ panel <- function(..., #' @importFrom htmltools tags HTML alert <- function(..., status = c("info", "success", "danger", "warning"), dismissible = FALSE) { status <- match.arg(status) + if (!isTRUE(dismissible)) { + return(tags$div( + class = paste0("alert alert-", status), + ... + )) + } + tagFunction(function() { + theme <- shiny::getCurrentTheme() + if (!bslib::is_bs_theme(theme)) { + return(markup_alert_dismiss_bs3(..., status = status)) + } + if (bslib::theme_version(theme) %in% c("5")) { + return(markup_alert_dismiss_bs5(..., status = status)) + } + markup_alert_dismiss_bs3(..., status = status) + }) +} + +markup_alert_dismiss_bs3 <- function(..., status) { + tags$div( + class = sprintf("alert alert-%s alert-dismissible", status), + tags$button( + type = "button", + class = "close", + `data-dismiss` = "alert", + `aria-label` = "Close", + tags$span(`aria-hidden` = "true", HTML("×")) + ), + ... + ) +} + +markup_alert_dismiss_bs5 <- function(..., status) { tags$div( - class = paste0("alert alert-", status), - class = if (isTRUE(dismissible)) "alert-dismissible", - if (isTRUE(dismissible)) { - tags$button( - type = "button", - class = "close", - `data-dismiss` = "alert", - `aria-label` = "Close", - tags$span(`aria-hidden` = "true", HTML("×")) - ) - }, + class = sprintf("alert alert-%s alert-dismissible", status), + tags$button( + type = "button", + class = "btn-close", + `data-bs-dismiss` = "alert", + `aria-label` = "Close" + ), ... ) } diff --git a/examples/alert.R b/examples/alert.R index 5d577213..79a4ea11 100644 --- a/examples/alert.R +++ b/examples/alert.R @@ -5,6 +5,10 @@ library(shiny) library(shinyWidgets) ui <- fluidPage( + + # Try with different Bootstrap version + # theme = bslib::bs_theme(version = 5), + tags$h2("Alerts"), fluidRow( column( diff --git a/examples/panel.R b/examples/panel.R index a969476a..5b393f3d 100644 --- a/examples/panel.R +++ b/examples/panel.R @@ -5,6 +5,8 @@ library(shiny) library(shinyWidgets) ui <- fluidPage( + # Try with different Bootstrap version + # theme = bslib::bs_theme(version = 5), tags$h2("Bootstrap panel"), @@ -12,6 +14,10 @@ ui <- fluidPage( panel( "Content goes here", ), + panel( + "With status", + status = "primary" + ), # With header and footer panel( diff --git a/man/bootstrap-utils.Rd b/man/bootstrap-utils.Rd index 87ef0352..e4b5783a 100644 --- a/man/bootstrap-utils.Rd +++ b/man/bootstrap-utils.Rd @@ -52,6 +52,8 @@ library(shiny) library(shinyWidgets) ui <- fluidPage( + # Try with different Bootstrap version + # theme = bslib::bs_theme(version = 5), tags$h2("Bootstrap panel"), @@ -59,6 +61,10 @@ ui <- fluidPage( panel( "Content goes here", ), + panel( + "With status", + status = "primary" + ), # With header and footer panel( @@ -112,6 +118,10 @@ library(shiny) library(shinyWidgets) ui <- fluidPage( + + # Try with different Bootstrap version + # theme = bslib::bs_theme(version = 5), + tags$h2("Alerts"), fluidRow( column(