Class: UI::MenubarCheckboxItem

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

Overview

CheckboxItem - Phlex implementation

A menu item with checkbox functionality.

Examples:

Basic usage

render UI::CheckboxItem.new(checked: true) { "Show Toolbar" }

Instance Method Summary collapse

Methods included from MenubarCheckboxItemBehavior

#menubar_checkbox_item_classes, #menubar_checkbox_item_data_attributes, #menubar_checkbox_item_html_attributes

Constructor Details

#initialize(checked: false, disabled: false, classes: "", **attributes) ⇒ MenubarCheckboxItem

Returns a new instance of MenubarCheckboxItem.

Parameters:

  • 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



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

def initialize(checked: false, disabled: false, classes: "", **attributes)
  @checked = checked
  @disabled = disabled
  @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/menubar_checkbox_item.rb', line 23

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