Class: CCS::Components::GovUK::Fieldset

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

Overview

GOV.UK Fieldset

This is used to generate the fieldset component from the GDS - Components - Fieldset

Defined Under Namespace

Classes: Legend

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the fieldset

{ class: 'govuk-fieldset' }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(legend: nil, **options) ⇒ Fieldset

Returns a new instance of Fieldset.

Parameters:

  • legend (Hash) (defaults to: nil)

    options for the fieldset legend. See Legend#initialize for details of the options.

  • options (Hash)

    options that will be used in customising the HTML

Options Hash (**options):

  • :classes (String)

    additional CSS classes for the fieldset HTML

  • :attributes (Hash) — default: {}

    any additional attributes that will added as part of the HTML



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

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

  @legend = Legend.new(context: @context, **legend) if legend
end

Instance Method Details

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

Generates the HTML for the GOV.UK Fieldset component

Yields:

  • HTML that will be contained within the ‘govuk-fieldset’ div and under the legend

Returns:

  • (ActiveSupport::SafeBuffer)


41
42
43
44
45
46
# File 'lib/ccs/components/govuk/fieldset.rb', line 41

def render
  tag.fieldset(**options[:attributes]) do
    concat(legend.render) if legend
    yield if block_given?
  end
end