Class: GovukComponent::LanguageNavigationComponent
- Inherits:
-
Base
- Object
- Base
- GovukComponent::LanguageNavigationComponent
- Defined in:
- app/components/govuk_component/language_navigation_component.rb
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#any_rtl ⇒ Object
readonly
Returns the value of attribute any_rtl.
-
#inverse ⇒ Object
readonly
Returns the value of attribute inverse.
Instance Method Summary collapse
- #before_render ⇒ Object
- #call ⇒ Object
- #default_attributes ⇒ Object
-
#initialize(items: [], inverse: false, classes: [], html_attributes: {}) ⇒ LanguageNavigationComponent
constructor
A new instance of LanguageNavigationComponent.
- #render? ⇒ Boolean
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_rtl ⇒ Object (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 |
#inverse ⇒ Object (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_render ⇒ Object
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 |
#call ⇒ Object
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_attributes ⇒ Object
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
26 27 28 |
# File 'app/components/govuk_component/language_navigation_component.rb', line 26 def render? items.any? end |