Sha256: 82bd2c450f9b0e4e16a09475626a370c58118d2fc346a4156e87c432f08849af

Contents?: true

Size: 1.32 KB

Versions: 51

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

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

        # :nodoc:
        class Option
          attr_reader :label, :value, :system_arguments

          def initialize(label:, value:, **system_arguments)
            @label = label
            @value = value
            @system_arguments = 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 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

51 entries across 51 versions & 2 rubygems

Version Path
primer_view_components-0.1.8 lib/primer/forms/dsl/select_input.rb
primer_view_components-0.1.7 lib/primer/forms/dsl/select_input.rb
primer_view_components-0.1.6 lib/primer/forms/dsl/select_input.rb
primer_view_components-0.1.5 lib/primer/forms/dsl/select_input.rb
primer_view_components-0.1.4 lib/primer/forms/dsl/select_input.rb
primer_view_components-0.1.3 lib/primer/forms/dsl/select_input.rb
primer_view_components-0.1.2 lib/primer/forms/dsl/select_input.rb
primer_view_components-0.1.1 lib/primer/forms/dsl/select_input.rb
primer_view_components-0.1.0 lib/primer/forms/dsl/select_input.rb
primer_view_components-0.0.123 lib/primer/forms/dsl/select_input.rb
primer_view_components-0.0.122 lib/primer/forms/dsl/select_input.rb