Class: UI::SelectLabel

Inherits:
Phlex::HTML
  • Object
show all
Includes:
SelectLabelBehavior, SharedAsChildBehavior
Defined in:
app/components/ui/select_label.rb

Overview

Select Label - Phlex implementation

Label for a group of select items. Supports asChild pattern for composition.

Examples:

Basic usage

render UI::Label.new { "North America" }

Instance Method Summary collapse

Methods included from SharedAsChildBehavior

#merge_attributes

Methods included from SelectLabelBehavior

#select_label_classes, #select_label_html_attributes

Constructor Details

#initialize(as_child: false, classes: "", **attributes) ⇒ SelectLabel

Returns a new instance of SelectLabel.

Parameters:

  • as_child (Boolean) (defaults to: false)

    When true, yields attributes to block instead of rendering div

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



17
18
19
20
21
# File 'app/components/ui/select_label.rb', line 17

def initialize(as_child: false, classes: "", **attributes)
  @as_child = as_child
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/ui/select_label.rb', line 23

def view_template(&block)
  label_attrs = select_label_html_attributes.deep_merge(@attributes)

  if @as_child
    # asChild mode: yield attributes to block
    yield(label_attrs) if block_given?
  else
    # Default mode: render as div
    div(**label_attrs, &block)
  end
end