Class: GovukComponent::ServiceNavigationComponent::NavigationItemComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/govuk_component/service_navigation_component/navigation_item_component.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods inherited from Base

#brand, #class_prefix

Constructor Details

#initialize(text:, href: nil, current_path: nil, active_when: nil, current: false, active: false, classes: [], html_attributes: {}) ⇒ NavigationItemComponent

Returns a new instance of NavigationItemComponent.



4
5
6
7
8
9
10
11
12
13
14
# File 'app/components/govuk_component/service_navigation_component/navigation_item_component.rb', line 4

def initialize(text:, href: nil, current_path: nil, active_when: nil, current: false, active: false, classes: [], html_attributes: {})
  @current = current
  @active = active
  @text = text
  @href = href

  @current_path = current_path
  @active_when = active_when

  super(classes:, html_attributes:)
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



2
3
4
# File 'app/components/govuk_component/service_navigation_component/navigation_item_component.rb', line 2

def active
  @active
end

#active_whenObject (readonly)

Returns the value of attribute active_when.



2
3
4
# File 'app/components/govuk_component/service_navigation_component/navigation_item_component.rb', line 2

def active_when
  @active_when
end

#currentObject (readonly)

Returns the value of attribute current.



2
3
4
# File 'app/components/govuk_component/service_navigation_component/navigation_item_component.rb', line 2

def current
  @current
end

#current_pathObject (readonly)

Returns the value of attribute current_path.



2
3
4
# File 'app/components/govuk_component/service_navigation_component/navigation_item_component.rb', line 2

def current_path
  @current_path
end

#hrefObject (readonly)

Returns the value of attribute href.



2
3
4
# File 'app/components/govuk_component/service_navigation_component/navigation_item_component.rb', line 2

def href
  @href
end

#textObject (readonly)

Returns the value of attribute text.



2
3
4
# File 'app/components/govuk_component/service_navigation_component/navigation_item_component.rb', line 2

def text
  @text
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
# File 'app/components/govuk_component/service_navigation_component/navigation_item_component.rb', line 16

def call
  tag.li(**html_attributes) do
    if href.present?
      wrap_link(link_to(text, href, class: "#{brand}-service-navigation__link", **aria_current))
    else
      tag.span(text, class: "#{brand}-service-navigation__text")
    end
  end
end