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, #merge_actions, #merge_classes

Constructor Details

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

Returns a new instance of NavItemComponent.



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

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

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#callObject



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

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