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

Methods inherited from Base

#brand, #class_prefix

Constructor Details

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

Returns a new instance of NavigationItem.



62
63
64
65
66
67
68
69
# File 'app/components/govuk_component/header_component.rb', line 62

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

  super(classes:, html_attributes:)
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



60
61
62
# File 'app/components/govuk_component/header_component.rb', line 60

def active
  @active
end

#hrefObject (readonly)

Returns the value of attribute href.



60
61
62
# File 'app/components/govuk_component/header_component.rb', line 60

def href
  @href
end

#optionsObject (readonly)

Returns the value of attribute options.



60
61
62
# File 'app/components/govuk_component/header_component.rb', line 60

def options
  @options
end

#textObject (readonly)

Returns the value of attribute text.



60
61
62
# File 'app/components/govuk_component/header_component.rb', line 60

def text
  @text
end

Instance Method Details

#active_classObject



77
78
79
# File 'app/components/govuk_component/header_component.rb', line 77

def active_class
  ["#{brand}-header__navigation-item--active"] if active?
end

#before_renderObject



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

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

#callObject



85
86
87
88
89
90
91
92
93
# File 'app/components/govuk_component/header_component.rb', line 85

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

#link?Boolean

Returns:

  • (Boolean)


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

def link?
  href.present?
end