Sha256: aac1d6db5068a3bb546aa24ea583a0f558eed24500a9e0de4a01e990aa6f9dff

Contents?: true

Size: 1.53 KB

Versions: 27

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Primer
  module Forms
    # :nodoc:
    class SubmitButton < BaseComponent
      # :nodoc:
      module SubmitAttributeGenerator
        extend ActionView::Helpers::FormTagHelper

        class << self
          alias submit_tag_attributes submit_tag

          private

          # FormTagHelper#submit_tag ultimately calls the #tag method. We return the options hash here instead
          # of returning a string so it can be merged into the hash of options we pass to the Primer::ButtonComponent.
          def tag(_name, options)
            options
          end
        end
      end

      delegate :builder, :form, to: :@input

      def initialize(input:)
        @input = input
        @input.add_input_classes("FormField-input flex-self-start")
        @input.merge_input_arguments!(
          SubmitAttributeGenerator.submit_tag_attributes(input.label, name: input.name).deep_symbolize_keys
        )

        # rails uses a string for this, but PVC wants a symbol
        @input.merge_input_arguments!(type: :submit)

        # Never disable submit buttons. This overrides the global
        # ActionView::Base.automatically_disable_submit_tag setting.
        # Disabling the submit button is not accessible.
        @input.remove_input_data(:disable_with)
      end

      def input_arguments
        @input_arguments ||= @input.input_arguments.deep_dup.tap do |args|
          # rails uses :class but PVC wants :classes
          args[:classes] = args.delete(:class)
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
primer_view_components-0.0.112 lib/primer/forms/submit_button.rb
primer_view_components-0.0.111 lib/primer/forms/submit_button.rb
primer_view_components-0.0.110 lib/primer/forms/submit_button.rb
primer_view_components-0.0.109 lib/primer/forms/submit_button.rb
primer_view_components-0.0.108 lib/primer/forms/submit_button.rb
primer_view_components-0.0.107 lib/primer/forms/submit_button.rb
primer_view_components-0.0.106 lib/primer/forms/submit_button.rb
primer_view_components-0.0.105 lib/primer/forms/submit_button.rb
primer_view_components-0.0.104 lib/primer/forms/submit_button.rb
primer_view_components-0.0.103 lib/primer/forms/submit_button.rb
primer_view_components-0.0.102 lib/primer/forms/submit_button.rb
primer_view_components-0.0.101 lib/primer/forms/submit_button.rb
primer_view_components-0.0.100 lib/primer/forms/submit_button.rb
primer_view_components-0.0.99 lib/primer/forms/submit_button.rb
primer_view_components-0.0.98 lib/primer/forms/submit_button.rb
primer_view_components-0.0.97 lib/primer/forms/submit_button.rb
primer_view_components-0.0.96 lib/primer/forms/submit_button.rb
primer_view_components-0.0.95 lib/primer/forms/submit_button.rb
primer_view_components-0.0.94 lib/primer/forms/submit_button.rb
primer_view_components-0.0.93 lib/primer/forms/submit_button.rb