Class: GOVUKDesignSystemFormBuilder::Elements::Hint

Inherits:
Base
  • Object
show all
Includes:
Traits::Localisation
Defined in:
lib/govuk_design_system_formbuilder/elements/hint.rb

Instance Method Summary collapse

Methods inherited from Base

#field_id, #to_s

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.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/govuk_design_system_formbuilder/elements/hint.rb', line 8

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

Returns:

  • (Boolean)


23
24
25
# File 'lib/govuk_design_system_formbuilder/elements/hint.rb', line 23

def active?
  [@text, @raw].any?(&:present?)
end

#hint_idObject



33
34
35
36
37
# File 'lib/govuk_design_system_formbuilder/elements/hint.rb', line 33

def hint_id
  return unless active?

  build_id('hint')
end

#htmlObject



27
28
29
30
31
# File 'lib/govuk_design_system_formbuilder/elements/hint.rb', line 27

def html
  return unless active?

  tag.div(**hint_options, **@html_attributes) { hint_body }
end