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



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

Returns:

  • (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

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


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

def link_data
  build_link_data(@data, @hotkey)
end


55
56
57
# File 'app/components/avo/sidebar/link_component.rb', line 55

def link_icon
  @icon
end

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

Returns:

  • (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 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

#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