Skip to content

Commit

Permalink
chore: Enable return of dependency CSS as Sass files (#4044)
Browse files Browse the repository at this point in the history
* chore: Enable return of dependency CSS as Sass files

Makes it possible to extract the Sass files prior to compilation for the following CSS:

* shiny
* selectize
* ionrangeslider
* daterange picker

* refactor: Take a more functional approach

* fix: missing selectizeDir

* rename: __SassLayer --> __Sass
  • Loading branch information
gadenbuie committed Jun 13, 2024
1 parent 9fd4ba1 commit 0b7fda7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
10 changes: 7 additions & 3 deletions R/input-date.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ datePickerDependency <- function(theme) {
)
}

datePickerSass <- function() {
sass::sass_file(
system_file(package = "shiny", "www/shared/datepicker/scss/build3.scss")
)
}

datePickerCSS <- function(theme) {
if (!is_bs_theme(theme)) {
return(htmlDependency(
Expand All @@ -164,10 +170,8 @@ datePickerCSS <- function(theme) {
))
}

scss_file <- system_file(package = "shiny", "www/shared/datepicker/scss/build3.scss")

bslib::bs_dependency(
input = sass::sass_file(scss_file),
input = datePickerSass(),
theme = theme,
name = "bootstrap-datepicker",
version = version_bs_date_picker,
Expand Down
16 changes: 11 additions & 5 deletions R/input-select.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,20 @@ selectizeDependencyFunc <- function(theme) {
return(selectizeStaticDependency(version_selectize))
}

selectizeDir <- system_file(package = "shiny", "www/shared/selectize/")
bs_version <- bslib::theme_version(theme)
stylesheet <- file.path(
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),
# but DT, crosstalk, and maybe other pkgs include selectize JS/CSS
# in HTML dependency named selectize, so if we were to change that
# name, the JS/CSS would be loaded/included twice, which leads to
# strange issues, especially since we now include a 3rd party
# accessibility plugin https://github.com/rstudio/shiny/pull/3153
selectizeDir <- system_file(package = "shiny", "www/shared/selectize/")
script <- file.path(selectizeDir, selectizeScripts())

bslib::bs_dependency(
input = sass::sass_file(stylesheet),
input = selectizeSass(bs_version),
theme = theme,
name = "selectize",
version = version_selectize,
Expand All @@ -265,6 +263,14 @@ selectizeDependencyFunc <- function(theme) {
)
}

selectizeSass <- function(bs_version) {
selectizeDir <- system_file(package = "shiny", "www/shared/selectize/")
stylesheet <- file.path(
selectizeDir, "scss", paste0("selectize.bootstrap", bs_version, ".scss")
)
sass::sass_file(stylesheet)
}

selectizeStaticDependency <- function(version) {
htmlDependency(
"selectize",
Expand Down
16 changes: 10 additions & 6 deletions R/input-slider.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ ionRangeSliderDependency <- function() {
)
}

ionRangeSliderDependencySass <- function() {
list(
list(accent = "$component-active-bg"),
sass::sass_file(
system_file(package = "shiny", "www/shared/ionrangeslider/scss/shiny.scss")
)
)
}

ionRangeSliderDependencyCSS <- function(theme) {
if (!is_bs_theme(theme)) {
return(htmlDependency(
Expand All @@ -234,12 +243,7 @@ ionRangeSliderDependencyCSS <- function(theme) {
}

bslib::bs_dependency(
input = list(
list(accent = "$component-active-bg"),
sass::sass_file(
system_file(package = "shiny", "www/shared/ionrangeslider/scss/shiny.scss")
)
),
input = ionRangeSliderDependencySass(),
theme = theme,
name = "ionRangeSlider",
version = version_ion_range_slider,
Expand Down
15 changes: 9 additions & 6 deletions R/shinyui.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ shinyDependencies <- function() {
)
}

shinyDependencySass <- function(bs_version) {
bootstrap_scss <- paste0("shiny.bootstrap", bs_version, ".scss")

scss_home <- system_file("www/shared/shiny_scss", package = "shiny")
scss_files <- file.path(scss_home, c(bootstrap_scss, "shiny.scss"))
lapply(scss_files, sass::sass_file)
}

shinyDependencyCSS <- function(theme) {
version <- get_package_version("shiny")

Expand All @@ -150,14 +158,9 @@ shinyDependencyCSS <- function(theme) {
}

bs_version <- bslib::theme_version(theme)
bootstrap_scss <- paste0("shiny.bootstrap", bs_version, ".scss")

scss_home <- system_file("www/shared/shiny_scss", package = "shiny")
scss_files <- file.path(scss_home, c(bootstrap_scss, "shiny.scss"))
scss_files <- lapply(scss_files, sass::sass_file)

bslib::bs_dependency(
input = scss_files,
input = shinyDependencySass(bs_version),
theme = theme,
name = "shiny-sass",
version = version,
Expand Down

0 comments on commit 0b7fda7

Please sign in to comment.