Class: UI::ContextMenu

Inherits:
Phlex::HTML
  • Object
show all
Includes:
ContextMenuBehavior
Defined in:
app/components/ui/context_menu.rb

Overview

ContextMenu - Phlex implementation

Container for context menus triggered by right-click. Uses ContextMenuBehavior concern for shared styling logic.

Examples:

Basic usage

render UI::ContextMenu.new do
  render UI::Trigger.new { "Right-click me" }
  render UI::Content.new do
    render UI::Item.new { "Menu Item" }
  end
end

Instance Method Summary collapse

Methods included from ContextMenuBehavior

#context_menu_classes, #context_menu_data_attributes, #context_menu_html_attributes

Constructor Details

#initialize(classes: "", **attributes) ⇒ ContextMenu

Returns a new instance of ContextMenu.

Parameters:

  • classes (String) (defaults to: "")

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



20
21
22
23
# File 'app/components/ui/context_menu.rb', line 20

def initialize(classes: "", **attributes)
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



25
26
27
28
29
# File 'app/components/ui/context_menu.rb', line 25

def view_template(&block)
  div(**context_menu_html_attributes.deep_merge(@attributes)) do
    yield if block_given?
  end
end