Class: SdrViewComponents::Elements::Navigation::NavItemComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/sdr_view_components/elements/navigation/nav_item_component.rb

Overview

Component for navigation item link.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#args_for, #mark_label_required, #merge_actions, #merge_classes

Constructor Details

#initialize(text:, path: nil, data: {}, classes: []) ⇒ NavItemComponent

Returns a new instance of NavItemComponent.



8
9
10
11
12
13
14
# File 'app/components/sdr_view_components/elements/navigation/nav_item_component.rb', line 8

def initialize(text:, path: nil, data: {}, classes: [])
  @text = text
  @path = path
  @data = data
  @classes = classes
  super()
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



16
17
18
# File 'app/components/sdr_view_components/elements/navigation/nav_item_component.rb', line 16

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



16
17
18
# File 'app/components/sdr_view_components/elements/navigation/nav_item_component.rb', line 16

def path
  @path
end

#textObject (readonly)

Returns the value of attribute text.



16
17
18
# File 'app/components/sdr_view_components/elements/navigation/nav_item_component.rb', line 16

def text
  @text
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
# File 'app/components/sdr_view_components/elements/navigation/nav_item_component.rb', line 18

def call
  tag.li class: 'nav-item' do
    if path.present?
      link_to text, path, class: classes, data:
    else
      tag.span text, class: classes
    end
  end
end

#classesObject



28
29
30
# File 'app/components/sdr_view_components/elements/navigation/nav_item_component.rb', line 28

def classes
  merge_classes('nav-link', @classes)
end