Class: GovukComponent::HeaderComponent::NavigationItem
- Inherits:
-
Base
- Object
- ViewComponent::Base
- Base
- GovukComponent::HeaderComponent::NavigationItem
- Defined in:
- app/components/govuk_component/header_component.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Attributes inherited from Base
Instance Method Summary collapse
- #active_class ⇒ Object
- #before_render ⇒ Object
- #call ⇒ Object
-
#initialize(text:, href: nil, options: {}, active: nil, classes: [], html_attributes: {}) ⇒ NavigationItem
constructor
A new instance of NavigationItem.
- #link? ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(text:, href: nil, options: {}, active: nil, classes: [], html_attributes: {}) ⇒ NavigationItem
Returns a new instance of NavigationItem.
68 69 70 71 72 73 74 75 |
# File 'app/components/govuk_component/header_component.rb', line 68 def initialize(text:, href: nil, options: {}, active: nil, classes: [], html_attributes: {}) @text = text @href = href = @active_override = active super(classes:, html_attributes:) end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
66 67 68 |
# File 'app/components/govuk_component/header_component.rb', line 66 def active @active end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
66 67 68 |
# File 'app/components/govuk_component/header_component.rb', line 66 def href @href end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
66 67 68 |
# File 'app/components/govuk_component/header_component.rb', line 66 def end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
66 67 68 |
# File 'app/components/govuk_component/header_component.rb', line 66 def text @text end |
Instance Method Details
#active_class ⇒ Object
83 84 85 |
# File 'app/components/govuk_component/header_component.rb', line 83 def active_class ["#{brand}-header__navigation-item--active"] if active? end |
#before_render ⇒ Object
77 78 79 80 81 |
# File 'app/components/govuk_component/header_component.rb', line 77 def before_render if active? html_attributes[:class] << active_class end end |
#call ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'app/components/govuk_component/header_component.rb', line 91 def call tag.li(**html_attributes) do if link? link_to(text, href, class: "#{brand}-header__link", **) else text end end end |
#link? ⇒ Boolean
87 88 89 |
# File 'app/components/govuk_component/header_component.rb', line 87 def link? href.present? end |