Class: CCS::Components::GovUK::WarningText
- Defined in:
- lib/ccs/components/govuk/warning_text.rb
Overview
GOV.UK Warning text
This helper is used for generating the warning text component from the GDS - Components - Warning text
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the warning text
{ class: 'govuk-warning-text' }.freeze
Instance Method Summary collapse
-
#initialize(text: nil, **options) ⇒ WarningText
constructor
A new instance of WarningText.
-
#render { ... } ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Warning text component.
Constructor Details
#initialize(text: nil, **options) ⇒ WarningText
Returns a new instance of WarningText.
29 30 31 32 33 |
# File 'lib/ccs/components/govuk/warning_text.rb', line 29 def initialize(text: nil, **) super(**) @text = text end |
Instance Method Details
#render { ... } ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Warning text component
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ccs/components/govuk/warning_text.rb', line 41 def render tag.div(**[:attributes]) do concat(tag.span('!', class: 'govuk-warning-text__icon', aria: { hidden: true })) concat(tag.strong(class: 'govuk-warning-text__text') do concat(tag.span([:icon_fallback_text] || 'Warning', class: 'govuk-visually-hidden')) if text concat(text) else yield end end) end end |