Class: CCS::Components::GovUK::NotificationBanner
- Defined in:
- lib/ccs/components/govuk/notification_banner.rb
Overview
GOV.UK Notification Banner
This helper is used for generating the notification banner component from the GDS - Components - Notification banner
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the notifaction banner
{ class: 'govuk-notification-banner', data: { module: 'govuk-notification-banner' } }.freeze
- DEFAULT_OPTIONS =
Default options used in normal versions of the notification banner
{ title_text: 'Important', title_id: 'govuk-notification-banner-title', role: 'region' }.freeze
- SUCCESS_BANNER_OPTIONS =
Specific options for the success version of the notification banner
{ classes: ' govuk-notification-banner--success', title_text: 'Success', role: 'alert' }.freeze
Instance Method Summary collapse
-
#initialize(text: nil, success_banner: nil, **options) ⇒ NotificationBanner
constructor
A new instance of NotificationBanner.
-
#render { ... } ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Notification banner component.
Constructor Details
#initialize(text: nil, success_banner: nil, **options) ⇒ NotificationBanner
Returns a new instance of NotificationBanner.
35 36 37 38 39 40 41 42 |
# File 'lib/ccs/components/govuk/notification_banner.rb', line 35 def initialize(text: nil, success_banner: nil, **) super(**) @text = text @success_banner = || false end |
Instance Method Details
#render { ... } ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Notification banner component
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ccs/components/govuk/notification_banner.rb', line 50 def render tag.div(**[:attributes]) do concat(tag.div(class: 'govuk-notification-banner__header') do tag.send(:"h#{[:heading_level] || 2}", [:title_text], class: 'govuk-notification-banner__title', id: [:title_id]) end) concat(tag.div(class: 'govuk-notification-banner__content') do if block_given? yield else tag.p(text, class: 'govuk-notification-banner__heading') end end) end end |