Sha256: d9f17668ac6dcc8824438c8cb75576704241733d34f5d7ef7ff7899e962dec8e

Contents?: true

Size: 1.4 KB

Versions: 39

Compression:

Stored size: 1.4 KB

Contents

module GOVUKDesignSystemFormBuilder
  module Containers
    class Fieldset < Base
      include Traits::HTMLAttributes

      def initialize(builder, object_name = nil, attribute_name = nil, legend: {}, caption: {}, described_by: nil, **kwargs, &block)
        super(builder, object_name, attribute_name, &block)

        @legend          = legend
        @caption         = caption
        @described_by    = combine_references(described_by)
        @attribute_name  = attribute_name
        @html_attributes = kwargs
      end

      def html
        tag.fieldset(**attributes(@html_attributes)) do
          safe_join([legend_element, (@block_content || yield)])
        end
      end

    private

      def options
        {
          class: classes,
          aria: { describedby: [@described_by] }
        }
      end

      def classes
        [%(#{brand}-fieldset)]
      end

      def legend_element
        @legend_element ||= if @legend.nil?
                              Elements::Null.new
                            else
                              Elements::Legend.new(*bound, **legend_options)
                            end
      end

      def legend_options
        case @legend
        when Hash
          @legend.merge(caption: @caption)
        when Proc
          { content: @legend }
        else
          fail(ArgumentError, %(legend must be a Proc or Hash))
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 2 rubygems

Version Path
govuk_design_system_formbuilder-5.8.0 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.7.1 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.7.0 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.6.0 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.5.0 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.4.1 lib/govuk_design_system_formbuilder/containers/fieldset.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/govuk_design_system_formbuilder-5.4.0/lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.3.3 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.3.2 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.3.1 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.3.0 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.2.0 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.1.0 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.1.0b1 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.0.0 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-5.0.0b1 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-4.1.1 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-4.1.0 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-4.0.0 lib/govuk_design_system_formbuilder/containers/fieldset.rb
govuk_design_system_formbuilder-4.0.0rc1 lib/govuk_design_system_formbuilder/containers/fieldset.rb