Class: CCS::Components::GovUK::Breadcrumbs

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

Overview

GOV.UK Breadcrumbs

This is used to generate the breadcrumbs component from the GDS - Components - Breadcrumbs

Defined Under Namespace

Classes: Link

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the breadcrumbs

{ class: 'govuk-breadcrumbs' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(breadcrumb_links:, **options) ⇒ Breadcrumbs

Returns a new instance of Breadcrumbs.

Parameters:

  • breadcrumb_links (Array<Hash>)

    An array of links for the breadcrumbs list. See Link#initialize for details of the items in the array.

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the breadcrumbs HTML

  • :collapse_on_mobile (Boolean)

    indicates if it is to colapse breadcrumbs on mobile

  • :attributes (Hash)

    any additional attributes that will added as part of the HTML



30
31
32
33
34
35
36
# File 'lib/ccs/components/govuk/breadcrumbs.rb', line 30

def initialize(breadcrumb_links:, **options)
  super(**options)
  @options[:attributes][:class] << ' govuk-breadcrumbs--collapse-on-mobile' if @options[:collapse_on_mobile]
  (@options[:attributes][:aria] ||= {})[:label] ||= 'Breadcrumb'

  @breadcrumb_links = breadcrumb_links.map { |breadcrumb_link| Link.new(context: @context, **breadcrumb_link) }
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK breadcrumbs component

Returns:

  • (ActiveSupport::SafeBuffer)


42
43
44
45
46
47
48
# File 'lib/ccs/components/govuk/breadcrumbs.rb', line 42

def render
  tag.nav(**options[:attributes]) do
    tag.ol(class: 'govuk-breadcrumbs__list') do
      breadcrumb_links.each { |breadcrumb_link| concat(breadcrumb_link.render) }
    end
  end
end