Class: UI::FieldLabelComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
FieldLabelBehavior
Defined in:
app/view_components/ui/field_label_component.rb

Overview

FieldLabelComponent - ViewComponent implementation

Label styled for form fields with disability states. Uses FieldLabelBehavior concern for shared styling logic.

Examples:

With block

<%= render UI::FieldLabelComponent.new(for_id: "email") do %>
  Email Address
<% end %>

Instance Method Summary collapse

Methods included from FieldLabelBehavior

#field_label_classes, #field_label_html_attributes

Constructor Details

#initialize(for_id: nil, classes: "", **attributes) ⇒ FieldLabelComponent

Returns a new instance of FieldLabelComponent.

Parameters:

  • for_id (String) (defaults to: nil)

    ID of the associated form control

  • classes (String) (defaults to: "")

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



18
19
20
21
22
# File 'app/view_components/ui/field_label_component.rb', line 18

def initialize(for_id: nil, classes: "", **attributes)
  @for_id = for_id
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



24
25
26
27
28
# File 'app/view_components/ui/field_label_component.rb', line 24

def call
   :label, **field_label_html_attributes do
    content
  end
end