Class: UI::ContextMenuItemComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ContextMenuItemBehavior
Defined in:
app/view_components/ui/context_menu_item_component.rb

Overview

ItemComponent - ViewComponent implementation

Instance Method Summary collapse

Methods included from ContextMenuItemBehavior

#context_menu_item_classes, #context_menu_item_data_attributes, #context_menu_item_html_attributes

Constructor Details

#initialize(href: nil, inset: false, variant: "default", classes: "", **attributes) ⇒ ContextMenuItemComponent

Returns a new instance of ContextMenuItemComponent.



7
8
9
10
11
12
13
# File 'app/view_components/ui/context_menu_item_component.rb', line 7

def initialize(href: nil, inset: false, variant: "default", classes: "", **attributes)
  @href = href
  @inset = inset
  @variant = variant
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#call ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/view_components/ui/context_menu_item_component.rb', line 15

def call
  attrs = context_menu_item_html_attributes
  attrs[:data] = attrs[:data].merge(@attributes.fetch(:data, {}))

  if @href
     :a, **attrs.merge(@attributes.except(:data)) do
      content
    end
  else
     :div, **attrs.merge(@attributes.except(:data)) do
      content
    end
  end
end