Class: CCS::Components::GovUK::StepByStepNavigation

Inherits:
Base
  • Object
show all
Defined in:
lib/ccs/components/govuk/step_by_step_navigation.rb,
lib/ccs/components/govuk/step_by_step_navigation/section.rb,
lib/ccs/components/govuk/step_by_step_navigation/section/content.rb,
lib/ccs/components/govuk/step_by_step_navigation/section/heading.rb,
lib/ccs/components/govuk/step_by_step_navigation/section/content/list.rb,
lib/ccs/components/govuk/step_by_step_navigation/section/content/list/item.rb,
lib/ccs/components/govuk/step_by_step_navigation/section/content/paragraph.rb

Overview

GOV.UK Step by step navigation

This is used for generating the Step by step navigation component from the / GDS - Pages - Step by step navigation

Defined Under Namespace

Classes: Section

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the step byt step navigation

{ class: 'gem-c-step-nav gem-c-step-nav--large gem-c-step-nav--active', data: { module: 'govuk-step-by-step-navigation' } }.freeze
DEFAULT_SHOW_HIDE_TEXT =

Default text for the show and hide buttons which are part of each section

{ 'show-text': 'Show', 'hide-text': 'Hide', 'show-all-text': 'Show all', 'hide-all-text': 'Hide all' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(step_by_step_navigation_sections:, **options) ⇒ StepByStepNavigation

Returns a new instance of StepByStepNavigation.

Parameters:

  • step_by_step_navigation_sections (Array<Hash>)

    An array of options for the step by step navigation section. See Section#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 step by step navigation HTML

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML



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

def initialize(step_by_step_navigation_sections:, **options)
  super(**options)

  DEFAULT_SHOW_HIDE_TEXT.each { |key, value| @options[:attributes][:data][key] ||= value }

  @step_by_step_navigation_sections = step_by_step_navigation_sections.map.with_index(1) { |step_by_step_section, index| Section.new(index: index.to_s, context: @context, **step_by_step_section) }
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Step by step navigation component (experimental)

Returns:

  • (ActiveSupport::SafeBuffer)


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

def render
  tag.div(**options[:attributes]) do
    tag.ol(class: 'gem-c-step-nav__steps') do
      step_by_step_navigation_sections.each { |step_by_step_navigation_section| concat(step_by_step_navigation_section.render) }
    end
  end
end