Class: CCS::Components::GovUK::Header

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/header.rb,
lib/ccs/components/govuk/header/link.rb,
lib/ccs/components/govuk/header/navigation.rb

Overview

GOV.UK Header

This is used to generate the header component from the GDS - Components - Header

Defined Under Namespace

Classes: Link, Navigation

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the breadcrumbs

{ class: 'govuk-header', data: { module: 'govuk-header' } }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(navigation: nil, menu_button: nil, service: nil) ⇒ Header

Returns a new instance of Header.

Parameters:

  • navigation (Hash) (defaults to: nil)

    options for the navigation section of the header. See Navigation#initialize for details of the options.

  • menu_button (Hash) (defaults to: nil)

    options for the menu button in the header. See Navigation#initialize for details of the options.

  • service (Hash) (defaults to: nil)

    options for the service name

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (service:):

  • :name (String)

    the name of the service, included in the header

  • :href (String)

    URL for the service name anchor



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ccs/components/govuk/header.rb', line 45

def initialize(navigation: nil, menu_button: nil, service: nil, **)
  super(**)

  @options[:container_classes] ||= 'govuk-width-container'
  @options[:homepage_url] ||= '/'
  @options[:use_tudor_crown] = true if @options[:use_tudor_crown].nil?

  @logo = Logo.new(rebrand: @options[:rebrand], use_tudor_crown: @options[:use_tudor_crown], classes: 'govuk-header__logotype', attributes: { aria: { label: 'GOV.UK' } }, context: @context)
  @navigation = Navigation.new(navigation: navigation, menu_button: menu_button, context: @context) if navigation && navigation[:items].present?
  @service = service
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Header component

Returns:

  • (ActiveSupport::SafeBuffer)


61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ccs/components/govuk/header.rb', line 61

def render
  tag.header(**options[:attributes]) do
    tag.div(class: "govuk-header__container #{options[:container_classes]}") do
      concat()
      if service || navigation
        concat(tag.div(class: 'govuk-header__content') do
          concat(header_service_name) if service
          concat(navigation.render) if navigation
        end)
      end
    end
  end
end