Skip to content

Commit

Permalink
bootstrap utilities: b5 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Feb 12, 2022
1 parent 02bc552 commit 3df9687
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 13 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
^\.github$
^LICENSE\.md$
^pkgdown$
^CRAN-SUBMISSION$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut", "cre", "cph")),
person("Fanny", "Meyer", role = "aut"),
Expand Down
53 changes: 41 additions & 12 deletions R/bootstrap-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -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("&times;"))
),
...
)
}

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("&times;"))
)
},
class = sprintf("alert alert-%s alert-dismissible", status),
tags$button(
type = "button",
class = "btn-close",
`data-bs-dismiss` = "alert",
`aria-label` = "Close"
),
...
)
}
Expand Down
4 changes: 4 additions & 0 deletions examples/alert.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions examples/panel.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ library(shiny)
library(shinyWidgets)

ui <- fluidPage(
# Try with different Bootstrap version
# theme = bslib::bs_theme(version = 5),

tags$h2("Bootstrap panel"),

# Default
panel(
"Content goes here",
),
panel(
"With status",
status = "primary"
),

# With header and footer
panel(
Expand Down
10 changes: 10 additions & 0 deletions man/bootstrap-utils.Rd

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

0 comments on commit 3df9687

Please sign in to comment.