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

chore: Enable return of dependency CSS as Sass files #4044

Merged
merged 6 commits into from
Jun 13, 2024
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
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) {
)
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer Layer to not be in the name since I'd expect it to return a sass::sass_layer().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I used that because 1. It's not clear to me what exactly a sass layer is and 2. in bslib we already had component_dependency_sass() which compiles Sass but actually returns an HTMLDependency.


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 = datePickerSassLayer(),
theme = theme,
name = "bootstrap-datepicker",
version = version_bs_date_picker,
Expand Down
15 changes: 10 additions & 5 deletions R/input-select.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -256,7 +253,7 @@ selectizeDependencyFunc <- function(theme) {
script <- file.path(selectizeDir, selectizeScripts())

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

selectizeSassLayer <- 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() {
)
}

ionRangeSliderDependencySassLayer <- 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 = ionRangeSliderDependencySassLayer(),
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 @@ -134,6 +134,14 @@ shinyDependencies <- function() {
)
}

shinyDependencySassLayer <- 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 @@ -149,14 +157,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 = shinyDependencySassLayer(bs_version),
theme = theme,
name = "shiny-sass",
version = version,
Expand Down