Sha256: 1d2ddf15cd436468207fdc6389e1066345039ff2e2b1952584799bfe70dc5eaa

Contents?: true

Size: 1.92 KB

Versions: 325

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

# rubocop:disable Style/StringConcatenation
require "action_view"

module Playbook
  module PbSelect
    class Select < Playbook::KitBase
      prop :blank_selection
      prop :compact, type: Playbook::Props::Boolean, default: false
      prop :disabled, type: Playbook::Props::Boolean, default: false
      prop :error
      prop :include_blank
      prop :inline, type: Playbook::Props::Boolean, default: false
      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 classnames
        classname + inline_class + compact_class
      end

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

      def inline_class
        inline ? " inline " : " "
      end

      def compact_class
        compact ? "compact" : ""
      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

# rubocop:enable Style/StringConcatenation

Version data entries

325 entries across 325 versions & 1 rubygems

Version Path
playbook_ui-12.38.0.pre.alpha.PLAY932removemomentqp1088 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.38.0.pre.alpha.PLAY966collapsiblenav41086 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.38.0.pre.alpha.audiencesalpha1083 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.38.0.pre.alpha.PLAY966collapsiblenav41082 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.37.0.pre.alpha.PLAY951collapsiblenav31078 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.38.0.pre.alpha.playbook123801077 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.37.0.pre.alpha.PLAY951collapsiblenav31074 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.37.0.pre.alpha.PLAY951collapsiblenav31073 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.37.0.pre.alpha.PLAYaddingdatapropselectkit1071 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.38.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.37.0.pre.alpha.svgiconmethods1064 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.37.0.pre.alpha.PLAY951collapsiblenav31062 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.37.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.36.0.pre.alpha.svgiconmethods1059 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.36.0.pre.alpha.PLAY936momentjs1058 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.36.0.pre.alpha.PLAY936momentjs1050 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.36.0.pre.alpha.PLAY936momentjs1047 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.36.0.pre.alpha.svgiconmethods1043 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.36.0.pre.alpha.PLAY942collapsiblenav21035 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-12.36.0 app/pb_kits/playbook/pb_select/select.rb