Class: Collavre::PopupMenuComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/collavre/popup_menu_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(button_content:, button_classes: "", menu_classes: "", menu_id: nil, align: :left, button_attributes: {}) ⇒ PopupMenuComponent

Returns a new instance of PopupMenuComponent.



3
4
5
6
7
8
9
10
# File 'app/components/collavre/popup_menu_component.rb', line 3

def initialize(button_content:, button_classes: "", menu_classes: "", menu_id: nil, align: :left, button_attributes: {})
  @button_content = button_content
  @button_classes = button_classes
  @menu_classes = menu_classes
  @menu_id = menu_id || "popup-menu-#{SecureRandom.hex(4)}"
  @align = align
  @button_attributes = button_attributes
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



12
13
14
# File 'app/components/collavre/popup_menu_component.rb', line 12

def align
  @align
end

#button_attributesObject (readonly)

Returns the value of attribute button_attributes.



12
13
14
# File 'app/components/collavre/popup_menu_component.rb', line 12

def button_attributes
  @button_attributes
end

#button_classesObject (readonly)

Returns the value of attribute button_classes.



12
13
14
# File 'app/components/collavre/popup_menu_component.rb', line 12

def button_classes
  @button_classes
end

#button_contentObject (readonly)

Returns the value of attribute button_content.



12
13
14
# File 'app/components/collavre/popup_menu_component.rb', line 12

def button_content
  @button_content
end

Returns the value of attribute menu_classes.



12
13
14
# File 'app/components/collavre/popup_menu_component.rb', line 12

def menu_classes
  @menu_classes
end

Returns the value of attribute menu_id.



12
13
14
# File 'app/components/collavre/popup_menu_component.rb', line 12

def menu_id
  @menu_id
end

Instance Method Details

#button_optionsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/components/collavre/popup_menu_component.rb', line 14

def button_options
  defaults = {
    type: "button",
    class: [ "popup-menu-toggle", button_classes.presence ].compact.join(" "),
    data: {
      action: "click->popup-menu#toggle",
      popup_menu_target: "button"
    }
  }

  return defaults if button_attributes.blank?

  defaults.deep_merge(button_attributes) do |key, this_val, other_val|
    key == :class ? [ this_val, other_val ].compact.join(" ") : other_val
  end
end