Sha256: 9a47b53a6b45d8ada918aa8188ff39ba9d18cdf1ddf71f67a068767f066e6ebe

Contents?: true

Size: 1.61 KB

Versions: 88

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require "action_view"

module Playbook
  module PbSelect
    class Select
      include ActionView::Helpers::FormTagHelper
      include ActionView::Context
      include Playbook::Props

      partial "pb_select/select"

      prop :blank_selection
      prop :dark, type: Playbook::Props::Boolean, default: false
      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", dark_class)
      end

      def select_wrapper_class
        "pb_select_kit_wrapper" + error_class
      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

      def dark_class
        dark ? "dark" : nil
      end
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
playbook_ui-5.2.0.pre.alpha11 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.5.1.pre.alpha4 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.5.1.pre.alpha3 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.5.1.pre.alpha2 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.5.1.pre.alpha1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.2.0.pre.alpha10 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.5.1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.5.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.5.0.pre.alpha1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.2.0.pre.alpha9 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.2.0.pre.alpha8 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.2.0.pre.alpha7 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.3.0.pre.alpha1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.4.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.2.0.pre.alpha6 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.2.0.pre.alpha5 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.3.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.2.0.pre.alpha4 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.2.0.pre.alpha3 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-5.2.0.pre.alpha2 app/pb_kits/playbook/pb_select/select.rb