Sha256: 3eb0071db0c736620f0307b2c700e9f31fdeba672d522b30ccbc4a4b28cd9333

Contents?: true

Size: 1.48 KB

Versions: 79

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module Primer
  module Forms
    module Dsl
      # :nodoc:
      class SelectInput < Input
        SELECT_ARGUMENTS = %i[multiple include_blank include_hidden prompt].freeze

        # :nodoc:
        class Option
          include Primer::TestSelectorHelper

          attr_reader :label, :value, :system_arguments

          def initialize(label:, value:, **system_arguments)
            @label = label
            @value = value
            @system_arguments = add_test_selector(system_arguments)
          end
        end

        attr_reader :name, :label, :options, :select_arguments

        def initialize(name:, label:, **system_arguments)
          @name = name
          @label = label
          @options = []

          @select_arguments = {}.tap do |select_args|
            SELECT_ARGUMENTS.each do |select_arg|
              select_args[select_arg] = system_arguments.delete(select_arg)
            end
          end

          super(**system_arguments)

          yield(self) if block_given?
        end

        def multiple?
          @select_arguments.fetch(:multiple, false)
        end

        def option(**system_arguments)
          @options << Option.new(**system_arguments)
        end

        def to_component
          Select.new(input: self)
        end

        # :nocov:
        def type
          :select_list
        end
        # :nocov:

        # :nocov:
        def focusable?
          true
        end
        # :nocov:
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 2 rubygems

Version Path
primer_view_components-0.36.5 app/lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.52.2 app/lib/primer/forms/dsl/select_input.rb
primer_view_components-0.36.4 app/lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.52.1 app/lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.52.0 app/lib/primer/forms/dsl/select_input.rb
primer_view_components-0.36.3 app/lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.51.0 app/lib/primer/forms/dsl/select_input.rb
primer_view_components-0.36.2 app/lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.50.1 app/lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.50.0 app/lib/primer/forms/dsl/select_input.rb
primer_view_components-0.36.1 app/lib/primer/forms/dsl/select_input.rb
primer_view_components-0.36.0 app/lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.49.2 app/lib/primer/forms/dsl/select_input.rb
primer_view_components-0.35.2 app/lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.49.1 app/lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.49.0 app/lib/primer/forms/dsl/select_input.rb
primer_view_components-0.35.1 app/lib/primer/forms/dsl/select_input.rb
primer_view_components-0.35.0 app/lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.48.2 lib/primer/forms/dsl/select_input.rb
openproject-primer_view_components-0.48.1 lib/primer/forms/dsl/select_input.rb