You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.2KB

  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. #' @param column_class Additional parameters passed to the `class` argument
  19. #' of the `column` div. Only used if `width` is specified.
  20. #' @family Bulma components
  21. #' @references <https://bulma.io/documentation/components/message/>
  22. #' @export
  23. bulma_message <- function(
  24. ...,
  25. header = NULL,
  26. delete = FALSE,
  27. color = NULL,
  28. size = c("normal", "small", "medium", "large"),
  29. width = NULL,
  30. centered = !is.null(width),
  31. column_class = NULL
  32. ) {
  33. size <- match.arg(size)
  34. if (size == "normal") size <- NULL
  35. article <- tag_function("article")
  36. color <- validate_color(color, "color", "is-")
  37. width <- validate_col_size(width, "width")
  38. if (is.null(header) && delete) header <- tag_p()
  39. if (!is.null(header) && !(is_htmlish(header) | is.character(header))) {
  40. rlang::abort("`header` must be character or HTML.")
  41. }
  42. ret <- article(
  43. class = c_str("message", c_prefix(size, "is-"), c_prefix(color)),
  44. if (!is.null(header)) tag_div(
  45. class = "message-header",
  46. header,
  47. if (delete) tag_function("button")(
  48. class = c_str("delete", c_prefix(size, "is-")),
  49. "aria-label" = "delete"
  50. )
  51. ),
  52. tag_div(class = "message-body", ...)
  53. )
  54. if (!is.null(width)) {
  55. ret <- bulma_column(ret, size = width, class = column_class)
  56. if (centered) ret <- bulma_columns(ret, centered = TRUE)
  57. }
  58. ret
  59. }
  60. #' Bulma Message as a Sidenote
  61. #'
  62. #' Creates a message block as a sidenote, pulled either left or right.
  63. #'
  64. #' @param side Should the sidenote be pulled to the left or the right?
  65. #' @inheritDotParams bulma_message
  66. #' @examples
  67. #' bulma_sidenote("A sidenote!", side = "left", color = "info")
  68. #' bulma_sidenote("A sidenote!", side = "right", color = "info",
  69. #' header = "Title")
  70. #' @family Bulma components
  71. #' @seealso [bulma_message()]
  72. #' @export
  73. bulma_sidenote <- function(
  74. ...,
  75. side = c("right", "left"),
  76. header = NULL,
  77. color = NULL,
  78. size = c("small", "normal", "medium", "large"),
  79. width = "one-third",
  80. delete = FALSE,
  81. column_class = NULL
  82. ) {
  83. side <- match.arg(side)
  84. column_class <- c_str("sidenote",
  85. "is-full-mobile",
  86. c_prefix(side, "is-pulled-"),
  87. "is-block is-float",
  88. column_class)
  89. bulma_message(...,
  90. header = header, color = color, size = match.arg(size), width = width,
  91. centered = FALSE, delete = delete, column_class = column_class
  92. )
  93. }