lib/primer/classify.rb
# NOTE: This is a fairly naive implementation that we're building as we go.
# Feel free to refactor as this is thoroughly tested.
#
# Utility for mapping component configuration into Primer CSS class names
#
# styles_hash - A hash with utility keys that mimic the interface used by https://github.com/primer/components
#
# Returns a string of Primer CSS class names and style attributes to be added to an HTML tag.
#
# Example usage:
# extract_css_attrs({ mt: 4, py: 2 }) => "mt-4 py-2"
This is a fairly naive implementation that we're building as we go.
Feel free to refactor as this is thoroughly tested.

Utility for mapping component configuration into Primer CSS class names



Returns a string of Primer CSS class names and style attributes to be added to an HTML tag.


This is a fairly naive implementation that we ' re building as we go . Feel free to refactor as this is thoroughly tested . Utility for mapping component configuration into Primer CSS class names Returns a string of Primer CSS class names and style attributes to be added to an HTML tag .
def extract_css_attrs(styles_hash)
        classes = []
        styles = +""
        styles_hash.each do |key, value|
          if value.is_a?(Array)
            raise ArgumentError, "#{key} does not support responsive values" unless Primer::Classify::Flex::RESPONSIVE_KEYS.include?(key) || Primer::Classify::Utilities.supported_key?(key)
            value.each_with_index do |val, index|
              extract_one_css_attr(classes, styles, key, val, BREAKPOINTS[index])
            end
          else
            extract_one_css_attr(classes, styles, key, value, BREAKPOINTS[0])
          end
        end
        {
          class: classes.join(" "),
          style: styles
        }
      end
def extract_css_attrs ( styles_hash ) classes = [ ] styles = + "" styles_hash . each do | key , value | if value . is_a? ( Array ) raise ArgumentError , "#{key} does not support responsive values" unless Primer :: Classify :: Flex :: RESPONSIVE_KEYS . include? ( key ) || Primer :: Classify :: Utilities . supported_key? ( key ) value . each_with_index do | val , index | extract_one_css_attr ( classes , styles , key , val , BREAKPOINTS [ index ] ) end else extract_one_css_attr ( classes , styles , key , value , BREAKPOINTS [ 0 ] ) end end { class : classes . join ( " " ) , style : styles } end
NOTE: This is a fairly naive implementation that we're building as we go.
NOTE : This is a fairly naive implementation that we ' re building as we go .
styles_hash