Module: UI::MenubarContentBehavior

Included in:
MenubarContent, MenubarContentComponent
Defined in:
app/behaviors/ui/menubar_content_behavior.rb

Overview

MenubarContentBehavior

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

Instance Method Summary collapse

Instance Method Details

Returns combined CSS classes for the content



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/behaviors/ui/menubar_content_behavior.rb', line 18

def menubar_content_classes
  classes_value = respond_to?(:classes, true) ? classes : @classes
  base_classes = [
    "bg-popover text-popover-foreground",
    "data-[state=open]:animate-in data-[state=closed]:animate-out",
    "data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
    "data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",
    "data-[side=bottom]:slide-in-from-top-2",
    "data-[side=left]:slide-in-from-right-2",
    "data-[side=right]:slide-in-from-left-2",
    "data-[side=top]:slide-in-from-bottom-2",
    "z-50 min-w-[12rem] overflow-hidden rounded-md border p-1 shadow-md",
    "hidden absolute"
  ].join(" ")

  TailwindMerge::Merger.new.merge([
    base_classes,
    classes_value
  ].compact.join(" "))
end

Returns data attributes for Stimulus target



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/behaviors/ui/menubar_content_behavior.rb', line 40

def menubar_content_data_attributes
  attributes_value = respond_to?(:attributes, true) ? attributes : @attributes

  align_value = defined?(@align) ? @align : "start"
  side_value = defined?(@side) ? @side : "bottom"

  (attributes_value&.fetch(:data, {}) || {}).merge({
    "ui--menubar-target": "content",
    state: "closed",
    side: side_value,
    align: align_value
  })
end

Returns HTML attributes for the content container



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

def menubar_content_html_attributes
  {
    class: menubar_content_classes,
    data: menubar_content_data_attributes,
    role: "menu",
    tabindex: "-1"
  }
end