Sha256: 579374e702f17d3ef1f25c65a0b4336ebc440ae6075dd134a2c26b46ae46718e

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module GOVUKDesignSystemFormBuilder
  module Elements
    class File < GOVUKDesignSystemFormBuilder::Base
      def initialize(builder, object_name, attribute_name, hint_text:, label:, **extra_args)
        super(builder, object_name, attribute_name)

        @label      = label
        @hint_text  = hint_text
        @extra_args = extra_args
      end

      def html
        Containers::FormGroup.new(@builder, @object_name, @attribute_name).html do
          @builder.safe_join(
            [
              label_element.html,
              hint_element.html,
              error_element.html,
              @builder.file_field(
                @attribute_name,
                id: field_id(link_errors: true),
                class: file_classes,
                aria: { describedby: described_by(hint_element.hint_id, error_element.error_id) },
                **@extra_args
              )
            ]
          )
        end
      end

    private

      def file_classes
        %w(govuk-file-upload).tap do |c|
          c.push('govuk-file-upload--error') if has_errors?
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-0.9.2 lib/govuk_design_system_formbuilder/elements/file.rb
govuk_design_system_formbuilder-0.9.1 lib/govuk_design_system_formbuilder/elements/file.rb
govuk_design_system_formbuilder-0.9.0 lib/govuk_design_system_formbuilder/elements/file.rb
govuk_design_system_formbuilder-0.7.10 lib/govuk_design_system_formbuilder/elements/file.rb