Class: PhlexKit::DropdownMenuItem

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/dropdown_menu/dropdown_menu_item.rb

Overview

A menu row in a PhlexKit::DropdownMenuContent. as: :a (default, pass href:) or :div (e.g. to wrap a button_to). Closes the menu on click. See dropdown_menu.rb.

Constant Summary collapse

VARIANTS =
{ default: nil, destructive: "destructive" }.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(as: :a, href: "#", variant: :default, **attrs) ⇒ DropdownMenuItem

Returns a new instance of DropdownMenuItem.



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

def initialize(as: :a, href: "#", variant: :default, **attrs)
  @as = as.to_sym
  @href = href
  @variant = variant.to_sym
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'app/components/phlex_kit/dropdown_menu/dropdown_menu_item.rb', line 14

def view_template(&block)
  base = {
    role: "menuitem",
    tabindex: "-1",
    class: [ "pk-dropdown-menu-item", fetch_option(VARIANTS, @variant, :variant) ].compact.join(" "),
    data: { phlex_kit__dropdown_menu_target: "menuItem", action: "click->phlex-kit--dropdown-menu#close" }
  }
  base[:href] = @href unless @as == :div
  send(@as, **mix(base, @attrs), &block)
end