Retrieve Sass variable values from the current theme
Source:R/bs-theme-preview.R
bs_get_variables.Rd
Useful for retriving a variable from the current theme and using the value to inform another R function.
Arguments
- theme
a
bs_theme()
object.- varnames
a character string referencing a Sass variable in the current theme.
Value
a character string containing a CSS/Sass value.
If the variable(s) are not defined, their value is NA
.
Examples
vars <- c("body-bg", "body-color", "primary", "border-radius")
bs_get_variables(bs_theme(), varnames = vars)
#> body-bg body-color primary border-radius
#> "#ffffff" "#1D1F21" "#007bc2" "3px"
bs_get_variables(bs_theme(bootswatch = "darkly"), varnames = vars)
#> body-bg body-color primary border-radius
#> "#222" "#fff" "#375a7f" "0.375rem"
bs_get_contrast(bs_theme(), c("primary", "dark", "light"))
#> primary dark light
#> "#FFFFFF" "#FFFFFF" "#000000"
library(htmltools)
div(
class = "bg-primary",
style = css(
color = bs_get_contrast(bs_theme(), "primary")
)
)
#> <div class="bg-primary" style="color:#FFFFFF;"></div>