Class: GovukComponent::LanguageNavigationComponent

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

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items: [], inverse: false, classes: [], html_attributes: {}) ⇒ LanguageNavigationComponent

Returns a new instance of LanguageNavigationComponent.



6
7
8
9
10
11
12
# File 'app/components/govuk_component/language_navigation_component.rb', line 6

def initialize(items: [], inverse: false, classes: [], html_attributes: {})
  @items = items
  @any_rtl = items.any? { |item| item.symbolize_keys[:dir] == 'rtl' }
  @inverse = inverse

  super(classes:, html_attributes:)
end

Instance Attribute Details

#any_rtlObject (readonly)

Returns the value of attribute any_rtl.



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

def any_rtl
  @any_rtl
end

#inverseObject (readonly)

Returns the value of attribute inverse.



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

def inverse
  @inverse
end

Instance Method Details

#before_renderObject



14
15
16
# File 'app/components/govuk_component/language_navigation_component.rb', line 14

def before_render
  @items.each { |item| with_item(**item, any_rtl:) }
end

#callObject



18
19
20
21
22
23
24
# File 'app/components/govuk_component/language_navigation_component.rb', line 18

def call
  tag.nav(**html_attributes) do
    tag.ul(class: "#{brand}-language-navigation__list") do
      safe_join(items)
    end
  end
end

#default_attributesObject



30
31
32
33
34
35
36
37
38
# File 'app/components/govuk_component/language_navigation_component.rb', line 30

def default_attributes
  {
    class: class_names(
      "#{brand}-language-navigation",
      "#{brand}-language-navigation--inverse" => inverse
    ),
    aria: { label: 'language' }
  }
end

#render?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/components/govuk_component/language_navigation_component.rb', line 26

def render?
  items.any?
end