Sha256: aeedcbabdac80927bbdc267be56558565aafa54f2ab63b2270e17ad38735d2b5

Contents?: true

Size: 1.01 KB

Versions: 9

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

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

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

          super(**system_arguments)

          add_label_classes("FormControl-label", "mb-2")

          yield(self) if block_given?
        end

        def to_component
          CheckBoxGroup.new(input: self)
        end

        def name
          nil
        end

        def type
          :check_box_group
        end

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

          @check_boxes << CheckBoxInput.new(**args)
        end

        private

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
primer_view_components-0.0.103 lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.0.102 lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.0.101 lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.0.100 lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.0.99 lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.0.98 lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.0.97 lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.0.96 lib/primer/forms/dsl/check_box_group_input.rb
primer_view_components-0.0.95 lib/primer/forms/dsl/check_box_group_input.rb