|
- #' @title Bulma Level
- #' @examples
- #' bulma_level("Home", "Menu", "Bulma", "Reservations", "Contact")
- #' bulma_level("Tweets" = 3456, Following = 123, Followers = "456K", Likes = 789, style = "header")
- #' @export
- bulma_level <- function(
- ...,
- left = NULL,
- right = NULL,
- is_mobile = TRUE,
- style = c("item", "header"),
- container_tag = c("div", "nav")
- ) {
- level_item_f <- switch(
- match.arg(style),
- item = level_item,
- header = level_item_header
- )
- tag_f <- tag_function(container_tag)
- x <- tag_f(
- class = paste("level", if (is_mobile) "is-mobile"),
- level_side(left),
- level_item_f(...),
- level_side(right)
- )
-
- x
- }
-
- level_item <- function(...) {
- x <- apply_tag(dots2list(...), tag = "div", class = "level-item")
- tagList(x)
- }
-
- level_side <- function(x, side = "left") {
- if (is.null(x)) return(NULL)
- match.arg(side, c("left", "right"))
- lapply(x, function(item) {
- htmltools::tags$div(
- class = paste0("level-", side),
- level_item(x)
- )
- })
- }
-
- #' @title Bulma Level Items With Headers
- level_item_header <- function(..., item_class = "has-text-centered", heading_class = NULL, title_class = NULL) {
- items <- dots2list(...)
- x <- mapply(level_item_header_, names(items), items,
- MoreArgs = list(item_class = item_class,
- heading_class = heading_class,
- title_class = title_class),
- SIMPLIFY = FALSE)
- tagList(x)
- }
-
- #' @importFrom htmltools tag
- level_item_header_ <- function(item_name, item_body, item_class = NULL, heading_class = NULL, title_class = NULL) {
- tag("div", list(
- class = paste("level-item", item_class),
- list(tag("div", list(
- tag("p", list(class = paste("heading", heading_class), item_name)),
- tag("p", list(class = paste("title", title_class), item_body))
- )))
- ))
- }
|