R/bulma-spacing.R

Defines functions bulma_spacing

Documented in bulma_spacing

#' @title
#' Bulma Spacing
#'
#' @description
#' Change the size and color of the tex for one or multiple viewport width.
#'
#' [Spacing Helpers](https://bulma.io/documentation/helpers/spacing-helpers/)
#'
#' @family Bulma Modifiers
#' @name bulma_spacing
NULL

#' @describeIn bulma_spacing changes spacing of an existing tag
#'
#' @param tag  (tag) to be modified
#' @param type (string) padding or margin
#' @param side (string) which part to add spacing: top, bottom, right, left,
#'                      x (left and right), or y (top and bottom)
#' @param size (int) size of the spacing.
#'
#' @export
bulma_spacing <- function(tag,
                          type = c("padding", "margin"),
                          size = 1L:6L,
                          side = c("top", "bottom", "right", "left",
                                   "x", "y", "all")) {

  type <- match_arg(type)
  size <- match_arg(size)
  side <- match_arg(side) %||% "all"
  assert_string(type)
  assert_string(side)
  assert_int(size)

  type <- switch(
    type,
    "padding" = "p",
    "margin"  = "m"
  )

  side <- switch(
    side,
    "all" = "",
    "top" = "t",
    "bottom" = "b",
    "right" = "r",
    "left" = "l",
    "x" = "x",
    "y" = "y"
  )

  size <- as.character(size)

  tagAppendAttributes(
    tag,
    class = glue("{type}{side}-{size}")
  )

}
tjpalanca/bulma.R documentation built on Dec. 23, 2021, 10:58 a.m.