Sha256: 654e9903b527f58889a33953737ded7719f8dc6a0bdb754ea746efe4b257f3c0

Contents?: true

Size: 610 Bytes

Versions: 15

Compression:

Stored size: 610 Bytes

Contents

# frozen_string_literal: true

# Inspired by https://github.com/JedWatson/classnames
#
# Helps build a list of conditional class names
module Primer
  module ClassNameHelper
    def class_names(*args)
      classes = []

      args.each do |class_name|
        case class_name
        when String
          classes << class_name if class_name.present?
        when Hash
          class_name.each do |key, val|
            classes << key if val
          end
        when Array
          classes << class_names(*class_name).presence
        end
      end

      classes.compact.uniq.join(" ")
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
primer_view_components-0.0.17 lib/primer/class_name_helper.rb
primer_view_components-0.0.16 lib/primer/class_name_helper.rb
primer_view_components-0.0.15 lib/primer/class_name_helper.rb
primer_view_components-0.0.14 lib/primer/class_name_helper.rb
primer_view_components-0.0.13 lib/primer/class_name_helper.rb
primer_view_components-0.0.12 lib/primer/class_name_helper.rb
primer_view_components-0.0.11 lib/primer/class_name_helper.rb
primer_view_components-0.0.10 lib/primer/class_name_helper.rb
primer_view_components-0.0.9 lib/primer/class_name_helper.rb
primer_view_components-0.0.8 lib/primer/class_name_helper.rb
primer_view_components-0.0.7 lib/primer/class_name_helper.rb
primer_view_components-0.0.6 lib/primer/class_name_helper.rb
primer_view_components-0.0.5 lib/primer/class_name_helper.rb
primer_view_components-0.0.4 lib/primer/class_name_helper.rb
primer_view_components-0.0.3 lib/primer/class_name_helper.rb