Sha256: 17225eadcf21c2f2c9ba042c2e6ff69a391d73025a8ee69f1fcdcbaaa279353b

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 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 :label
      prop :required, type: Playbook::Props::Boolean, default: false
      prop :disabled, type: Playbook::Props::Boolean, default: false
      prop :multiple, type: Playbook::Props::Boolean, default: false
      prop :name
      prop :onchange
      prop :include_blank
      prop :blank_selection
      prop :options, type: Playbook::Props::HashArray, required: false, default: []
      prop :dark, type: Playbook::Props::Boolean, default: false

      def classname
        generate_classname("pb_select", dark_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 dark_class
          dark ? "dark" : nil
        end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
playbook_ui-3.4.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-3.3.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-3.2.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-3.1.0 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-3.0.1 app/pb_kits/playbook/pb_select/select.rb
playbook_ui-3.0.0 app/pb_kits/playbook/pb_select/select.rb