Class: UI::LabelComponent

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

Overview

LabelComponent - ViewComponent implementation

Accessible label for form inputs following shadcn/ui design patterns.

Instance Method Summary collapse

Methods included from LabelBehavior

#label_classes, #label_html_attributes

Constructor Details

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

Returns a new instance of LabelComponent.

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



12
13
14
15
16
# File 'app/view_components/ui/label_component.rb', line 12

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

Instance Method Details

#callObject



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

def call
   :label, **label_html_attributes.merge(@attributes.except(:data)) do
    content
  end
end