Class: Avo::Sidebar::LinkComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/avo/sidebar/link_component.rb

Instance Method Summary collapse

Instance Method Details

#active_item_indexObject



50
51
52
53
54
55
56
# File 'app/components/avo/sidebar/link_component.rb', line 50

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

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'app/components/avo/sidebar/link_component.rb', line 20

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

Backwards compatibility with ViewComponent 3.x



33
34
35
36
37
38
39
# File 'app/components/avo/sidebar/link_component.rb', line 33

def link_caller
  if Gem::Version.new(ViewComponent::VERSION::STRING) >= Gem::Version.new("4.0.0")
    helpers
  else
    self
  end
end


46
47
48
# File 'app/components/avo/sidebar/link_component.rb', line 46

def link_icon
  @icon
end

For external links active_link_to marks them all as active.



28
29
30
# File 'app/components/avo/sidebar/link_component.rb', line 28

def link_method
  is_external? ? :link_to : :active_link_to
end

Returns:

  • (Boolean)


41
42
43
44
# File 'app/components/avo/sidebar/link_component.rb', line 41

def parent_link_active?
  return false if @path.blank?
  helpers.is_active_link?(@path, @active)
end

#subitem_bar_class(index) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/components/avo/sidebar/link_component.rb', line 58

def subitem_bar_class(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