Sha256: 9a651765f1514c087ed08cd4a7f6b92cc2db4d634f18fc131df1671f2cd22c5f

Contents?: true

Size: 1.08 KB

Versions: 149

Compression:

Stored size: 1.08 KB

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

      def nested_form_arguments
        return @nested_form_arguments if defined?(@nested_form_arguments)

        @nested_form_arguments = { hidden: @input.hidden?, **@input.nested_form_arguments }
        @nested_form_arguments[:class] = class_names(
          @nested_form_arguments[:class],
          @nested_form_arguments.delete(:classes),
          "ml-4"
        )

        @nested_form_arguments
      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

149 entries across 149 versions & 2 rubygems

Version Path
openproject-primer_view_components-0.6.3 lib/primer/forms/check_box.rb
primer_view_components-0.6.0 lib/primer/forms/check_box.rb
primer_view_components-0.5.1 lib/primer/forms/check_box.rb
primer_view_components-0.5.0 lib/primer/forms/check_box.rb
primer_view_components-0.4.0 lib/primer/forms/check_box.rb
primer_view_components-0.3.1 lib/primer/forms/check_box.rb
primer_view_components-0.3.0 lib/primer/forms/check_box.rb
primer_view_components-0.2.0 lib/primer/forms/check_box.rb
primer_view_components-0.1.9 lib/primer/forms/check_box.rb
primer_view_components-0.1.8 lib/primer/forms/check_box.rb
primer_view_components-0.1.7 lib/primer/forms/check_box.rb
primer_view_components-0.1.6 lib/primer/forms/check_box.rb
primer_view_components-0.1.5 lib/primer/forms/check_box.rb
primer_view_components-0.1.4 lib/primer/forms/check_box.rb
primer_view_components-0.1.3 lib/primer/forms/check_box.rb
primer_view_components-0.1.2 lib/primer/forms/check_box.rb
primer_view_components-0.1.1 lib/primer/forms/check_box.rb
primer_view_components-0.1.0 lib/primer/forms/check_box.rb
primer_view_components-0.0.123 lib/primer/forms/check_box.rb
primer_view_components-0.0.122 lib/primer/forms/check_box.rb