Class: UI::FieldLabel

Inherits:
Phlex::HTML
  • Object
show all
Includes:
FieldLabelBehavior
Defined in:
app/components/ui/field_label.rb

Overview

Label - Phlex implementation

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

Examples:

Basic usage

render UI::Label.new(for_id: "email") { "Email Address" }

Instance Method Summary collapse

Methods included from FieldLabelBehavior

#field_label_classes, #field_label_html_attributes

Constructor Details

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

Returns a new instance of FieldLabel.

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



16
17
18
19
20
# File 'app/components/ui/field_label.rb', line 16

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

Instance Method Details

#view_template(&block) ⇒ Object



22
23
24
25
26
# File 'app/components/ui/field_label.rb', line 22

def view_template(&block)
  label(**field_label_html_attributes) do
    yield if block_given?
  end
end