R/position-centered.R

Defines functions position_centered

Documented in position_centered

#' Centering positioned elements
#'
#' Use `position_centered()` to position an element by its center instead of its edge.
#'
#' @param x `r param_subject()`
#'
#' @returns `r returns_same("x")`
#'
#' @family position utilities
#'
#' @export
#'
#' @examples
#'
#' library(htmltools)
#'
#' div(
#'   .style %>%
#'     position("absolute") %>%
#'     position_right(0) %>%
#'     position_centered()
#' )
#'
#' tags$button(
#'   type = "button",
#'   .style %>%
#'     position("relative") %>%
#'     background_color(theme_primary()),
#'   "Mail",
#'   span(
#'     .style %>%
#'       position("absolute") %>%
#'       position_top(0) %>%
#'       position_right(0) %>%
#'       position_centered() %>%
#'       rounded_all("pill") %>%
#'       background_color(theme_secondary()),
#'     "+99"
#'   )
#' )
#'
position_centered <- function(x) {
  add_class(
    x,
    "translate-middle"
  )
}

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.