Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

67 lines
1.8KB

  1. #' @title Bulma Level
  2. #' @examples
  3. #' bulma_level("Home", "Menu", "Bulma", "Reservations", "Contact")
  4. #' bulma_level("Tweets" = 3456, Following = 123, Followers = "456K", Likes = 789, style = "header")
  5. #' @export
  6. bulma_level <- function(
  7. ...,
  8. left = NULL,
  9. right = NULL,
  10. is_mobile = TRUE,
  11. style = c("item", "header"),
  12. container_tag = c("div", "nav")
  13. ) {
  14. level_item_f <- switch(
  15. match.arg(style),
  16. item = level_item,
  17. header = level_item_header
  18. )
  19. tag_f <- tag_function(container_tag)
  20. x <- tag_f(
  21. class = paste("level", if (is_mobile) "is-mobile"),
  22. level_side(left),
  23. level_item_f(...),
  24. level_side(right)
  25. )
  26. x
  27. }
  28. level_item <- function(...) {
  29. x <- apply_tag(dots2list(...), tag = "div", class = "level-item")
  30. tagList(x)
  31. }
  32. level_side <- function(x, side = "left") {
  33. if (is.null(x)) return(NULL)
  34. match.arg(side, c("left", "right"))
  35. lapply(x, function(item) {
  36. htmltools::tags$div(
  37. class = paste0("level-", side),
  38. level_item(x)
  39. )
  40. })
  41. }
  42. #' @title Bulma Level Items With Headers
  43. level_item_header <- function(..., item_class = "has-text-centered", heading_class = NULL, title_class = NULL) {
  44. items <- dots2list(...)
  45. x <- mapply(level_item_header_, names(items), items,
  46. MoreArgs = list(item_class = item_class,
  47. heading_class = heading_class,
  48. title_class = title_class),
  49. SIMPLIFY = FALSE)
  50. tagList(x)
  51. }
  52. #' @importFrom htmltools tag
  53. level_item_header_ <- function(item_name, item_body, item_class = NULL, heading_class = NULL, title_class = NULL) {
  54. tag("div", list(
  55. class = paste("level-item", item_class),
  56. list(tag("div", list(
  57. tag("p", list(class = paste("heading", heading_class), item_name)),
  58. tag("p", list(class = paste("title", title_class), item_body))
  59. )))
  60. ))
  61. }