Class: UI::Label

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

Overview

Label - Phlex implementation

Accessible label for form inputs following shadcn/ui design patterns. Uses LabelBehavior concern for shared styling logic.

Examples:

Basic usage

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

With custom classes

render UI::Label.new(for_id: "password", classes: "text-destructive") { "Password" }

Instance Method Summary collapse

Methods included from LabelBehavior

#label_classes, #label_html_attributes

Constructor Details

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

Returns a new instance of Label.

Parameters:

  • for_id (String) (defaults to: nil)

    The ID of the form element this label is for

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



19
20
21
22
23
# File 'app/components/ui/label.rb', line 19

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

Instance Method Details

#view_template(&block) ⇒ Object



25
26
27
28
29
# File 'app/components/ui/label.rb', line 25

def view_template(&block)
  label(**label_html_attributes.deep_merge(@attributes)) do
    yield if block_given?
  end
end