R/bulma-tabs.R

Defines functions bulma_tabs

Documented in bulma_tabs

#' @title
#' Bulma Tabs
#'
#' @description
#' Simple responsive horizontal navigation tabs, with different styles. The
#' Bulma tabs are a straightforward navigation component that come in a variety
#' of versions.
#'
#' [Tabs](https://bulma.io/documentation/components/tabs/)
#'
#' @family Bulma Components
#' @name bulma_tabs
NULL

#' @describeIn bulma_tabs is the main container for the tabs.
#'
#' @param align,size (str) styling
#' @param full_width (flg) whether the tabs stretch horizontally
#' @param ...        (tag) content
#' @param id         (str) string identifier
#' @param boxed,toggle,toggle_rounded (flg) styling
#' @param outer_tag,inner_tag (fn) generators for tags (`<div><ul>` for
#'                                 bulma tabs, `<li><a>` for bulma tab items.
#'
#' @export
bulma_tabs <- function(...,
                       id = NULL,
                       boxed  = FALSE,
                       toggle = FALSE,
                       toggle_rounded = FALSE,
                       align  = c("left", "centered", "right"),
                       size   = c("small", "normal", "medium", "large"),
                       full_width = FALSE,
                       outer_tag = tags$div,
                       inner_tag = tags$ul) {

  assert_string(id, null.ok = TRUE)
  assert_function(outer_tag)
  assert_function(inner_tag)
  align <- match_arg(align)
  size <- match_arg(size)
  walk(unnamed(...), assert_class, "bulma_tabs_item")
  assert_true(!toggle || toggle_rounded)

  outer_tag(id = id, class = "tabs", inner_tag(...)) %>%
    bulma_align(align) %>%
    bulma_size(size) %>%
    when(boxed, bulma_is(., "boxed")) %>%
    when(toggle, bulma_is(., "toggle")) %>%
    when(full_width, bulma_fullwidth(.)) %>%
    when(toggle_rounded, bulma_is(., "toggle-rounded")) %>%
    add_class("bulma_tabs")

}

#' @describeIn bulma_tabs are placed in `bulma_tab()`.
#'
#' @param active (flag) selected or chosen tab.
#'
#' @export
bulma_tabs_item <- function(...,
                            id = NULL,
                            active = FALSE,
                            outer_tag = tags$li,
                            inner_tag = tags$a) {

  assert_function(outer_tag)
  assert_function(inner_tag)

  outer_tag(id = id, inner_tag(...)) %>%
    when(active, bulma_is(., "active")) %>%
    add_class("bulma_tabs_item")

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