R/text-wrap.R

Defines functions text_wrap

Documented in text_wrap

text_wrap_values <- chr(
  "TRUE" = "wrap",
  "FALSE" = "nowrap"
)

#' Text wrap
#'
#' The `text_wrap()` adjusts how text is wrapped, or not wrapped, in a tag
#' element.
#'
#' @param x `r param_subject()`
#'
#' @param wrap A boolean. One of,
#'
#'   `r rd_bullets(names(text_wrap_values))`
#'
#' @returns `r returns_same("x")`
#'
#' @family text utilities
#'
#' @export
#'
#' @examples
#'
#' library(htmltools)
#'
#' div(
#'   style = "width: 5rem;",
#'   .style %>%
#'     background_color(theme_primary()) %>%
#'     text_wrap(TRUE),
#'   "Wrap text to fit the element"
#' )
#'
#' div(
#'   style = "width: rem;",
#'   .style %>%
#'     background_color(theme_secondary()) %>%
#'     text_wrap(FALSE),
#'   "This text won't wrap onto a new line."
#' )
#'
text_wrap <- function(x, wrap) {
  add_class(
    x,
    compose_class(
      "text",
      text_wrap_values,
      wrap
    )
  )
}

Try the cascadess package in your browser

Any scripts or data that you put into this service are public.

cascadess documentation built on Oct. 30, 2024, 9:29 a.m.