R/noti_banner.R

Defines functions noti_banner

Documented in noti_banner

#' Notification Banner Function
#'
#' This function creates a notification banner.
#' @param inputId The input Id for the banner
#' @param title_txt The wording that appears in the title
#' @param body_txt The wording that appears in the banner body
#' @param type The type of banner. Options are standard and success.
#' Standard is default
#' @return a notification HTML shiny tag object
#' @family Govstyle feedback types
#' @export
#' @examples
#' ui <- shiny::fluidPage(
#'   shinyGovstyle::header(
#'     org_name = "Example",
#'     service_name = "User Examples",
#'     logo="shinyGovstyle/images/moj_logo.png"
#'   ),
#'   shinyGovstyle::noti_banner(
#'     inputId = "banner", title_txt = "Important", body_txt = "Example text"
#'   )
#' )
#'
#' server <- function(input, output, session) {}
#'
#' if (interactive()) shinyApp(ui = ui, server = server)
noti_banner <- function(
  inputId, # nolint
  title_txt = "Important",
  body_txt = NULL,
  type = "standard"
) {
  if (type == "success") {
    type_class <- "govuk-notification-banner govuk-notification-banner--success"
    role_type <- "alert"
  } else {
    type_class <- "govuk-notification-banner"
    role_type <- "region"
  }

  gov_noti_banner <- shiny::tags$div(
    class = type_class,
    role = role_type,
    `aria-labelledby` = inputId,
    `data-module` = "govuk-notification-banner",
    shiny::tags$div(
      class = "govuk-notification-banner__header",
      shiny::tags$h2(
        class = "govuk-notification-banner__title",
        id = inputId,
        title_txt
      )
    ),
    shiny::tags$div(
      class = "govuk-notification-banner__content",
      shiny::tags$p(
        class = "govuk-notification-banner__heading",
        shiny::HTML(body_txt)
      )
    )
  )
  attachDependency(gov_noti_banner) # nolint
}

Try the shinyGovstyle package in your browser

Any scripts or data that you put into this service are public.

shinyGovstyle documentation built on April 13, 2026, 5:06 p.m.