Sha256: 6a0d0056d5c1353157254c00df8a41b5528acca072bff29b6560e75adb4653b7

Contents?: true

Size: 1.49 KB

Versions: 43

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require "action_view"

module Playbook
  module PbSelect
    class Select < Playbook::KitBase
      prop :blank_selection
      prop :disabled, type: Playbook::Props::Boolean, default: false
      prop :error
      prop :include_blank
      prop :label
      prop :multiple, type: Playbook::Props::Boolean, default: false
      prop :name
      prop :onchange
      prop :options, type: Playbook::Props::HashArray, required: false, default: []
      prop :required, type: Playbook::Props::Boolean, default: false

      def classname
        generate_classname("pb_select", select_margin_bottom, separator: " ")
      end

      def select_wrapper_class
        "pb_select_kit_wrapper" + error_class
      end

      def select_margin_bottom
        margin.present? || margin_bottom.present? ? nil : "mb_sm"
      end

      def options_to_array
        options.map { |option| [option[:value_text] || option[:value], option[:value]] }
      end

      def selected
        selections = options.map { |option| option[:value] if option[:selected] == true }.compact
        if selections.empty?
          nil
        else
          selections
        end
      end

      def disabled_options
        disabled_options = options.map { |option| option[:value] if option[:disabled] == true }.compact
        if disabled_options.empty?
          nil
        else
          disabled_options
        end
      end

    private

      def error_class
        error ? " error" : ""
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
playbook_ui-10.4.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.3.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.2.1.alpha.sisensefix app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.2.1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.2.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.1.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.0.3.pre.alpha.walkthrough2 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.0.3.pre.alpha.walkthrough app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.0.1.alpha.railscusticon app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.0.2.pre.alpha.pre.iconfix app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.0.1.alpha.rtflexfix app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.0.0.pre.alphafonts app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.0.1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-10.0.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.19.0.pre.alpha.pre.fonts2 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.19.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.19.0.pre.alphafonts app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.18.0.flow.bin.alpha app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.18.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-9.17.0 app/pb_kits/playbook/pb_select/select.rb