Sha256: ca5eb81f8ad164740a225ea21649e38479b85a4238bd3d24298aa2bd6de2a1cb

Contents?: true

Size: 693 Bytes

Versions: 3

Compression:

Stored size: 693 Bytes

Contents

# frozen_string_literal: true

module Primer
  module Forms
    # :nodoc:
    class CheckBox < BaseComponent
      delegate :builder, :form, to: :@input

      def initialize(input:)
        @input = input
        @input.add_label_classes("FormControl-label")
        @input.add_input_classes("FormControl-checkbox")

        return unless @input.scheme == :array

        @input.input_arguments[:multiple] = true
        @input.label_arguments[:value] = checked_value
      end

      private

      def checked_value
        @input.value || "1"
      end

      def unchecked_value
        return if @input.scheme == :array

        @input.unchecked_value || "0"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
primer_view_components-0.0.103 lib/primer/forms/check_box.rb
primer_view_components-0.0.102 lib/primer/forms/check_box.rb
primer_view_components-0.0.101 lib/primer/forms/check_box.rb