Module: UI::MenubarBehavior

Included in:
Menubar, MenubarComponent
Defined in:
app/behaviors/ui/menubar_behavior.rb

Overview

UI::MenubarBehavior

Instance Method Summary collapse

Instance Method Details

Returns combined CSS classes for the menubar



61
62
63
64
65
66
67
# File 'app/behaviors/ui/menubar_behavior.rb', line 61

def menubar_classes
  classes_value = respond_to?(:classes, true) ? classes : @classes
  TailwindMerge::Merger.new.merge([
    "bg-background flex h-9 items-center gap-1 rounded-md border p-1 shadow-xs",
    classes_value
  ].compact.join(" "))
end

Returns data attributes for Stimulus controller



70
71
72
73
74
75
76
77
78
79
80
# File 'app/behaviors/ui/menubar_behavior.rb', line 70

def menubar_data_attributes
  attributes_value = respond_to?(:attributes, true) ? attributes : @attributes
  base_data = {
    controller: "ui--menubar"
  }

  # Add loop value if specified
  base_data[:"ui--menubar-loop-value"] = @loop if defined?(@loop) && @loop

  (attributes_value&.fetch(:data, {}) || {}).merge(base_data)
end

Returns HTML attributes for the menubar container



47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/behaviors/ui/menubar_behavior.rb', line 47

def menubar_html_attributes
  attrs = {
    class: menubar_classes,
    data: menubar_data_attributes,
    role: "menubar"
  }

  # Add aria-label if provided
  attrs[:"aria-label"] = @aria_label if defined?(@aria_label) && @aria_label

  attrs
end