Class: CCS::Components::GovUK::ExitThisPage

Inherits:
Base
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers
Defined in:
lib/ccs/components/govuk/exit_this_page.rb

Overview

GOV.UK Exit this page

This is used to generate the exit this page component from the GDS - Components - Exit this page

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the exit this page

{ class: 'govuk-exit-this-page', data: { module: 'govuk-exit-this-page' } }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(text: nil, redirect_url: nil, **options) ⇒ ExitThisPage

Returns a new instance of ExitThisPage.

Parameters:

  • text (String) (defaults to: nil)

    the text for the exit this page

  • redirect_url (String) (defaults to: nil)

    the href for the exit this page

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the exit this page HTML

  • :activated_text (String)

    Text announced by screen readers when Exit this Page has been activated via the keyboard shortcut. Defaults to “Loading.”

  • :timed_out_text (String)

    Text announced by screen readers when the keyboard shortcut has timed out without successful activation. Defaults to “Exit this page expired.”

  • :press_two_more_times_text (String)

    Text announced by screen readers when the user must press Shift two more times to activate the button. Defaults to “Shift, press 2 more times to exit.”

  • :press_one_more_time_text (String)

    Text announced by screen readers when the user must press Shift one more time to activate the button. Defaults to “Shift, press 1 more time to exit.”

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ccs/components/govuk/exit_this_page.rb', line 38

def initialize(text: nil, redirect_url: nil, **options)
  super(**options)

  @text = text || default_text
  @redirect_url = redirect_url || 'https://www.bbc.co.uk/weather'

  %i[activated timed_out press_two_more_times press_one_more_time].each do |data_attribute|
    data_attribute_name = :"#{data_attribute}_text"
    @options[:attributes][:data][:"i18n.#{data_attribute.to_s.gsub('_', '-')}"] = options[data_attribute_name] if options[data_attribute_name]
  end
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Exit this page component

Returns:

  • (ActiveSupport::SafeBuffer)


54
55
56
57
58
# File 'lib/ccs/components/govuk/exit_this_page.rb', line 54

def render
  tag.div(**options[:attributes]) do
    Button.new(text: text, href: redirect_url, context: context, classes: 'govuk-button--warning govuk-exit-this-page__button govuk-js-exit-this-page-button', attributes: { rel: 'nofollow noreferrer' }).render
  end
end