Class: Railsboot::FormField::LabelComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/form_field/label_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(form:, **html_attributes) ⇒ LabelComponent

Returns a new instance of LabelComponent.



2
3
4
5
6
7
8
9
10
11
# File 'app/components/railsboot/form_field/label_component.rb', line 2

def initialize(form:, **html_attributes)
  @form = form
  @html_attributes = html_attributes
  @attribute = @attribute.presence || html_attributes.delete(:for)

  @html_attributes[:class] = class_names(
    "form-label",
    html_attributes[:class]
  )
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
# File 'app/components/railsboot/form_field/label_component.rb', line 13

def call
  if content.present?
    @form.label @attribute, content, **@html_attributes
  else
    @form.label @attribute, **@html_attributes
  end
end