Sha256: 852d933d0ed48220de044127602227453c7badd0e6f13b21c6b5cc87efbf0ea8

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Yattho
  module Forms
    module Dsl
      # :nodoc:
      class SelectListInput < 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
          SelectList.new(input: self)
        end

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yattho_view_components-0.1.1 lib/yattho/forms/dsl/select_list_input.rb
yattho_view_components-0.0.1 lib/yattho/forms/dsl/select_list_input.rb