Class: Jav::Sidebar::LinkComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/jav/sidebar/link_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label: nil, path: nil, active: :inclusive, target: nil, data: {}, icon: nil) ⇒ LinkComponent

Returns a new instance of LinkComponent.



6
7
8
9
10
11
12
13
# File 'app/components/jav/sidebar/link_component.rb', line 6

def initialize(label: nil, path: nil, active: :inclusive, target: nil, data: {}, icon: nil)
  @label = label
  @path = path
  @active = active
  @target = target
  @data = data
  @icon = icon
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



4
5
6
# File 'app/components/jav/sidebar/link_component.rb', line 4

def active
  @active
end

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'app/components/jav/sidebar/link_component.rb', line 4

def data
  @data
end

#iconObject (readonly)

Returns the value of attribute icon.



4
5
6
# File 'app/components/jav/sidebar/link_component.rb', line 4

def icon
  @icon
end

#labelObject (readonly)

Returns the value of attribute label.



4
5
6
# File 'app/components/jav/sidebar/link_component.rb', line 4

def label
  @label
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'app/components/jav/sidebar/link_component.rb', line 4

def path
  @path
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'app/components/jav/sidebar/link_component.rb', line 4

def target
  @target
end

Instance Method Details

#classesObject



27
28
29
# File 'app/components/jav/sidebar/link_component.rb', line 27

def classes
  'px-4 pr-0 flex-1 flex mx-6 leading-none py-2 text-black rounded-sm font-medium hover:bg-gray-100 gap-1'
end

#is_external?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'app/components/jav/sidebar/link_component.rb', line 15

def is_external?
  # If the path contains the scheme, check if it includes the root path or not
  return path.exclude?(Jav::App.root_path) if URI(path).scheme.present?

  false
end

For external links active_link_to marks them all as active.



23
24
25
# File 'app/components/jav/sidebar/link_component.rb', line 23

def link_method
  is_external? ? :link_to : :active_link_to
end