Class: Panda::Core::Admin::Navigation::ItemComponent
- Inherits:
-
Base
- Object
- ViewComponent::Base
- Base
- Panda::Core::Admin::Navigation::ItemComponent
- 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
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#badge ⇒ Object
readonly
Returns the value of attribute badge.
-
#badge_color ⇒ Object
readonly
Returns the value of attribute badge_color.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#menu_id ⇒ Object
readonly
Returns the value of attribute menu_id.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #badge_tag ⇒ Object
- #expandable? ⇒ Boolean
-
#initialize(label:, icon:, path: nil, active: false, menu_id: nil, target: nil, badge: nil, badge_color: nil, compact: false, **attrs) ⇒ ItemComponent
constructor
rubocop:disable Metrics/ParameterLists.
- #link_classes ⇒ Object
- #margin_class ⇒ Object
- #padding_class ⇒ Object
- #parent_classes ⇒ Object
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 = @target = target @badge = badge @badge_color = badge_color @compact = compact super(**attrs) end |
Instance Attribute Details
#active ⇒ Object (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 |
#badge ⇒ Object (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_color ⇒ Object (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 |
#icon ⇒ Object (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 |
#label ⇒ Object (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 |
#menu_id ⇒ Object (readonly)
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 end |
#path ⇒ Object (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 |
#target ⇒ Object (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
35 36 37 |
# File 'app/components/panda/core/admin/navigation/item_component.rb', line 35 def active? @active end |
#badge_tag ⇒ Object
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.content_tag(: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
39 40 41 |
# File 'app/components/panda/core/admin/navigation/item_component.rb', line 39 def sub_items.any? end |
#link_classes ⇒ Object
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_class ⇒ Object
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_class ⇒ Object
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_classes ⇒ Object
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 |