Class: UI::MenubarRadioItem

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

Overview

RadioItem - Phlex implementation

A menu item with radio functionality.

Examples:

Basic usage

render UI::RadioItem.new(value: "option1", checked: true) { "Option 1" }

Instance Method Summary collapse

Methods included from MenubarRadioItemBehavior

#menubar_radio_item_classes, #menubar_radio_item_data_attributes, #menubar_radio_item_html_attributes

Constructor Details

#initialize(value: nil, checked: false, disabled: false, classes: "", **attributes) ⇒ MenubarRadioItem

Returns a new instance of MenubarRadioItem.

Parameters:

  • value (String) (defaults to: nil)

    Value for this radio item

  • checked (Boolean) (defaults to: false)

    Initial checked state

  • disabled (Boolean) (defaults to: false)

    Disable the item

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



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

def initialize(value: nil, checked: false, disabled: false, classes: "", **attributes)
  @value = value
  @checked = checked
  @disabled = disabled
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/ui/menubar_radio_item.rb', line 25

def view_template(&block)
  div(**menubar_radio_item_html_attributes.deep_merge(@attributes)) do
    # Radio indicator container
    span(class: "absolute left-2 flex size-3.5 items-center justify-center") do
      if @checked
        render_radio_icon
      end
    end
    yield if block_given?
  end
end