Skip to content

Commit

Permalink
docs(theme-utilities): family, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Oct 19, 2023
1 parent de43f27 commit 9245693
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 34 deletions.
9 changes: 6 additions & 3 deletions R/bs-theme-preset-bootswatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
#'
#' @param version the major version of Bootswatch.
#' @param full_path whether to return a path to the installed theme.
#' @return Returns a character vector of Bootswatch themes.
#' @family Bootstrap theme utility functions
#' @export
#' @return a character vector of Bootswatch themes.
bootswatch_themes <- function(version = version_default(), full_path = FALSE) {
list.dirs(bootswatch_dist(version), full.names = full_path, recursive = FALSE)
}

#' Obtain a theme's Bootswatch theme name
#'
#' @inheritParams bs_theme_update
#' @return the Bootswatch theme named used (if any) in the `theme`.
#' @return Returns the Bootswatch theme named used (if any) in the `theme`.
#' @family Bootstrap theme utility functions
#' @export
theme_bootswatch <- function(theme) {
if (!is_bs_theme(theme)) return(NULL)
Expand All @@ -22,7 +24,8 @@ theme_bootswatch <- function(theme) {
#' Obtain a theme's Bootstrap version
#'
#' @inheritParams bs_theme_update
#' @return the major version of Bootstrap used in the `theme`.
#' @return Returns the major version of Bootstrap used in the `theme`.
#' @family Bootstrap theme utility functions
#' @export
theme_version <- function(theme) {
if (!is_bs_theme(theme)) return(NULL)
Expand Down
6 changes: 5 additions & 1 deletion R/bs-theme-preset-builtin.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
#'
#' @param version the major version of Bootstrap.
#' @param full_path whether to return a path to the installed theme.
#'
#' @return Returns a character vector of built-in themes provided by
#' \pkg{bslib}.
#'
#' @family Bootstrap theme utility functions
#' @export
#' @return a character vector of built-in themes provided by \pkg{bslib}.
builtin_themes <- function(version = version_default(), full_path = FALSE) {
path_builtins <- path_builtin_theme(version = version)
if (is.null(path_builtins)) return(NULL)
Expand Down
18 changes: 12 additions & 6 deletions R/bs-theme-preview.R
Original file line number Diff line number Diff line change
Expand Up @@ -596,21 +596,27 @@ gfont_key <- function() {

#' Retrieve Sass variable values from the current theme
#'
#' Useful for retriving a variable from the current theme and using
#' Useful for retrieving a variable from the current theme and using
#' the value to inform another R function.
#'
#' @inheritParams bs_theme_update
#' @param varnames a character string referencing a Sass variable
#' in the current theme.
#' @return a character string containing a CSS/Sass value.
#' If the variable(s) are not defined, their value is `NA`.
#' @param varnames A character string referencing a Sass variable in the current
#' theme.
#'
#' @return Returns a character string containing a CSS/Sass value. If the
#' variable(s) are not defined, their value is `NA`.
#'
#' @references [Theming: Bootstrap 5 variables](https://rstudio.github.io/bslib/articles/bs5-variables/index.html)
#' provides a searchable reference of all theming variables available in
#' Bootstrap 5.
#'
#' @export
#' @family Bootstrap theme utility functions
#'
#' @examples
#' vars <- c("body-bg", "body-color", "primary", "border-radius")
#' bs_get_variables(bs_theme(), varnames = vars)
#' bs_get_variables(bs_theme(bootswatch = "darkly"), varnames = vars)
#'
bs_get_variables <- function(theme, varnames) {
if (length(varnames) == 0) {
return(stats::setNames(character(0), character(0)))
Expand Down
49 changes: 37 additions & 12 deletions R/bs-theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,24 @@
#' theme <- bs_add_rules(theme, ".my-class { color: $my-class-color }")
#'
#' @export
bs_theme <- function(version = version_default(), preset = NULL, ...,
bg = NULL, fg = NULL, primary = NULL, secondary = NULL,
success = NULL, info = NULL, warning = NULL, danger = NULL,
base_font = NULL, code_font = NULL, heading_font = NULL,
font_scale = NULL, bootswatch = NULL) {

bs_theme <- function(
version = version_default(),
preset = NULL,
...,
bg = NULL,
fg = NULL,
primary = NULL,
secondary = NULL,
success = NULL,
info = NULL,
warning = NULL,
danger = NULL,
base_font = NULL,
code_font = NULL,
heading_font = NULL,
font_scale = NULL,
bootswatch = NULL
) {
if (is.null(preset) && is.null(bootswatch) && version >= 5) {
preset <- "shiny"
}
Expand Down Expand Up @@ -175,13 +187,26 @@ bs_theme <- function(version = version_default(), preset = NULL, ...,
}

#' @rdname bs_theme
#' @param theme a [bs_theme()] object.
#' @param theme A [bs_theme()] object.
#' @export
bs_theme_update <- function(theme, ..., preset = NULL, bg = NULL, fg = NULL,
primary = NULL, secondary = NULL, success = NULL,
info = NULL, warning = NULL, danger = NULL,
base_font = NULL, code_font = NULL, heading_font = NULL,
font_scale = NULL, bootswatch = NULL) {
bs_theme_update <- function(
theme,
...,
preset = NULL,
bg = NULL,
fg = NULL,
primary = NULL,
secondary = NULL,
success = NULL,
info = NULL,
warning = NULL,
danger = NULL,
base_font = NULL,
code_font = NULL,
heading_font = NULL,
font_scale = NULL,
bootswatch = NULL
) {
assert_bs_theme(theme)

preset <- resolve_bs_preset(preset, bootswatch, version = theme_version(theme))
Expand Down
3 changes: 2 additions & 1 deletion R/version-default.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' Available Bootstrap versions
#'
#' @return A list of the Bootstrap versions available.
#' @return Returns a list of the Bootstrap versions available.
#'
#' @family Bootstrap theme utility functions
#' @export
versions <- function() {
rlang::set_names(
Expand Down
11 changes: 10 additions & 1 deletion man/bootswatch_themes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions man/bs_get_variables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion man/builtin_themes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion man/theme_bootswatch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion man/theme_version.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion man/versions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9245693

Please sign in to comment.