Module: UI::ContextMenuTriggerBehavior

Included in:
ContextMenuTrigger, ContextMenuTriggerComponent
Defined in:
app/behaviors/ui/context_menu_trigger_behavior.rb

Overview

ContextMenuTriggerBehavior

Shared behavior for ContextMenuTrigger component across ERB, ViewComponent, and Phlex implementations.

Instance Method Summary collapse

Instance Method Details

#context_menu_trigger_classesObject

Returns combined CSS classes for the trigger



16
17
18
19
20
21
22
# File 'app/behaviors/ui/context_menu_trigger_behavior.rb', line 16

def context_menu_trigger_classes
  classes_value = respond_to?(:classes, true) ? classes : @classes
  TailwindMerge::Merger.new.merge([
    "flex h-[150px] w-[300px] items-center justify-center rounded-md border border-dashed text-sm",
    classes_value
  ].compact.join(" "))
end

#context_menu_trigger_data_attributesObject

Returns data attributes for Stimulus action



25
26
27
28
29
30
31
# File 'app/behaviors/ui/context_menu_trigger_behavior.rb', line 25

def context_menu_trigger_data_attributes
  attributes_value = respond_to?(:attributes, true) ? attributes : @attributes
  (attributes_value&.fetch(:data, {}) || {}).merge({
    action: "contextmenu->ui--context-menu#open",
    "ui--context-menu-target": "trigger"
  })
end

#context_menu_trigger_html_attributesObject

Returns HTML attributes for the context menu trigger



8
9
10
11
12
13
# File 'app/behaviors/ui/context_menu_trigger_behavior.rb', line 8

def context_menu_trigger_html_attributes
  {
    class: context_menu_trigger_classes,
    data: context_menu_trigger_data_attributes
  }
end