Class: CCS::Components::GovUK::Tag

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

Overview

GOV.UK Tag

This is used to generate the tag component from the GDS - Components - Tag

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the tag

{ class: 'govuk-tag' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(text:, colour: nil, **options) ⇒ Tag

Returns a new instance of Tag.

Parameters:

  • text (String)

    the text for the tag

  • colour (String) (defaults to: nil)

    optional colour for the tag, see Tag - Additional colours for available colours in GOV.UK Frontend

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the tag HTML

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML



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

def initialize(text:, colour: nil, **options)
  super(**options)
  @options[:attributes][:class][..8] = "govuk-tag govuk-tag--#{colour}" if colour

  @text = text
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Tag component

Returns:

  • (ActiveSupport::SafeBuffer)


41
42
43
# File 'lib/ccs/components/govuk/tag.rb', line 41

def render
  tag.strong(text, **options[:attributes])
end