Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap 5 support #3410

Merged
merged 4 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 2 additions & 6 deletions R/input-select.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,9 @@ selectizeDependencyFunc <- function(theme) {
}

selectizeDir <- system.file(package = "shiny", "www/shared/selectize/")
bs_version <- bslib::theme_version(theme)
stylesheet <- file.path(
selectizeDir, "scss",
if ("3" %in% bslib::theme_version(theme)) {
"selectize.bootstrap3.scss"
} else {
"selectize.bootstrap4.scss"
}
selectizeDir, "scss", paste0("selectize.bootstrap", bs_version, ".scss")
)
# It'd be cleaner to ship the JS in a separate, href-based,
# HTML dependency (which we currently do for other themable widgets),
Expand Down
36 changes: 27 additions & 9 deletions R/modal.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,25 @@ removeModal <- function(session = getDefaultReactiveDomain()) {
#' }
#' @export
modalDialog <- function(..., title = NULL, footer = modalButton("Dismiss"),
size = c("m", "s", "l"), easyClose = FALSE, fade = TRUE) {
size = c("m", "s", "l", "xl"), easyClose = FALSE, fade = TRUE) {
cpsievert marked this conversation as resolved.
Show resolved Hide resolved

size <- match.arg(size)

cls <- if (fade) "modal fade" else "modal"
div(id = "shiny-modal", class = cls, tabindex = "-1",
`data-backdrop` = if (!easyClose) "static",
`data-keyboard` = if (!easyClose) "false",
backdrop <- if (!easyClose) "static"
keyboard <- if (!easyClose) "false"
div(
id = "shiny-modal",
class = "modal",
class = if (fade) "fade",
tabindex = "-1",
`data-backdrop` = backdrop,
`data-bs-backdrop` = backdrop,
`data-keyboard` = keyboard,
`data-bs-keyboard` = keyboard,

div(
class = "modal-dialog",
class = switch(size, s = "modal-sm", m = NULL, l = "modal-lg"),
class = switch(size, s = "modal-sm", m = NULL, l = "modal-lg", xl = "modal-xl"),
div(class = "modal-content",
if (!is.null(title)) div(class = "modal-header",
tags$h4(class = "modal-title", title)
Expand All @@ -171,14 +178,25 @@ modalDialog <- function(..., title = NULL, footer = modalButton("Dismiss"),
if (!is.null(footer)) div(class = "modal-footer", footer)
)
),
tags$script("$('#shiny-modal').modal().focus();")
tags$script(
"if (window.bootstrap) {
var modal = new bootstrap.Modal(document.getElementById('shiny-modal'));
modal.show();
} else {
$('#shiny-modal').modal().focus();
}"
)
)
}

#' @export
#' @rdname modalDialog
modalButton <- function(label, icon = NULL) {
tags$button(type = "button", class = "btn btn-default",
`data-dismiss` = "modal", validateIcon(icon), label
tags$button(
type = "button",
class = "btn btn-default",
`data-dismiss` = "modal",
`data-bs-dismiss` = "modal",
validateIcon(icon), label
)
}
4 changes: 2 additions & 2 deletions R/showcase.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ navTabsHelper <- function(files, prefix = "") {
with(tags,
li(class=if (tolower(file) %in% c("app.r", "server.r")) "active" else "",
a(href=paste("#", gsub(".", "_", file, fixed=TRUE), "_code", sep=""),
"data-toggle"="tab", paste0(prefix, file)))
"data-toggle"="tab", "data-bs-toggle"="tab", paste0(prefix, file)))
)
})
}
Expand All @@ -92,7 +92,7 @@ navTabsDropdown <- function(files) {
if (length(files) > 0) {
with(tags,
li(role="presentation", class="dropdown",
a(class="dropdown-toggle", `data-toggle`="dropdown", href="#",
a(class="dropdown-toggle", `data-toggle`="dropdown", `data-bs-toggle`="dropdown", href="#",
role="button", `aria-haspopup`="true", `aria-expanded`="false",
"www", span(class="caret")
),
Expand Down
2 changes: 1 addition & 1 deletion inst/www/shared/selectize/scss/selectize.bootstrap4.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $selectize-color-text: $input-color !default;
$selectize-color-highlight: rgba(255,237,40,0.4) !default;
$selectize-color-input: $input-bg !default;
$selectize-color-input-full: $input-bg !default;
$selectize-color-input-error: theme-color("danger") !default;
$selectize-color-input-error: $danger !default;
$selectize-color-input-error-focus: darken($selectize-color-input-error, 10%) !default;
$selectize-color-disabled: $input-bg !default;
$selectize-color-item: mix($selectize-color-input, $selectize-color-text, 90%) !default;
Expand Down
3 changes: 3 additions & 0 deletions inst/www/shared/selectize/scss/selectize.bootstrap5.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$input-line-height-sm: $form-select-line-height !default;
@import 'selectize.bootstrap4';
.selectize-control{padding:0;}
13 changes: 13 additions & 0 deletions tools/selectize-patches/005-bs5-support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/inst/www/shared/selectize/scss/selectize.bootstrap4.scss b/inst/www/shared/selectize/scss/selectize.bootstrap4.scss
index 44dae201..03b4f491 100644
--- a/inst/www/shared/selectize/scss/selectize.bootstrap4.scss
+++ b/inst/www/shared/selectize/scss/selectize.bootstrap4.scss
@@ -13,7 +13,7 @@ $selectize-color-text: $input-color !default;
$selectize-color-highlight: rgba(255,237,40,0.4) !default;
$selectize-color-input: $input-bg !default;
$selectize-color-input-full: $input-bg !default;
-$selectize-color-input-error: theme-color("danger") !default;
+$selectize-color-input-error: $danger !default;
$selectize-color-input-error-focus: darken($selectize-color-input-error, 10%) !default;
$selectize-color-disabled: $input-bg !default;
$selectize-color-item: mix($selectize-color-input, $selectize-color-text, 90%) !default;
13 changes: 12 additions & 1 deletion tools/updateSelectize.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ scss <- readLines(scss_file)
scss <- scss[!grepl('@import\\s+"\\.\\./bootstrap', scss)]
writeLines(scss, scss_file)

# Support Bootstrap 5 as well
# https://github.com/selectize/selectize.js/issues/1584
writeLines(
c(
"$input-line-height-sm: $form-select-line-height !default;",
"@import 'selectize.bootstrap4';",
".selectize-control{padding:0;}"
),
file.path(target, "selectize.bootstrap5.scss")
)

## -----------------------------------------------------------------
## Fourth, download Bootstrap 3 SASS port
## https://github.com/herschel666/selectize-scss
Expand Down Expand Up @@ -120,4 +131,4 @@ for (patch in list.files(patch_dir, full.names = TRUE)) {
# =============================================================================
# Generate minified js
# =============================================================================
withr::with_dir(find_package_root_file("tools"), system("yarn grunt"))
withr::with_dir(find_package_root_file("srcts"), system("yarn build"))