Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

142 Zeilen
4.9KB

  1. # Layout ------------------------------------------------------------------
  2. #' Bulma Level
  3. #'
  4. #' A multi-purpose horizontal level that can contain almost any other element.
  5. #'
  6. #' @param ... Items to be wrapped in a `"level-item"` `<div>` and included in the
  7. #' main level container. If only one argument is provided and that argument is
  8. #' a list, the items inside the list will be treated as individual level items.
  9. #' @param left A list of items to be placed in the left side of the level in a
  10. #' `"level-left"` container.
  11. #' @param right A list of items to be placed in the right side of the level in a
  12. #' `"level-right"` container.
  13. #' @param type One of `"item"` or `"header"`. The default (`"item"`) places level
  14. #' items in the standard `"level-item"` container. Use `"header"` to use the
  15. #' names of the arguments in `...` as headers over their elements to create a
  16. #' large single-row pseudo-table. See examples for more details.
  17. #' @param container_tag Which tag should be used for the main `"level"` container?
  18. #' One of `"div"` or `"nav"`.
  19. #' @param class Additional classes applied to level container
  20. #' @param style Additional style parameters applied to level container
  21. #' @param level_class Additional classes applied to all level item containers (except
  22. #' for manually created level items).
  23. #' @param level_style Additional style arguments applied to all level item containers
  24. #' (except for manually create level items).
  25. #' @examples
  26. #' bulma_level("Home", "Menu", "Bulma", "Reservations", "Contact")
  27. #' bulma_level("Tweets" = 3456, Following = 123, Followers = "456K", Likes = 789, type = "header")
  28. #'
  29. #' iris_vals <- lapply(iris, function(x) length(unique(x)))
  30. #' bulma_level(iris_vals, type = "header")
  31. #'
  32. #' @references <https://bulma.io/documentation/layout/level/>
  33. #' @family Bulma layouts
  34. #' @export
  35. bulma_level <- function(
  36. ...,
  37. left = NULL,
  38. right = NULL,
  39. is_mobile = TRUE,
  40. type = c("item", "header"),
  41. container_tag = c("div", "nav"),
  42. class = NULL,
  43. style = NULL,
  44. level_class = NULL,
  45. level_style = NULL
  46. ) {
  47. type <- match.arg(type)
  48. tag_f <- tag_function(match.arg(container_tag))
  49. x <- tag_f(
  50. class = c_str("level", if (is_mobile) "is-mobile", class),
  51. style = style,
  52. level_side(left, "left"),
  53. if (type == "item")
  54. tagList(lapply(dots2list(...), bulma_level_item, class = level_class, style = level_style)),
  55. if (type == "header") bulma_level_items_header(..., class = level_class, style = level_style),
  56. level_side(right, "right")
  57. )
  58. x
  59. }
  60. #' Bulma Level Item
  61. #'
  62. #' Constructs an individual level item.
  63. #'
  64. #' @param ... Elements to be included in the level item
  65. #' @param class Additional classes to be applied to the level item container
  66. #' @param style Additional CSS style directives to be applied to the level item container
  67. #' @family Bulma layouts
  68. #' @export
  69. bulma_level_item <- function(..., class = NULL, style = NULL) {
  70. item <- dots2list(...)
  71. if (is_level_item(item)) return(item)
  72. as_level_item(
  73. tag_div(class = c_str("level-item", class),
  74. style = style,
  75. item)
  76. )
  77. }
  78. as_level_item <- function(x) {
  79. if (inherits(x, "level_item")) return(x)
  80. class(x) <- c("level_item", class(x))
  81. x
  82. }
  83. is_level_item <- function(x) inherits(x, "level_item")
  84. level_side <- function(x, side = "left") {
  85. if (is.null(x)) return(NULL)
  86. match.arg(side, c("left", "right"))
  87. items <- lapply(x, bulma_level_item)
  88. tag_div(class = c_prefix(side, "level-"), items)
  89. }
  90. #' Bulma Level Items with Headers
  91. #'
  92. #' Takes named arguments and converts them to
  93. #' (level items with headers)[bulma_level_item_header].
  94. #'
  95. #' @inheritParams bulma_level_item
  96. #' @param header_class Additional classes to be applied to the header (upper)
  97. #' container in addition to `"heading"`
  98. #' @param body_class Additional classes to be applied to the title (lower)
  99. #' container in addition to `"title"`
  100. #' @family Bulma layouts
  101. #' @export
  102. bulma_level_items_header <- function(..., class = NULL, style = NULL, header_class = NULL, body_class = NULL) {
  103. items <- dots2list(...)
  104. x <- map_arg(
  105. .f = bulma_level_item_header,
  106. names(items),
  107. items,
  108. .args = list(class = if (is.null(class)) "has-text-centered" else class,
  109. style = style,
  110. header_class = header_class,
  111. body_class = body_class)
  112. )
  113. tagList(x)
  114. }
  115. #' Bulma Level Item with Header
  116. #'
  117. #' Constructs an individual level item with a header (upper) and a title (lower).
  118. #'
  119. #' @param item_name The header (or name) of the item
  120. #' @param item_body The body of the item
  121. #' @inheritParams bulma_level_items_header
  122. #' @family Bulma layouts
  123. #' @export
  124. bulma_level_item_header <- function(item_header, item_body, class = NULL, style = NULL, header_class = NULL, body_class = NULL) {
  125. bulma_level_item(
  126. class = class,
  127. style = style,
  128. tag_div(
  129. tag_p(class = c_str("heading", header_class), item_header),
  130. tag_p(class = c_str("title", body_class), item_body)
  131. ))
  132. }