Class: SdrViewComponents::Elements::Navigation::NavItemComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- SdrViewComponents::Elements::Navigation::NavItemComponent
- Defined in:
- app/components/sdr_view_components/elements/navigation/nav_item_component.rb
Overview
Component for navigation item link.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #call ⇒ Object
- #classes ⇒ Object
-
#initialize(text:, path: nil, data: {}, classes: []) ⇒ NavItemComponent
constructor
A new instance of NavItemComponent.
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
#data ⇒ Object (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 |
#path ⇒ Object (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 |
#text ⇒ Object (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
#call ⇒ Object
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 |
#classes ⇒ Object
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 |