# NOT RUN {
# Function to preview the styling a (primary) Bootstrap button
library(htmltools)
button <- tags$a(class = "btn btn-primary", href = "#", role = "button", "Hello")
preview_button <- function(x) {
browsable(tags$body(x, button))
}
# To create a custom theme, you must start by calling bs_theme_new()
# Here we start with a theme based on a Bootswatch theme,
# then override some variable defaults
bs_theme_new(bootswatch = "sketchy")
bs_theme_add_variables(
primary = "orange",
"body-bg" = "#EEEEEE",
"font-family-base" = "monospace",
"font-size-base" = "1.4rem",
"btn-padding-y" = ".16rem",
"btn-padding-x" = "2rem",
"border-radius" = 0,
"border-radius-lg" = 0,
"border-radius-sm" = 0
)
preview_button(bootstrap())
# If you need to set a variable based on another Bootstrap variable
bs_theme_add_variables(
"body-color" = "$success",
.where = "declarations"
)
preview_button(bootstrap())
# Start a new global theme and add some custom rules that
# use Bootstrap variables to define a custom styling for a
# 'person card'
bs_theme_new()
bs_theme_add(
rules = sass::sass_file(
system.file("custom", "person.scss", package = "bootstraplib")
)
)
# Include custom CSS that leverages bootstrap Sass variables
person <- function(name, title, company) {
tags$div(
class = "person",
h3(class = "name", name),
div(class = "title", title),
div(class = "company", company)
)
}
browsable(tags$body(
bootstrap(),
person("Andrew Carnegie", "Owner", "Carnegie Steel Company"),
person("John D. Rockefeller", "Chairman", "Standard Oil")
))
# Once a theme has been set, you can get it, and see which
# version/bootswatch was specified
bs_theme_new(bootswatch = "cosmo")
theme <- bs_theme_get()
theme_version(theme)
theme_bootswatch(theme)
# Themes are just sass_layer(), so you can work with them locally
# just like any other sass layer
# https://rstudio.github.io/sass/articles/sass.html#layers
class(theme)
layer <- sass::sass_layer("$primary: red")
theme <- sass::sass_layer_merge(theme, layer)
bs_theme_set(theme)
# }
Run the code above in your browser using DataLab