Class: PhlexKit::ContextMenuItem
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::ContextMenuItem
- Defined in:
- app/components/phlex_kit/context_menu/context_menu_item.rb
Overview
A menu row in a PhlexKit::ContextMenuContent. Matches the dropdown-menu
grammar: gap-based layout (no forced inset), variant: :destructive,
checked: renders a leading ✓, shortcut: a trailing kbd hint (or
compose ContextMenuShortcut yourself). Closes the menu on click.
See context_menu.rb.
Constant Summary collapse
- VARIANTS =
{ default: nil, destructive: "destructive" }.freeze
Instance Method Summary collapse
-
#initialize(href: "#", checked: false, shortcut: nil, disabled: false, variant: :default, **attrs) ⇒ ContextMenuItem
constructor
A new instance of ContextMenuItem.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(href: "#", checked: false, shortcut: nil, disabled: false, variant: :default, **attrs) ⇒ ContextMenuItem
Returns a new instance of ContextMenuItem.
10 11 12 13 14 15 16 17 |
# File 'app/components/phlex_kit/context_menu/context_menu_item.rb', line 10 def initialize(href: "#", checked: false, shortcut: nil, disabled: false, variant: :default, **attrs) @href = href @checked = checked @shortcut = shortcut @disabled = disabled @variant = variant.to_sym @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/components/phlex_kit/context_menu/context_menu_item.rb', line 19 def view_template(&block) classes = [ "pk-context-menu-item", fetch_option(VARIANTS, @variant, :variant) ].compact.join(" ") base = { href: @href, role: "menuitem", tabindex: "-1", class: classes, data: { action: ("click->phlex-kit--context-menu#close" unless @disabled), phlex_kit__context_menu_target: "menuItem", disabled: (@disabled ? "true" : nil) }.compact } base[:aria] = { disabled: "true" } if @disabled a(**mix(base, @attrs)) do if @checked span(class: "pk-context-menu-check") do render Icon.new(:check, size: nil) end end yield span(class: "pk-context-menu-shortcut") { @shortcut } if @shortcut end end |