Class: Panda::Core::Admin::Navigation::ItemComponent

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

Overview

A top-level navigation item Can be a simple link or an expandable menu with children

Constant Summary collapse

BASE_CLASSES =
"transition-all group flex items-center gap-x-3 px-3 " \
"text-sm font-medium cursor-pointer"
SPACIOUS_PADDING =
"py-2.5"
COMPACT_PADDING =
"py-1.5"
ACTIVE_CLASSES =
"bg-primary-500/20 text-white rounded-xl"
EXPANDED_BUTTON_CLASSES =
"bg-white/15 text-white rounded-t-xl"
INACTIVE_CLASSES =
"text-white/80 hover:bg-white/5 rounded-xl"

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label:, icon:, path: nil, active: false, menu_id: nil, target: nil, badge: nil, badge_color: nil, compact: false, **attrs) ⇒ ItemComponent

rubocop:disable Metrics/ParameterLists



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/components/panda/core/admin/navigation/item_component.rb', line 20

def initialize(label:, icon:, path: nil, active: false, menu_id: nil, target: nil, badge: nil, badge_color: nil, compact: false, **attrs) # rubocop:disable Metrics/ParameterLists
  @label = label
  @icon = icon
  @path = path
  @active = active
  @menu_id = menu_id
  @target = target
  @badge = badge
  @badge_color = badge_color
  @compact = compact
  super(**attrs)
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



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

def active
  @active
end

#badgeObject (readonly)

Returns the value of attribute badge.



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

def badge
  @badge
end

#badge_colorObject (readonly)

Returns the value of attribute badge_color.



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

def badge_color
  @badge_color
end

#iconObject (readonly)

Returns the value of attribute icon.



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

def icon
  @icon
end

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

Returns the value of attribute menu_id.



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

def menu_id
  @menu_id
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#targetObject (readonly)

Returns the value of attribute target.



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

def target
  @target
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/components/panda/core/admin/navigation/item_component.rb', line 35

def active?
  @active
end

#badge_tagObject



59
60
61
62
63
64
# File 'app/components/panda/core/admin/navigation/item_component.rb', line 59

def badge_tag
  return unless badge
  helpers.(:span, badge,
    class: "ml-auto px-1.5 py-0.5 text-[10px] font-semibold rounded-full text-white",
    style: "background-color: #{badge_color || "#52B788"}")
end

#expandable?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/components/panda/core/admin/navigation/item_component.rb', line 39

def expandable?
  sub_items.any?
end


55
56
57
# File 'app/components/panda/core/admin/navigation/item_component.rb', line 55

def link_classes
  "#{BASE_CLASSES} #{padding_class} rounded-xl #{margin_class} #{active? ? "#{ACTIVE_CLASSES} relative" : INACTIVE_CLASSES}"
end

#margin_classObject



47
48
49
# File 'app/components/panda/core/admin/navigation/item_component.rb', line 47

def margin_class
  @compact ? "mb-0.5" : "mb-2"
end

#padding_classObject



43
44
45
# File 'app/components/panda/core/admin/navigation/item_component.rb', line 43

def padding_class
  @compact ? COMPACT_PADDING : SPACIOUS_PADDING
end

#parent_classesObject



51
52
53
# File 'app/components/panda/core/admin/navigation/item_component.rb', line 51

def parent_classes
  "#{BASE_CLASSES} #{padding_class} w-full #{active? ? EXPANDED_BUTTON_CLASSES : INACTIVE_CLASSES}"
end