|
-
- # Bulma Messages ----------------------------------------------------------
- # https://bulma.io/documentation/components/message/
-
- #' Bulma Message
- #'
- #' Creates a message box with optional title bar.
- #'
- #' @param ... Message body
- #' @param header Message header
- #' @param delete Should delete button be displayed in upper right corner?
- #' @param size Text size, one of `"small"`, `"normal"` (default),
- #' `"medium"`, or `"large"`.
- #' @param width Width of the message. If `NULL` then width is 100% of container.
- #' If specified, the message is wrapped in a `column` div (see [bulma_column()]
- #' for more information and for valid column sizes).
- #' @param centered Should the message container be centered horizontally?
- #' Requires `width` to be specified. If `TRUE`, the message container is
- #' inside a `column` div inside a `columns` div.
- #' @family Bulma components
- #' @references <https://bulma.io/documentation/components/message/>
- #' @export
- bulma_message <- function(
- ...,
- header = NULL,
- delete = FALSE,
- color = NULL,
- size = c("normal", "small", "medium", "large"),
- width = NULL,
- centered = !is.null(width)
- ) {
- size <- match.arg(size)
- if (size == "normal") size <- NULL
- article <- tag_function("article")
- color <- validate_color(color, "color", "is-")
- width <- validate_col_size(width, "width")
- if (is.null(header) && delete) header <- tag_p()
- if (!is.null(header) && !(is_htmlish(header) | is.character(header))) {
- rlang::abort("`header` must be character or HTML.")
- }
- ret <- article(
- class = c_str("message", c_prefix(size, "is-"), c_prefix(color)),
- if (!is.null(header)) tag_div(
- class = "message-header",
- header,
- if (delete) tag_function("button")(
- class = c_str("delete", c_prefix(size, "is-")),
- "aria-label" = "delete"
- )
- ),
- tag_div(class = "message-body", ...)
- )
- if (!is.null(width)) {
- ret <- bulma_column(ret, size = width)
- if (centered) ret <- bulma_columns(ret, centered = TRUE)
- }
- ret
- }
|