Class: CCS::Components::GovUK::PhaseBanner

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

Overview

GOV.UK Phase banner

This is used to generate the phase banner component from the GDS - Components - Phase banner

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the phase banner

{ class: 'govuk-phase-banner' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(tag_options:, text: nil, **options) ⇒ PhaseBanner

Returns a new instance of PhaseBanner.

Parameters:

  • tag_options (Hash)

    paramters for the govuk tag (see Tag). options are:

    • text

    • colour

    • options

  • text (String) (defaults to: nil)

    the text for the phase banner. If nil, then a block will be rendered

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the phase banner HTML

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML



36
37
38
39
40
41
42
43
44
# File 'lib/ccs/components/govuk/phase_banner.rb', line 36

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

  tag_options[:classes] = "govuk-phase-banner__content__tag #{tag_options[:classes]}".rstrip
  tag_options[:context] = @context

  @text = text
  @tag_options = tag_options
end

Instance Method Details

#render { ... } ⇒ ActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Phase banner component

Yields:

  • HTML that will be used in the phase banner. Ignored if text is passed.

Returns:

  • (ActiveSupport::SafeBuffer)


52
53
54
55
56
57
58
59
60
61
# File 'lib/ccs/components/govuk/phase_banner.rb', line 52

def render
  tag.div(**options[:attributes]) do
    tag.p(class: 'govuk-phase-banner__content') do
      concat(Tag.new(**tag_options).render)
      concat(tag.span(class: 'govuk-phase-banner__text') do
        text || yield
      end)
    end
  end
end