Module: UI::MenubarLabelBehavior

Included in:
MenubarLabel, MenubarLabelComponent
Defined in:
app/behaviors/ui/menubar_label_behavior.rb

Overview

MenubarLabelBehavior

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

Instance Method Summary collapse

Instance Method Details

Returns combined CSS classes for the label



16
17
18
19
20
21
22
23
24
25
# File 'app/behaviors/ui/menubar_label_behavior.rb', line 16

def menubar_label_classes
  classes_value = respond_to?(:classes, true) ? classes : @classes
  inset_class = inset? ? "pl-8" : ""

  TailwindMerge::Merger.new.merge([
    "px-2 py-1.5 text-sm font-medium",
    inset_class,
    classes_value
  ].compact.join(" "))
end

Returns data attributes for the label



28
29
30
31
32
33
34
# File 'app/behaviors/ui/menubar_label_behavior.rb', line 28

def menubar_label_data_attributes
  attributes_value = respond_to?(:attributes, true) ? attributes : @attributes
  base_data = {}
  base_data[:inset] = "" if inset?

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

Returns HTML attributes for the label



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

def menubar_label_html_attributes
  {
    class: menubar_label_classes,
    data: menubar_label_data_attributes
  }
end