Sha256: c8931a24210ed4228d4ddefdaa32b0ddf1c94b5b7dec52c0a8a78109600b5582

Contents?: true

Size: 1.58 KB

Versions: 7

Compression:

Stored size: 1.58 KB

Contents

require 'bh/classes/button'

module Bh
  module Classes
    class Dropdown < Button
      # @return [#to_s] the group-related class to assign to the dropdown.
      def groupable_class
        Dropdown.groupables[@options[:groupable]]
      end

      # @return [#to_s] the direction-related class to assign to the dropdown.
      def direction_class
        Dropdown.directions[@options[:direction]]
      end

      # @return [#to_s] the align-related class to assign to the dropdown.
      def align_class
        Dropdown.aligns[@options[:align]]
      end

      def id
        @options.fetch :id, "dropdown-#{rand 10**10}"
      end

      def partial
        @options[:split] ? 'dropdown_split' : 'dropdown'
      end

    private

      # @return [Hash<Symbol, String>] the class that Bootstrap requires to
      #   append to a dropdown to display it as inline or block.
      def self.groupables
        HashWithIndifferentAccess.new(:'btn-group').tap do |klass|
          klass[false] = :dropdown
        end
      end

      # @return [Hash<Symbol, String>] the class that Bootstrap requires to
      #   append to a dropdown to show a drop-"up" or -"down".
      def self.directions
        HashWithIndifferentAccess.new.tap do |klass|
          klass[:up] = :dropup
        end
      end

      # @return [Hash<Symbol, String>] the class that Bootstrap requires to
      #   append to a dropdown to left- or right- align to the toggle button.
      def self.aligns
        HashWithIndifferentAccess.new.tap do |klass|
          klass[:right] = :'dropdown-menu-right'
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bh-1.3.6 lib/bh/classes/dropdown.rb
bh-1.3.5 lib/bh/classes/dropdown.rb
bh-1.3.4 lib/bh/classes/dropdown.rb
bh-1.3.3 lib/bh/classes/dropdown.rb
bh-1.3.1 lib/bh/classes/dropdown.rb
bh-1.3.0 lib/bh/classes/dropdown.rb
bh-1.2.0 lib/bh/classes/dropdown.rb