Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

59 lines
2.0KB

  1. # Bulma Messages ----------------------------------------------------------
  2. # https://bulma.io/documentation/components/message/
  3. #' Bulma Message
  4. #'
  5. #' Creates a message box with optional title bar.
  6. #'
  7. #' @param ... Message body
  8. #' @param header Message header
  9. #' @param delete Should delete button be displayed in upper right corner?
  10. #' @param size Text size, one of `"small"`, `"normal"` (default),
  11. #' `"medium"`, or `"large"`.
  12. #' @param width Width of the message. If `NULL` then width is 100% of container.
  13. #' If specified, the message is wrapped in a `column` div (see [bulma_column()]
  14. #' for more information and for valid column sizes).
  15. #' @param centered Should the message container be centered horizontally?
  16. #' Requires `width` to be specified. If `TRUE`, the message container is
  17. #' inside a `column` div inside a `columns` div.
  18. #' @family Bulma components
  19. #' @references <https://bulma.io/documentation/components/message/>
  20. #' @export
  21. bulma_message <- function(
  22. ...,
  23. header = NULL,
  24. delete = FALSE,
  25. color = NULL,
  26. size = c("normal", "small", "medium", "large"),
  27. width = NULL,
  28. centered = !is.null(width)
  29. ) {
  30. size <- match.arg(size)
  31. if (size == "normal") size <- NULL
  32. article <- tag_function("article")
  33. color <- validate_color(color, "color", "is-")
  34. width <- validate_col_size(width, "width")
  35. if (is.null(header) && delete) header <- tag_p()
  36. if (!is.null(header) && !(is_htmlish(header) | is.character(header))) {
  37. rlang::abort("`header` must be character or HTML.")
  38. }
  39. ret <- article(
  40. class = c_str("message", c_prefix(size, "is-"), c_prefix(color)),
  41. if (!is.null(header)) tag_div(
  42. class = "message-header",
  43. header,
  44. if (delete) tag_function("button")(
  45. class = c_str("delete", c_prefix(size, "is-")),
  46. "aria-label" = "delete"
  47. )
  48. ),
  49. tag_div(class = "message-body", ...)
  50. )
  51. if (!is.null(width)) {
  52. ret <- bulma_column(ret, size = width)
  53. if (centered) ret <- bulma_columns(ret, centered = TRUE)
  54. }
  55. ret
  56. }