Class: UI::SelectGroup

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

Overview

Select Group - Phlex implementation

Container for grouping select items with a label. Supports asChild pattern for composition.

Examples:

Basic usage

render UI::Group.new do
  render UI::Label.new { "North America" }
  render UI::Item.new(value: "america/new_york") { "Eastern Time" }
  render UI::Item.new(value: "america/chicago") { "Central Time" }
end

Instance Method Summary collapse

Methods included from SharedAsChildBehavior

#merge_attributes

Methods included from SelectGroupBehavior

#select_group_classes, #select_group_html_attributes

Constructor Details

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

Returns a new instance of SelectGroup.

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



21
22
23
24
25
# File 'app/components/ui/select_group.rb', line 21

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

Instance Method Details

#view_template(&block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'app/components/ui/select_group.rb', line 27

def view_template(&block)
  group_attrs = select_group_html_attributes.deep_merge(@attributes)

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