Class: GovukComponent::HeaderComponent::NavigationItem

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

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Constructor Details

#initialize(text:, href: nil, options: {}, active: nil, classes: [], html_attributes: {}) ⇒ NavigationItem

Returns a new instance of NavigationItem.



71
72
73
74
75
76
77
78
# File 'app/components/govuk_component/header_component.rb', line 71

def initialize(text:, href: nil, options: {}, active: nil, classes: [], html_attributes: {})
  @text            = text
  @href            = href
  @options         = options
  @active_override = active

  super(classes: classes, html_attributes: html_attributes)
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



69
70
71
# File 'app/components/govuk_component/header_component.rb', line 69

def active
  @active
end

#hrefObject (readonly)

Returns the value of attribute href.



69
70
71
# File 'app/components/govuk_component/header_component.rb', line 69

def href
  @href
end

#optionsObject (readonly)

Returns the value of attribute options.



69
70
71
# File 'app/components/govuk_component/header_component.rb', line 69

def options
  @options
end

#textObject (readonly)

Returns the value of attribute text.



69
70
71
# File 'app/components/govuk_component/header_component.rb', line 69

def text
  @text
end

Instance Method Details

#active_classObject



86
87
88
# File 'app/components/govuk_component/header_component.rb', line 86

def active_class
  %w(govuk-header__navigation-item--active) if active?
end

#before_renderObject



80
81
82
83
84
# File 'app/components/govuk_component/header_component.rb', line 80

def before_render
  if active?
    html_attributes[:class] << active_class
  end
end

#callObject



94
95
96
97
98
99
100
101
102
# File 'app/components/govuk_component/header_component.rb', line 94

def call
  tag.li(**html_attributes) do
    if link?
      link_to(text, href, class: "govuk-header__link", **options)
    else
      text
    end
  end
end

#link?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/components/govuk_component/header_component.rb', line 90

def link?
  href.present?
end