Class: Phlexi::Menu::Component

Inherits:
COMPONENT_BASE
  • Object
show all
Includes:
Field::Common::Tokens
Defined in:
lib/phlexi/menu/component.rb

Overview

Base menu component that other menu renderers can inherit from. Provides the core rendering logic for hierarchical menus with support for theming, icons, badges, and active state detection.

Examples:

Basic usage

class MyMenu < Phlexi::Menu::Component
  class Theme < Theme
    def self.theme
      super.merge({
        nav: "bg-white shadow",
        item_label: ->(depth) { "text-gray-#{600 + (depth * 100)}" }
      })
    end
  end
end

Defined Under Namespace

Classes: Badge, Theme

Constant Summary collapse

DEFAULT_MAX_DEPTH =

Returns The default maximum nesting depth for menu items.

Returns:

  • (Integer)

    The default maximum nesting depth for menu items

3

Instance Method Summary collapse

Constructor Details

#initialize(menu, max_depth: default_max_depth, **options) ⇒ Component

Initializes a new menu component.

Parameters:

  • menu (Phlexi::Menu::Builder)

    The menu structure to render

  • max_depth (Integer) (defaults to: default_max_depth)

    Maximum nesting depth for menu items

  • options (Hash)

    Additional options passed to rendering methods

Raises:

  • (ArgumentError)

    If menu is nil



38
39
40
41
42
43
44
45
# File 'lib/phlexi/menu/component.rb', line 38

def initialize(menu, max_depth: default_max_depth, **options)
  raise ArgumentError, "Menu cannot be nil" if menu.nil?

  @menu = menu
  @max_depth = max_depth
  @options = options
  super()
end

Instance Method Details

#view_templateObject



47
48
49
# File 'lib/phlexi/menu/component.rb', line 47

def view_template
  nav(class: themed(:nav)) { render_items(@menu.items) }
end