R/bulma-message.R

Defines functions bulmaMessage

Documented in bulmaMessage

#' @title bulma messqge
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @description Create a nice box for messages \url{https://bulma.io/documentation/elements/message/}.
#'
#' @param ... Any message to display in the body.
#' @param color Message color : \code{link}, \code{info}, \code{primary}, \code{warning},
#'  \code{danger}, \code{success}, \code{black}, \code{dark} and \code{ligth}.
#' @param size Message size : \code{small}, \code{medium} and \code{large}. NULL by default,
#' which corresponds to normal size.
#' @param header Message header. Display the header or not, TRUE by default.
#' @param header_title Header title, if any.
#'
#' @examples
#' if (interactive()) {
#'   library(shiny)
#'   
#'   ui <- bulmaPage(
#'     bulmaContainer(
#'       bulmaColumns(
#'         bulmaColumn(
#'           width = 4,
#'           bulmaMessage(
#'             color = NULL, 
#'             size = "large", 
#'             header = TRUE, 
#'             header_title = "First message",
#'             "Lorem ipsum dolor sit amet, 
#'             consectetur adipiscing elit. 
#'             Pellentesque risus mi, tempus 
#'             quis placerat ut, porta nec nulla. 
#'             Vestibulum rhoncus ac ex sit amet 
#'             fringilla. Nullam gravida purus diam, 
#'             et dictum felis venenatis efficitur. 
#'             Aenean ac eleifend lacus, in mollis 
#'             lectus. Donec sodales, arcu et 
#'             sollicitudin porttitor, tortor urna 
#'             tempor ligula, id porttitor mi magna a 
#'             neque. Donec dui urna, vehicula et 
#'             sem eget, facilisis sodales sem."
#'           )
#'         ),
#'         bulmaColumn(
#'           width = 4,
#'           bulmaMessage(
#'             color = "warning", 
#'             size = NULL, 
#'             header = FALSE,
#'             "Lorem ipsum dolor sit amet, 
#'             consectetur adipiscing elit. 
#'             Pellentesque risus mi, tempus 
#'             quis placerat ut, porta nec nulla. 
#'             Vestibulum rhoncus ac ex sit amet 
#'             fringilla. Nullam gravida purus diam, 
#'             et dictum felis venenatis efficitur. 
#'             Aenean ac eleifend lacus, in mollis 
#'             lectus. Donec sodales, arcu et 
#'             sollicitudin porttitor, tortor urna 
#'             tempor ligula, id porttitor mi magna a 
#'             neque. Donec dui urna, vehicula et 
#'             sem eget, facilisis sodales sem."
#'           )
#'         ),
#'         bulmaColumn(
#'           width = 4,
#'           bulmaMessage(
#'             color = "danger", 
#'             size = "small", 
#'             header = TRUE, 
#'             header_title = "Third message",
#'             "Lorem ipsum dolor sit amet, 
#'             consectetur adipiscing elit. 
#'             Pellentesque risus mi, tempus 
#'             quis placerat ut, porta nec nulla. 
#'             Vestibulum rhoncus ac ex sit amet 
#'             fringilla. Nullam gravida purus diam, 
#'             et dictum felis venenatis efficitur. 
#'             Aenean ac eleifend lacus, in mollis 
#'             lectus. Donec sodales, arcu et 
#'             sollicitudin porttitor, tortor urna 
#'             tempor ligula, id porttitor mi magna a 
#'             neque. Donec dui urna, vehicula et 
#'             sem eget, facilisis sodales sem."
#'           )
#'         )
#'       )
#'     )
#'   )
#'   
#'   server <- function(input, output, session) {
#'     
#'   }
#'   
#'   shinyApp(ui = ui, server = server)
#' }
#' @export
bulmaMessage <- function(..., color = NULL, size = NULL, header = TRUE, header_title = NULL) {
  
  cl <- "message"
  
  if (!is.null(color)) cl <- paste0(cl, " is-", color)
  if (!is.null(size)) cl <- paste0(cl, " is-", size)
  
  shiny::tags$article(
    class = cl,
    if (header == TRUE) {
      shiny::tagList(
        shiny::tags$div(
          class = "message-header",
          shiny::tags$p(header_title)
        ),
        shiny::tags$div(
          class = "message-body",
          ...
        )
      )
    } else {
      shiny::tags$div(
        class = "message-body",
        ...
      )
    }
  )
  
}
JohnCoene/shinybulma documentation built on Nov. 23, 2021, 6:20 p.m.