Class: GOVUKDesignSystemFormBuilder::Elements::Hint
- Defined in:
- lib/govuk_design_system_formbuilder/elements/hint.rb
Constant Summary
Constants included from Traits::Localisation
Traits::Localisation::BASE_NAME_REGEXP
Instance Method Summary collapse
- #active? ⇒ Boolean
- #hint_id ⇒ Object
- #html ⇒ Object
-
#initialize(builder, object_name, attribute_name, value: nil, text: nil, content: nil, radio: false, checkbox: false, **kwargs) ⇒ Hint
constructor
A new instance of Hint.
Methods included from Traits::HTMLClasses
Methods included from Traits::HTMLAttributes
Methods inherited from Base
Constructor Details
#initialize(builder, object_name, attribute_name, value: nil, text: nil, content: nil, radio: false, checkbox: false, **kwargs) ⇒ Hint
Returns a new instance of Hint.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/govuk_design_system_formbuilder/elements/hint.rb', line 10 def initialize(builder, object_name, attribute_name, value: nil, text: nil, content: nil, radio: false, checkbox: false, **kwargs) super(builder, object_name, attribute_name) @value = value @radio = radio @checkbox = checkbox @html_attributes = kwargs if content @raw = capture { content.call } else @text = retrieve_text(text) end end |
Instance Method Details
#active? ⇒ Boolean
25 26 27 |
# File 'lib/govuk_design_system_formbuilder/elements/hint.rb', line 25 def active? [@text, @raw].any?(&:present?) end |
#hint_id ⇒ Object
35 36 37 38 39 |
# File 'lib/govuk_design_system_formbuilder/elements/hint.rb', line 35 def hint_id return unless active? build_id('hint') end |
#html ⇒ Object
29 30 31 32 33 |
# File 'lib/govuk_design_system_formbuilder/elements/hint.rb', line 29 def html return unless active? tag.div(**attributes(@html_attributes)) { hint_body } end |