Class: GOVUKDesignSystemFormBuilder::Elements::Label
- Defined in:
- lib/govuk_design_system_formbuilder/elements/label.rb
Constant Summary
Constants included from Traits::Localisation
Traits::Localisation::BASE_NAME_REGEXP
Instance Method Summary collapse
- #active? ⇒ Boolean
- #html ⇒ Object
-
#initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true, content: nil, caption: nil, **kwargs) ⇒ Label
constructor
A new instance of Label.
Methods included from Traits::HTMLClasses
Methods included from Traits::HTMLAttributes
Methods inherited from Base
Constructor Details
#initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true, content: nil, caption: nil, **kwargs) ⇒ Label
Returns a new instance of Label.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/govuk_design_system_formbuilder/elements/label.rb', line 11 def initialize(builder, object_name, attribute_name, text: nil, value: nil, size: nil, hidden: false, radio: false, checkbox: false, tag: nil, link_errors: true, content: nil, caption: nil, **kwargs) super(builder, object_name, attribute_name) @value = value # used by field_id @tag = tag @radio = radio @checkbox = checkbox @link_errors = link_errors @html_attributes = kwargs # content is passed in directly via a proc and overrides # the other display options if content @content = capture { content.call } else @text = retrieve_text(text, hidden) @size_class = size_class(size) @caption = end end |
Instance Method Details
#active? ⇒ Boolean
42 43 44 |
# File 'lib/govuk_design_system_formbuilder/elements/label.rb', line 42 def active? [@content, @text].any?(&:present?) end |
#html ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/govuk_design_system_formbuilder/elements/label.rb', line 32 def html return unless active? if @tag.present? content_tag(@tag, class: %(#{brand}-label-wrapper)) { label } else label end end |