Sha256: 9c6763ec12eec4d39b67c269319e9f997d435152ef4a68c2f7238daa4635fa83

Contents?: true

Size: 1.64 KB

Versions: 12

Compression:

Stored size: 1.64 KB

Contents

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

module CCS
  module 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 if block_given?
          end
        end

        # The default attributes for the fieldset

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ccs-frontend_helpers-2.1.0 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-2.0.0 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-1.2.0 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-1.1.2 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-1.1.1 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-1.1.0 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-1.1.0.beta0 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-1.0.0 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-0.5.0.beta1 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-0.5.0.beta0 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-0.3.0 lib/ccs/components/govuk/fieldset.rb
ccs-frontend_helpers-0.2.0 lib/ccs/components/govuk/fieldset.rb