Sha256: 243fb67b397249cb84deb38246690b7c4d8893c970372b33e2a9fc23eb79e2d3

Contents?: true

Size: 1.09 KB

Versions: 67

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Primer
  module Forms
    module Dsl
      # :nodoc:
      class CheckBoxGroupInput < Input
        attr_reader :name, :label, :check_boxes

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

          super(**system_arguments)

          yield(self) if block_given?
        end

        def to_component
          CheckBoxGroup.new(input: self)
        end

        def type
          :check_box_group
        end

        def focusable?
          true
        end

        def autofocus!
          @check_boxes.first&.autofocus!
        end

        def check_box(**system_arguments, &block)
          args = {
            name: @name,
            builder: @builder,
            form: @form,
            scheme: scheme,
            disabled: disabled?,
            **system_arguments
          }

          @check_boxes << CheckBoxInput.new(**args, &block)
        end

        private

        def scheme
          @name ? :array : :boolean
        end
      end
    end
  end
end

Version data entries

67 entries across 67 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.49.2 app/lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.35.2 app/lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.49.1 app/lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.49.0 app/lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.35.1 app/lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.35.0 app/lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.48.2 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.48.1 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.48.0 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.47.1 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.47.0 lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.34.0 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.46.1 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.46.0 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.45.0 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.44.3 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.44.2 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.44.1 lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.33.0 lib/primer/forms/dsl/check_box_group_input.rb
openproject-primer_view_components-0.44.0 lib/primer/forms/dsl/check_box_group_input.rb