Class: PhlexKit::MenubarItem
- Inherits:
-
BaseComponent
- Object
- Phlex::HTML
- BaseComponent
- PhlexKit::MenubarItem
- Defined in:
- app/components/phlex_kit/menubar/menubar_item.rb
Overview
Constant Summary collapse
- VARIANTS =
{ default: nil, destructive: "destructive" }.freeze
Instance Method Summary collapse
-
#initialize(as: :a, href: "#", shortcut: nil, variant: :default, inset: false, disabled: false, **attrs) ⇒ MenubarItem
constructor
A new instance of MenubarItem.
- #view_template(&block) ⇒ Object
Methods inherited from BaseComponent
Constructor Details
#initialize(as: :a, href: "#", shortcut: nil, variant: :default, inset: false, disabled: false, **attrs) ⇒ MenubarItem
Returns a new instance of MenubarItem.
9 10 11 12 13 14 15 16 17 |
# File 'app/components/phlex_kit/menubar/menubar_item.rb', line 9 def initialize(as: :a, href: "#", shortcut: nil, variant: :default, inset: false, disabled: false, **attrs) @as = as.to_sym @href = href @shortcut = shortcut @variant = variant.to_sym @inset = inset @disabled = disabled @attrs = attrs end |
Instance Method Details
#view_template(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/components/phlex_kit/menubar/menubar_item.rb', line 19 def view_template(&block) base = { role: "menuitem", tabindex: "-1", class: [ "pk-menubar-item", fetch_option(VARIANTS, @variant, :variant), ("inset" if @inset) ].compact.join(" "), data: @disabled ? { disabled: "true" } : { action: "click->phlex-kit--menubar#close" } } base[:aria] = { disabled: "true" } if @disabled base[:href] = @href unless @as == :div || @disabled send(@as, **mix(base, @attrs)) do block&.call span(class: "pk-menubar-shortcut") { @shortcut } if @shortcut end end |