Class: UI::SidebarMenu

Inherits:
Phlex::HTML
  • Object
show all
Includes:
SidebarMenuBehavior
Defined in:
app/components/ui/sidebar_menu.rb

Overview

Menu - Phlex implementation

List container for sidebar menu items.

Examples:

Basic usage

render UI::Menu.new do
  render UI::MenuItem.new do
    render UI::MenuButton.new do
      render UI::Icon.new(name: "home")
      plain "Home"
    end
  end
end

Instance Method Summary collapse

Methods included from SidebarMenuBehavior

#sidebar_menu_classes, #sidebar_menu_data_attributes, #sidebar_menu_html_attributes

Constructor Details

#initialize(classes: "", **attributes) ⇒ SidebarMenu

Returns a new instance of SidebarMenu.



19
20
21
22
# File 'app/components/ui/sidebar_menu.rb', line 19

def initialize(classes: "", **attributes)
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/components/ui/sidebar_menu.rb', line 24

def view_template(&block)
  all_attributes = sidebar_menu_html_attributes

  if @attributes.key?(:class)
    merged_class = TailwindMerge::Merger.new.merge([
      all_attributes[:class],
      @attributes[:class]
    ].compact.join(" "))
    all_attributes = all_attributes.merge(class: merged_class)
  end

  all_attributes = all_attributes.deep_merge(@attributes.except(:class))

  ul(**all_attributes, &block)
end