Sha256: 752c26a50acb05787d7c7fbcb159989862398faeb478007a69e9907cab764856

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbCheckbox
    class Checkbox
      include Playbook::Props
      include ActionView::Helpers::FormTagHelper
      include ActionView::Context

      partial "pb_checkbox/checkbox"

      prop :error, type: Playbook::Props::Boolean, default: false
      prop :checked, type: Playbook::Props::Boolean, default: false
      prop :text
      prop :value
      prop :name
      prop :input_options, type: Playbook::Props::Hash,
                           default: {}
      prop :required, type: Playbook::Props::Boolean,
                      default: false
      prop :form_spacing, type: Playbook::Props::Boolean,
                          default: false

      def checked_html
        checked ? "checked='true'" : nil
      end

      def classname
        generate_classname("pb_checkbox_kit", checked_class) + error_class
      end

      def input
        check_box_tag(name, value, checked, input_options)
      end

      def for_attribute
        input_options[:id]
      end

      def checkbox_label_status
        error ? "negative" : nil
      end

    private

      def error_class
        error ? " error" : ""
      end

      def checked_class
        checked ? "on" : "off"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
playbook_ui-7.4.0.pre.alpha6 app/pb_kits/playbook/pb_checkbox/checkbox.rb
playbook_ui-7.4.0.pre.alpha4 app/pb_kits/playbook/pb_checkbox/checkbox.rb