Class: PhlexKit::ContextMenuCheckboxItem

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/phlex_kit/context_menu/context_menu_checkbox_item.rb

Overview

Toggleable row, mirroring shadcn/ui's ContextMenuCheckboxItem: a

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(checked: false, name: nil, value: "1", **attrs) ⇒ ContextMenuCheckboxItem

Returns a new instance of ContextMenuCheckboxItem.



7
8
9
10
11
12
# File 'app/components/phlex_kit/context_menu/context_menu_checkbox_item.rb', line 7

def initialize(checked: false, name: nil, value: "1", **attrs)
  @checked = checked
  @name = name
  @value = value
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/components/phlex_kit/context_menu/context_menu_checkbox_item.rb', line 14

def view_template(&block)
  base = {
    class: "pk-context-menu-item pk-context-menu-checkbox-item",
    data: { phlex_kit__context_menu_target: "menuItem" }
  }
  # Defaults only when the caller didn't supply their own — `mix` fuses.
  base[:role] = "menuitemcheckbox" unless attr_set?(:role)
  base[:tabindex] = "-1" unless attr_set?(:tabindex)
  base[:"aria-checked"] = (@checked ? "true" : "false") unless aria_key_set?(:checked)
  label(**mix(base, @attrs)) do
    input(type: :checkbox, class: "pk-context-menu-item-input", name: @name, value: @value, checked: @checked,
          tabindex: "-1", data: { action: "change->phlex-kit--context-menu#syncChecked" })
    span(class: "pk-context-menu-item-indicator", aria: { hidden: "true" }) do
      render Icon.new(:check, size: nil)
    end
    yield if block
  end
end