Class: Avo::Sidebar::LinkComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- Avo::Sidebar::LinkComponent
- Defined in:
- app/components/avo/sidebar/link_component.rb
Instance Method Summary collapse
- #active_item_index ⇒ Object
- #is_external? ⇒ Boolean
-
#link_caller ⇒ Object
Backwards compatibility with ViewComponent 3.x.
- #link_data ⇒ Object
- #link_icon ⇒ Object
-
#link_method ⇒ Object
For external links active_link_to marks them all as active.
- #parent_link_active? ⇒ Boolean
- #subitem_bar_class(index) ⇒ Object
- #subitem_data(item) ⇒ Object
Instance Method Details
#active_item_index ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/components/avo/sidebar/link_component.rb', line 59 def active_item_index return @active_item_index if defined?(@active_item_index) @active_item_index = @items&.index do |item| item.path.present? && helpers.is_active_link?(item.path, @active) end end |
#is_external? ⇒ Boolean
29 30 31 32 33 34 |
# File 'app/components/avo/sidebar/link_component.rb', line 29 def is_external? # If the path contains the scheme, check if it includes the root path or not return !@path.include?(helpers.mount_path) if URI(@path).scheme.present? false end |
#link_caller ⇒ Object
Backwards compatibility with ViewComponent 3.x
42 43 44 45 46 47 48 |
# File 'app/components/avo/sidebar/link_component.rb', line 42 def link_caller if Gem::Version.new(ViewComponent::VERSION::STRING) >= Gem::Version.new("4.0.0") helpers else self end end |
#link_data ⇒ Object
21 22 23 |
# File 'app/components/avo/sidebar/link_component.rb', line 21 def link_data build_link_data(@data, @hotkey) end |
#link_icon ⇒ Object
55 56 57 |
# File 'app/components/avo/sidebar/link_component.rb', line 55 def link_icon @icon end |
#link_method ⇒ Object
For external links active_link_to marks them all as active.
37 38 39 |
# File 'app/components/avo/sidebar/link_component.rb', line 37 def link_method is_external? ? :link_to : :active_link_to end |
#parent_link_active? ⇒ Boolean
50 51 52 53 |
# File 'app/components/avo/sidebar/link_component.rb', line 50 def parent_link_active? return false if @path.blank? helpers.is_active_link?(@path, @active) end |
#subitem_bar_class(index) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/components/avo/sidebar/link_component.rb', line 67 def (index) active_idx = active_item_index return "" if active_idx.nil? if index == active_idx "sidebar-subitem--bar-active" elsif index < active_idx "sidebar-subitem--bar-pass" else "" end end |
#subitem_data(item) ⇒ Object
25 26 27 |
# File 'app/components/avo/sidebar/link_component.rb', line 25 def subitem_data(item) build_link_data(item.data, item.hotkey) end |