Module: ViewComponent::MenuComponent

Included in:
UiHelper
Defined in:
app/helpers/view_component/menu_component.rb

Constant Summary collapse

ViewComponent::MenuItem
{
  left: 'menu-component-left',
  right: 'menu-component-right',
  center: 'menu-component-center'
}.freeze

Instance Method Summary collapse

Instance Method Details



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/view_component/menu_component.rb', line 13

def menu_component(menu_items:, position: 'right', html_options: {})
  position_key = position.to_s.downcase.to_sym
  position_class = MENU_POSITIONS[position_key] || MENU_POSITIONS[:right]

  menu_items_with_options = menu_items.map do |item|
    item.options ||= {}
    item.url = item.url.presence || 'javascript:void(0)'
    item
  end

  render(
    'view_components/menu_component/menu_component',
    menu_items: menu_items_with_options,
    position_class: position_class,
    html_options:
  )
end