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.

238 Zeilen
8.6KB

  1. # Modifiers :: Syntax -----------------------------------------------------
  2. #' Bulma Modifier Classes
  3. #'
  4. #' @param color "primary", "link", "info", "success", "warning", "danger"
  5. #' @param size "small", "medium", "large"
  6. #' @param state "outlined", "loading"
  7. #'
  8. #' @return String of modifer classes
  9. #' @examples
  10. #' bulma_modifier(color = "primary", size = "large", state = "outlined")
  11. #' @references https://bulma.io/documentation/modifiers/syntax/
  12. #' @export
  13. bulma_modifier <- function(color = NULL, size = NULL, state = NULL) {
  14. color <- validate_value(color,
  15. c("primary", "link", "info", "success", "warning", "danger"), FALSE, "color")
  16. size <- validate_value(size, c("small", "medium", "large"), FALSE, "size")
  17. state <- validate_value(state, c("outlined", "loading"), TRUE, "state")
  18. c_is(c(color, size, state))
  19. }
  20. # Modifiers :: Helpers ----------------------------------------------------
  21. #' Bulma Helper Classes
  22. #'
  23. #' @param float `clearfix` Fixes an element's floating children
  24. #'
  25. #' `pulled-left` Moves an element to the left
  26. #'
  27. #' `pulled-right` Moves an element to the right
  28. #' @param spacing `marginless` Removes any margin
  29. #'
  30. #' `paddingless` Removes any padding
  31. #' @param other `overlay` Completely covers the first positioned parent
  32. #' `clipped` Adds overflow hidden
  33. #'
  34. #' `radiusless` Removes any radius
  35. #'
  36. #' `shadowless` Removes any shadow
  37. #'
  38. #' `unselectable` Prevents the text from being selectable
  39. #'
  40. #' `invisible` Adds visibility hidden
  41. #'
  42. #' `sr-only` Hide elements visually but keep the element available to be announced by a screen reader
  43. #' @return String of modifer classes
  44. #' @examples
  45. #' bulma_helper(float = "pulled-left")
  46. #' bulma_helper(spacing = c("marginless", "paddingless"))
  47. #' bulma_helper(other = "clipped", float = "pulled-right")
  48. #' @references https://bulma.io/documentation/modifiers/helpers
  49. #' @export
  50. bulma_helper <- function(float = NULL, spacing = NULL, other = NULL) {
  51. float <- validate_value(float, c("clearfix", "pulled-left", "pulled-right"), FALSE, "float")
  52. spacing <- validate_value(spacing, c("marginless", "paddingless"), TRUE, "spacing")
  53. other <- validate_value(other,
  54. c("overlay", "clipped", "radiusless", "shadowless", "unselectable", "invisible", "sr-only"),
  55. TRUE, "other")
  56. c_is(c(float, spacing, other))
  57. }
  58. # Modifiers :: Responsive Helpers -----------------------------------------
  59. #' Bulma Responsive Helper Classes
  60. #'
  61. #' @param display One of "block", "flex", "inline", "inline-block", "inline-flex"
  62. #' @param viewport One of "mobile", "tablet", "touch", "desktop", "widescreen",
  63. #' "fullhd". See <https://bulma.io/documentation/modifiers/responsive-helpers/>
  64. #' for more information.
  65. #'
  66. #' @examples
  67. #' bulma_responsive("flex", "tablet")
  68. #' bulma_responsive("flex", "widescreen", only = TRUE)
  69. #' @references https://bulma.io/documentation/modifiers/responsive-helpers/
  70. #' @return A string of helper classes
  71. #' @export
  72. bulma_responsive <- function(display = NULL, viewport = NULL, only = FALSE) {
  73. display <- validate_value(display, c(
  74. "block", "flex", "inline", "inline-block", "inline-flex"
  75. ), FALSE, "display")
  76. viewport <- validate_viewport(viewport)
  77. c_is(paste(display, viewport, if (only) "only", sep = "-"))
  78. }
  79. validate_viewport <- function(viewport, var_name = "viewport") {
  80. validate_value(viewport, bulma_constants("viewports") , FALSE, var_name)
  81. }
  82. # Modifiers :: Color ------------------------------------------------------
  83. #' Bulma Color Helper Classes
  84. #'
  85. #' @param text One of "white", "black", "light", "dark", "primary", "info",
  86. #' "link", "success", "warning", "danger", "black-bis", "black-ter",
  87. #' "grey-darker", "grey-dark", "grey", "grey-light", "grey-lighter",
  88. #' "white-ter", "white-bis"
  89. #' @param background One of "white", "black", "light", "dark", "primary",
  90. #' "info", "link", "success", "warning", "danger", "black-bis", "black-ter",
  91. #' "grey-darker", "grey-dark", "grey", "grey-light", "grey-lighter",
  92. #' "white-ter", "white-bis"
  93. #'
  94. #' @examples
  95. #' bulma_color("white", "black")
  96. #' bulma_color("white", "primary")
  97. #'
  98. #' @references https://bulma.io/documentation/modifiers/color-helpers
  99. #' @return String of modifer classes
  100. #' @export
  101. bulma_color <- function(text = NULL, background = NULL) {
  102. text <- validate_color(text, "text")
  103. background <- validate_color(background, "background")
  104. c_has(c(text, background))
  105. }
  106. validate_color <- function(color, var_name = "text", prefix = paste0(var_name, "-"), several.ok = FALSE) {
  107. color <- validate_value(color, bulma_constants("colors"), several.ok, var_name)
  108. c_prefix(color, prefix)
  109. }
  110. # Modifiers :: Typography -------------------------------------------------
  111. #' Bulma Typography Helper Classes
  112. #'
  113. #' @param size One of 1 through 7 (large to small)
  114. #' @param text One of "white", "black", "light", "dark", "primary", "info",
  115. #' "link", "success", "warning", "danger", "black-bis", "black-ter",
  116. #' "grey-darker", "grey-dark", "grey", "grey-light", "grey-lighter",
  117. #' "white-ter", "white-bis"
  118. #' @param responsive_size See [bulma_responsive_size()].
  119. #' @param alignment One of "centered", "justified", "left", "right"
  120. #' @param transformation One (or more) of "capitalized", "lowercase", "uppercase", "italic"
  121. #' @param weight One of "light", "normal", "semibold", "bold"
  122. #' @param font_family One of "sans-serif", "monospace", "primary", "secondary", "code".
  123. #' (Coming in version 0.7.3.)
  124. #'
  125. #' @examples
  126. #' bulma_color("white", "black")
  127. #' bulma_color("white", "primary")
  128. #'
  129. #' @references https://bulma.io/documentation/modifiers/typography-helpers/
  130. #' @return String of modifer classes
  131. #' @export
  132. bulma_typography <- function(
  133. size = NULL,
  134. color = NULL,
  135. responsive_size = NULL,
  136. alignment = NULL,
  137. responsive_alignment = NULL,
  138. transformation = NULL,
  139. weight = NULL,
  140. font_family = NULL
  141. ) {
  142. size <- validate_value(paste(size), paste(1:7), FALSE, "size")
  143. size <- c_prefix(size, prefix = "size-")
  144. responsive_size <- use_bulma_responsive(responsive_size, "size", "responsive_size")
  145. color <- validate_color(color, "color", "text-")
  146. alignment <- validate_alignment(alignment)
  147. responsive_alignment <- use_bulma_responsive(responsive_alignment, "alignment", "responsive_alignment")
  148. transformation <- validate_value(transformation,
  149. c("capitalized", "lowercase", "uppercase", "italic"), TRUE, "transformation")
  150. weight <- validate_value(weight, c("light", "normal", "semibold", "bold"), FALSE, "weight")
  151. weight <- c_prefix(weight, "text-weight-")
  152. font_family <- validate_value(font_family, c(
  153. "sans-serif", "monospace", "primary", "secondary", "code"
  154. ), TRUE, "font_family")
  155. font_family <- c_prefix(font_family, "family-")
  156. x <- paste(
  157. c_is(c(size, transformation, font_family)),
  158. c_has(c(color, alignment, weight)),
  159. responsive_size,
  160. responsive_alignment
  161. )
  162. str_trim(x)
  163. }
  164. validate_alignment <- function(alignment, var_name = "alignment", prefix = "text-") {
  165. alignment <- validate_value(alignment, bulma_constants("alignment"), FALSE, var_name)
  166. c_prefix(alignment, prefix)
  167. }
  168. #' Bulma Responsive Size Helper Classes
  169. #'
  170. #' @inheritParams bulma_typography
  171. #' @inheritParams bulma_responsive
  172. #' @examples
  173. #' bulma_responsive_size()
  174. #' bulma_responsive_size(2, "tablet")
  175. #' bulma_responsive_size(viewport = "widescreen")
  176. #' @return String of modifier classes
  177. #' @export
  178. bulma_responsive_size <- function(size = "1", viewport = "desktop") {
  179. # TODO: Needs to be vectorized, matching size/viewport arguments
  180. size <- validate_value(paste(size), paste(1:7), FALSE, "size")
  181. size <- c_prefix(size, "size-")
  182. viewport <- validate_viewport(viewport)
  183. x <- c_is(paste0(size, "-", viewport))
  184. class(x) <- c("responsive_size", "bulma", "character")
  185. x
  186. }
  187. use_bulma_responsive <- function(x, var, varname) {
  188. if (!is.null(x)) {
  189. if (!inherits(x, glue("responsive_{var}"))) {
  190. rlang::abort(glue("Please use bulma_responsive_{var}() to prepare `{varname}`."))
  191. }
  192. x
  193. }
  194. }
  195. #' Bulma Responsive Alignemnt Helper Classes
  196. #'
  197. #' @inheritParams bulma_typography
  198. #' @inheritParams bulma_responsive_size
  199. #' @examples
  200. #' bulma_responsive_alignment()
  201. #' bulma_responsive_alignment("centered", "tablet")
  202. #' bulma_responsive_alignment(viewport = "widescreen")
  203. #' @return String of modifier classes
  204. #' @references https://bulma.io/documentation/modifiers/typography-helpers/#responsive-alignment
  205. #' @export
  206. bulma_responsive_alignment <- function(alignment = "left", viewport = "desktop") {
  207. # TODO: Needs to be vectorized, matching alignment/viewport arguments
  208. alignment <- validate_alignment(alignment)
  209. viewport <- validate_viewport(viewport)
  210. x <- c_has(paste0(alignment, "-", viewport))
  211. class(x) <- c("responsive_alignment", "bulma", "character")
  212. x
  213. }