app/pb_kits/playbook/pb_form/form_builder/checkbox_field.rb



# frozen_string_literal: true

module Playbook
  module PbForm
    module FormBuilder
      module CheckboxField
        def check_box(name, data: {}, props: {})
          value = props[:value] ||= 1
          input = super(name, { required: props[:required], data: data }, value)
          label_text = name.to_s.gsub("_", " ")

          props[:margin_bottom] = "sm"
          props[:form_spacing] = true

          # Refactor and dry up, solve adding nil error
          if props[:label]
            @template.pb_rails("caption", props: { text: label_text, margin_bottom: "xs" }) +
              @template.pb_rails("checkbox", props: props) do
                input
              end
          else
            @template.pb_rails("checkbox", props: props) do
              input
            end
          end
        end
      end
    end
  end
end