Class: CCS::Components::GovUK::InsetText

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

Overview

GOV.UK Inset Text

This is used to generate the inset text component from the GDS - Components - Inset text

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the inset text

{ class: 'govuk-inset-text' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(text: nil, **options) ⇒ InsetText

Returns a new instance of InsetText.

Parameters:

  • text (String) (defaults to: nil)

    text to use within the inset text component. 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 inset text HTML

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML



28
29
30
31
32
# File 'lib/ccs/components/govuk/inset_text.rb', line 28

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

  @text = text
end

Instance Method Details

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

Generates the HTML for the GOV.UK Inset text component

Yields:

  • HTML that will be contained within the inset text div. Ignored if inset text is given

Returns:

  • (ActiveSupport::SafeBuffer)


40
41
42
43
44
# File 'lib/ccs/components/govuk/inset_text.rb', line 40

def render
  tag.div(**options[:attributes]) do
    text || yield
  end
end