Class: Panda::Core::Admin::Navigation::SubItemComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/panda/core/admin/navigation/sub_item_component.rb

Overview

A child item within an expandable navigation menu Can render as a link or a button (for logout, etc.)

Constant Summary collapse

BASE_CLASSES =
"group flex items-center w-full px-3 py-2 cursor-pointer " \
"text-sm font-medium transition-colors"
ACTIVE_CLASSES =
"bg-primary-500/20 text-white"
INACTIVE_CLASSES =
"text-white/70 hover:bg-white/5"

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, path: nil, active: false, method: nil, button_options: {}, target: nil, **attrs) ⇒ SubItemComponent

rubocop:disable Metrics/ParameterLists



16
17
18
19
20
21
22
23
24
# File 'app/components/panda/core/admin/navigation/sub_item_component.rb', line 16

def initialize(label:, path: nil, active: false, method: nil, button_options: {}, target: nil, **attrs)
  @label = label
  @path = path
  @active = active
  @method = method
  @button_options = button_options
  @target = target
  super(**attrs)
end

Instance Attribute Details

#activeObject (readonly)

rubocop:enable Metrics/ParameterLists



27
28
29
# File 'app/components/panda/core/admin/navigation/sub_item_component.rb', line 27

def active
  @active
end

#button_optionsObject (readonly)

rubocop:enable Metrics/ParameterLists



27
28
29
# File 'app/components/panda/core/admin/navigation/sub_item_component.rb', line 27

def button_options
  @button_options
end

#labelObject (readonly)

rubocop:enable Metrics/ParameterLists



27
28
29
# File 'app/components/panda/core/admin/navigation/sub_item_component.rb', line 27

def label
  @label
end

#methodObject (readonly)

rubocop:enable Metrics/ParameterLists



27
28
29
# File 'app/components/panda/core/admin/navigation/sub_item_component.rb', line 27

def method
  @method
end

#pathObject (readonly)

rubocop:enable Metrics/ParameterLists



27
28
29
# File 'app/components/panda/core/admin/navigation/sub_item_component.rb', line 27

def path
  @path
end

#targetObject (readonly)

rubocop:enable Metrics/ParameterLists



27
28
29
# File 'app/components/panda/core/admin/navigation/sub_item_component.rb', line 27

def target
  @target
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/components/panda/core/admin/navigation/sub_item_component.rb', line 29

def active?
  @active
end

#button?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/components/panda/core/admin/navigation/sub_item_component.rb', line 33

def button?
  method.present?
end

#item_classesObject



37
38
39
# File 'app/components/panda/core/admin/navigation/sub_item_component.rb', line 37

def item_classes
  "#{BASE_CLASSES} #{active? ? ACTIVE_CLASSES : INACTIVE_CLASSES}"
end