Class: CCS::Components::GovUK::Hint

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

Overview

GOV.UK Hint

This is used to generate the hint text component from the Government Design Systems

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the hint

{ class: 'govuk-hint' }.freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Hint.

Parameters:

  • text (String) (defaults to: nil)

    the hint text. 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 hint HTML

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML



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

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

  @text = text
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Hint component

Returns:

  • (ActiveSupport::SafeBuffer)


37
38
39
40
41
# File 'lib/ccs/components/govuk/hint.rb', line 37

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