Class: Components::BurgerMenu

Inherits:
Base
  • Object
show all
Defined in:
app/components/burger_menu.rb

Instance Method Summary collapse

Constructor Details

#initialize(small: false, direction: :down, id: SecureRandom.uuid, data: {}) ⇒ BurgerMenu

Returns a new instance of BurgerMenu.



4
5
6
7
8
9
# File 'app/components/burger_menu.rb', line 4

def initialize(small: false, direction: :down, id: SecureRandom.uuid, data: {})
  @small = small
  @id = id
  @data = data
  @direction = direction
end

Instance Method Details

#view_template ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/burger_menu.rb', line 11

def view_template
  classes = %w[btn btn-secondary]
  classes << "btn-sm" if @small
  div id: @id, data: @data, class: ("dropup" if @direction == :up) do
    a id: @id + "-anchor",
      href: "#",
      data: {
        bs_toggle: "dropdown"
      },
      aria: {
        expanded: false,
        haspopup: "menu",
        controls: "#{@id}-menu"
      },
      class: classes.join(" "),
      tabindex: 0 do
      Icon icon: "list", label: t("general.menu")
    end
    ul class: "dropdown-menu dropdown-menu-end",
      id: "#{@id}-menu",
      role: "menu",
      aria: {labelledby: @id + "-anchor"} do
      yield
    end
  end
end