R/bulma-hero.R

Defines functions bulma_hero_foot bulma_hero_head bulma_hero_body bulma_hero

Documented in bulma_hero bulma_hero_body bulma_hero_foot bulma_hero_head

#' @title
#' Bulma Hero
#'
#' @description
#' An imposing hero banner to showcase something. The hero component allows you
#' to add a full width banner to your webpage, which can optionally cover the
#' full height of the page as well.
#'
#' * `bulma_hero()` - main component
#'   * `bulma_hero_body()` - put main content here
#'   * if it is fullheight:
#'     * `bulma_hero_head()` - header of the hero section
#'     * `bulma_hero_foot()` - footer of the hero section
#'
#' [Hero](https://bulma.io/documentation/layout/hero/)
#'
#' @param ... (tags) content
#' @param tag (fn) container object
#'
#' @family Bulma Layouts
#' @name bulma_hero
NULL

#' @describeIn bulma_hero main component; contains `bulma_hero_head()`,
#' `bulma_hero_body()`, and `bulma_hero_foot()`.
#'
#' @param color,size styling parameters
#' @param fullheight_with_navbar (flag) whether or not this element will
#'        have a navbar with full height so that the margin can be adjusted
#'
#' @export
bulma_hero <- function(...,
                       color = c("primary", "link", "info",
                                 "success", "warning", "danger",
                                 "white", "black", "light", "dark"),
                       size = c("small", "medium", "large",
                                "halfheight", "fullheight"),
                       fullheight_with_navbar = FALSE,
                       tag = tags$section) {

  assert_function(tag)
  walk(tagList(...),
       assert_multi_class,
       c("bulma_hero_head",
         "bulma_hero_body",
         "bulma_hero_foot"))
  size <- match_arg(size)
  if (fullheight_with_navbar) size <- NULL

  tag(class = "hero", ...) %>%
    bulma_color(color) %>%
    bulma_is(size) %>%
    when(fullheight_with_navbar, bulma_is(., "fullheight-with-navbar")) %>%
    add_class("bulma_hero")

}

#' @describeIn bulma_hero body content
#' @export
bulma_hero_body <- function(..., tag = tags$div) {

  assert_function(tag)

  tag(class = "hero-body", ...) %>%
    add_class("bulma_hero_body")

}

#' @describeIn bulma_hero hero header
#' @export
bulma_hero_head <- function(..., tag = tags$div) {

  assert_function(tag)

  tag(class = "hero-head", ...) %>%
    add_class("bulma_hero_head")

}

#' @describeIn bulma_hero hero footer
#' @export
bulma_hero_foot <- function(..., tag = tags$div) {

  assert_function(tag)

  tag(class = "hero-foot", ...) %>%
    add_class("bulma_hero_foot")

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