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

Attributes included from Traits::CustomHtmlAttributes

#html_attributes

Instance Method Summary collapse

Methods included from Traits::CustomClasses

#classes

Methods included from Govuk::Components::Helpers::CssUtilities

#combine_classes

Constructor Details

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

Returns a new instance of NavigationItem.



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

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

  @text    = text
  @href    = href
  @options = options

  @active_override = active
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



67
68
69
# File 'app/components/govuk_component/header_component.rb', line 67

def active
  @active
end

#hrefObject (readonly)

Returns the value of attribute href.



67
68
69
# File 'app/components/govuk_component/header_component.rb', line 67

def href
  @href
end

#optionsObject (readonly)

Returns the value of attribute options.



67
68
69
# File 'app/components/govuk_component/header_component.rb', line 67

def options
  @options
end

#textObject (readonly)

Returns the value of attribute text.



67
68
69
# File 'app/components/govuk_component/header_component.rb', line 67

def text
  @text
end

Instance Method Details

#active_classObject



83
84
85
# File 'app/components/govuk_component/header_component.rb', line 83

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

#before_renderObject



79
80
81
# File 'app/components/govuk_component/header_component.rb', line 79

def before_render
  @active = active?(@active_override)
end

#callObject



91
92
93
94
95
96
97
98
99
# File 'app/components/govuk_component/header_component.rb', line 91

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

#link?Boolean

Returns:

  • (Boolean)


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

def link?
  href.present?
end