Class: UI::SelectItem
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- UI::SelectItem
- Includes:
- SelectItemBehavior, SharedAsChildBehavior
- Defined in:
- app/components/ui/select_item.rb
Overview
Select Item - Phlex implementation
Individual selectable option in the dropdown. Supports asChild pattern for composition.
Instance Method Summary collapse
-
#initialize(as_child: false, value: nil, disabled: false, classes: "", **attributes) ⇒ SelectItem
constructor
A new instance of SelectItem.
- #view_template(&block) ⇒ Object
Methods included from SharedAsChildBehavior
Methods included from SelectItemBehavior
#select_item_classes, #select_item_html_attributes
Constructor Details
#initialize(as_child: false, value: nil, disabled: false, classes: "", **attributes) ⇒ SelectItem
Returns a new instance of SelectItem.
29 30 31 32 33 34 35 |
# File 'app/components/ui/select_item.rb', line 29 def initialize(as_child: false, value: nil, disabled: false, classes: "", **attributes) @as_child = as_child @value = value @disabled = disabled @classes = classes @attributes = attributes end |
Instance Method Details
#view_template(&block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/components/ui/select_item.rb', line 37 def view_template(&block) item_attrs = select_item_html_attributes.deep_merge(@attributes) if @as_child # asChild mode: yield attributes to block yield(item_attrs) if block_given? else # Default mode: render as div div(**item_attrs) do span(class: "flex-1") do yield if block_given? end # Checkmark icon - hidden by default, shown when selected svg( data_ui__select_target: "itemCheck", class: "ml-auto size-4 opacity-0 transition-opacity", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", stroke_width: "2", stroke_linecap: "round", stroke_linejoin: "round" ) do |s| s.path(d: "M20 6 9 17l-5-5") end end end end |