# 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. #' @param column_class Additional parameters passed to the `class` argument #' of the `column` div. Only used if `width` is specified. #' @family Bulma components #' @references #' @export bulma_message <- function( ..., header = NULL, delete = FALSE, color = NULL, size = c("normal", "small", "medium", "large"), width = NULL, centered = !is.null(width), column_class = NULL ) { 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, class = column_class) if (centered) ret <- bulma_columns(ret, centered = TRUE) } ret } #' Bulma Message as a Sidenote #' #' Creates a message block as a sidenote, pulled either left or right. #' #' @param side Should the sidenote be pulled to the left or the right? #' @inheritDotParams bulma_message #' @examples #' bulma_sidenote("A sidenote!", side = "left", color = "info") #' bulma_sidenote("A sidenote!", side = "right", color = "info", #' header = "Title") #' @family Bulma components #' @seealso [bulma_message()] #' @export bulma_sidenote <- function( ..., side = c("right", "left"), header = NULL, color = NULL, size = c("small", "normal", "medium", "large"), width = "one-third", delete = FALSE, column_class = NULL ) { side <- match.arg(side) column_class <- c_str("sidenote", "is-full-mobile", c_prefix(side, "is-pulled-"), "is-block is-float", column_class) bulma_message(..., header = header, color = color, size = match.arg(size), width = width, centered = FALSE, delete = delete, column_class = column_class ) }