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, **options) ⇒ 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

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the header HTML

  • :container_classes (String)

    classes for the container

  • :homepage_url (String)

    URL of the homepage. Defaults to /

  • :product_name (String)

    product name, used when the product name follows on directly from ‘GOV.UK

  • :use_tudor_crown (Boolean)

    flag to use the new tudor crown for the GOV.UK Logo

  • :attributes (Hash)

    additional attributes that will added as part of the header HTML



41
42
43
44
45
46
47
48
49
50
# File 'lib/ccs/components/govuk/header.rb', line 41

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

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

  @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)


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ccs/components/govuk/header.rb', line 56

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