Class: StimulusPlumbers::Form::Fields::Label

Inherits:
Plumber::Base show all
Defined in:
lib/stimulus_plumbers/form/fields/label.rb

Constant Summary

Constants included from Plumber::HtmlOptions

Plumber::HtmlOptions::STIMULUS_SPACEJOIN_KEYS

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Instance Method Summary collapse

Methods inherited from Plumber::Base

#initialize, #theme

Methods included from Plumber::HtmlOptions

#extract_classes, #merge_data_options, #merge_html_options, #merge_string_option, #normalize_part

Constructor Details

This class inherits a constructor from StimulusPlumbers::Plumber::Base

Instance Method Details

#render(text:, for_id: nil, id: nil, required: false, hidden: false, tag: :label) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stimulus_plumbers/form/fields/label.rb', line 7

def render(text:, for_id: nil, id: nil, required: false, hidden: false, tag: :label)
  mark_options = required && merge_html_options(
    { aria: { hidden: true } },
    theme.resolve(:form_required_mark)
  )
  html_options = merge_html_options(theme.resolve(:form_label, required: required, hidden: hidden))
  template.(tag, for: for_id, id: id, **html_options) do
    template.safe_join(
      [
        text,
        mark_options ? template.(:span, "*", **mark_options) : nil
      ]
    )
  end
end