From 0b7fda707e4846d2de06f63db312ac35dacf503a Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Thu, 13 Jun 2024 16:08:54 -0400 Subject: [PATCH] chore: Enable return of dependency CSS as Sass files (#4044) * 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 --- R/input-date.R | 10 +++++++--- R/input-select.R | 16 +++++++++++----- R/input-slider.R | 16 ++++++++++------ R/shinyui.R | 15 +++++++++------ 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/R/input-date.R b/R/input-date.R index bfc7ae3970..7278f3718e 100644 --- a/R/input-date.R +++ b/R/input-date.R @@ -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( @@ -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, diff --git a/R/input-select.R b/R/input-select.R index 3cbcb94d59..1061461924 100644 --- a/R/input-select.R +++ b/R/input-select.R @@ -241,11 +241,8 @@ 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 @@ -253,10 +250,11 @@ selectizeDependencyFunc <- function(theme) { # 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, @@ -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", diff --git a/R/input-slider.R b/R/input-slider.R index 9c3009a645..30bfae1979 100644 --- a/R/input-slider.R +++ b/R/input-slider.R @@ -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( @@ -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, diff --git a/R/shinyui.R b/R/shinyui.R index 4c9d938d41..6a5e35dc34 100644 --- a/R/shinyui.R +++ b/R/shinyui.R @@ -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") @@ -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,