Sha256: cb259c6787f986fb3f9f291d51cf0652c5005ffb38ad5ffbd11981e8766ad615

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require_relative '../base'
require_relative 'fieldset/legend'

module CCS::Components
  module GovUK
    # = GOV.UK Fieldset
    #
    # This is used to generate the fieldset component from the
    # {https://design-system.service.gov.uk/components/fieldset GDS - Components - Fieldset}
    #
    # @!attribute [r] legend
    #   @return [Legend] Initialised fieldset legend

    class Fieldset < Base
      private

      attr_reader :legend

      public

      # @param legend [Hash] options for the fieldset legend.
      #                      See {Components::GovUK::Fieldset::Legend#initialize Legend#initialize} for details of the options.
      # @param options [Hash] options that will be used in customising the HTML
      #
      # @option options [String] :classes additional CSS classes for the fieldset HTML
      # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML

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

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

      # Generates the HTML for the GOV.UK Fieldset component
      #
      # @yield HTML that will be contained within the 'govuk-fieldset' div and under the legend
      #
      # @return [ActiveSupport::SafeBuffer]

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

      # The default attributes for the fieldset

      DEFAULT_ATTRIBUTES = { class: 'govuk-fieldset' }.freeze
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ccs-frontend_helpers-0.1.0.rc.2 lib/ccs/components/govuk/fieldset.rb