Class: GovukComponent::ServiceNavigationComponent

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

Defined Under Namespace

Classes: NavigationItemComponent, ServiceNameComponent

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods inherited from Base

#brand, #class_prefix

Constructor Details

#initialize(service_name: nil, service_url: nil, navigation_items: [], current_path: nil, aria_label: "Service information", navigation_id: 'navigation', classes: [], html_attributes: {}) ⇒ ServiceNavigationComponent

Returns a new instance of ServiceNavigationComponent.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/govuk_component/service_navigation_component.rb', line 21

def initialize(service_name: nil, service_url: nil, navigation_items: [], current_path: nil, aria_label: "Service information", navigation_id: 'navigation', classes: [], html_attributes: {})
  @service_name_text = service_name
  @service_url = service_url
  @current_path = current_path
  @aria_label_text = aria_label
  @navigation_id = navigation_id

  if @service_name_text.present?
    with_service_name(service_name: @service_name_text, service_url:)
  end

  navigation_items.each { |ni| with_navigation_item(current_path:, **ni) }

  super(classes:, html_attributes:)
end

Instance Attribute Details

#aria_label_textObject (readonly)

Returns the value of attribute aria_label_text.



19
20
21
# File 'app/components/govuk_component/service_navigation_component.rb', line 19

def aria_label_text
  @aria_label_text
end

Returns the value of attribute navigation_id.



19
20
21
# File 'app/components/govuk_component/service_navigation_component.rb', line 19

def navigation_id
  @navigation_id
end

Instance Method Details

#callObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/components/govuk_component/service_navigation_component.rb', line 37

def call
  outer_element do
    tag.div(class: "#{brand}-width_container") do
      safe_join(
        [
          start_slot,
          tag.div(class: "#{brand}-service-navigation__container") do
            safe_join([service_name, navigation].compact)
          end,
          end_slot
        ]
      )
    end
  end
end


53
54
55
56
57
58
59
# File 'app/components/govuk_component/service_navigation_component.rb', line 53

def navigation
  return unless navigation_items?

  tag.nav(aria: { label: "Menu" }, class: "#{brand}-service-navigation__wrapper") do
    safe_join([menu_button, navigation_list])
  end
end


61
62
63
# File 'app/components/govuk_component/service_navigation_component.rb', line 61

def navigation_list
  tag.ul(safe_join(navigation_items), id: navigation_id, class: "#{brand}-service-navigation__list")
end