All files / src Row.js

100% Statements 24/24
75% Branches 3/4
100% Functions 8/8
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108        1x                                                                                             1x   1x 6x 6x 6x 6x 6x     1x                 6x   6x   6x 210x 1x   210x     6x   6x 30x 30x   30x 30x   30x     6x             6x              
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
 
const BOOL_PROPS_TO_CLASS_NAMES = {
  // zeros out padding on direct child cols
  collapse: ['rev-Row--collapse'],
  smallCollapse: ['rev-Row--smallCollapse'],
  mediumCollapse: ['rev-Row--mediumCollapse'],
  largeCollapse: ['rev-Row--largeCollapse'],
  xlargeCollapse: ['rev-Row--xlargeCollapse'],
  xxlargeCollapse: ['rev-Row--xxlargeCollapse'],
 
  // resets padding on direct child cols
  uncollapse: ['rev-Row--uncollapse'],
  smallUncollapse: ['rev-Row--smallUncollapse'],
  mediumUncollapse: ['rev-Row--mediumUncollapse'],
  largeUncollapse: ['rev-Row--largeUncollapse'],
  xlargeUncollapse: ['rev-Row--xlargeUncollapse'],
  xxlargeUncollapse: ['rev-Row--xxlargeUncollapse'],
 
  flex: ['rev-Row--flex'],
  smallFlex: ['rev-Row--smallFlex'],
  mediumFlex: ['rev-Row--mediumFlex'],
  largeFlex: ['rev-Row--largeFlex'],
  xlargeFlex: ['rev-Row--xlargeFlex'],
  xxlargeFlex: ['rev-Row--xxlargeFlex'],
 
  unflex: ['rev-Row--unflex'],
  smallUnflex: ['rev-Row--smallUnflex'],
  mediumUnflex: ['rev-Row--mediumUnflex'],
  largeUnflex: ['rev-Row--largeUnflex'],
  xlargeUnflex: ['rev-Row--xlargeUnflex'],
  xxlargeUnflex: ['rev-Row--xxlargeUnflex'],
 
  // flex grid props affecting child cols
  directionCol: ['rev-Row--directionCol'],
 
  justifyStart: ['rev-Row--justifyStart'],
  justifyEnd: ['rev-Row--justifyEnd'],
  justifyCenter: ['rev-Row--justifyCenter'],
  justifySpaceAround: ['rev-Row--justifySpaceAround'],
  justifySpaceBetween: ['rev-Row--justifySpaceBetween'],
 
  alignStart: ['rev-Row--alignStart'],
  alignEnd: ['rev-Row--alignEnd'],
  alignCenter: ['rev-Row--alignCenter'],
  alignBaseline: ['rev-Row--alignBaseline'],
  alignStretch: ['rev-Row--alignStretch'],
}
 
const BOOL_PROPS = Object.keys(BOOL_PROPS_TO_CLASS_NAMES)
 
const NUMBER_PROPS_TO_CLASS_NAMES = {
  smallUp: (arg) => [`rev-Row--smallUp${arg}`],
  mediumUp: (arg) => [`rev-Row--mediumUp${arg}`],
  largeUp: (arg) => [`rev-Row--largeUp${arg}`],
  xlargeUp: (arg) => [`rev-Row--xlargeUp${arg}`],
  xxlargeUp: (arg) => [`rev-Row--xxlargeUp${arg}`],
}
 
const NUMBER_PROPS = Object.keys(NUMBER_PROPS_TO_CLASS_NAMES)
 
export default class Row extends Component {
  static propTypes = {
    className: PropTypes.string,
    children: PropTypes.node,
  }
 
  render() {
    const {children, className, ...props} = this.props
 
    const boolClassNames = []
 
    BOOL_PROPS.forEach((name) => {
      if (props[name]) {
        boolClassNames.push(BOOL_PROPS_TO_CLASS_NAMES[name])
      }
      delete props[name]
    })
 
    const numberClassNames = []
 
    NUMBER_PROPS.forEach((name) => {
      const value = props[name]
      const func = NUMBER_PROPS_TO_CLASS_NAMES[name]
 
      Eif (value !== null) {
        numberClassNames.push(func(value))
      }
      delete props[name]
    })
 
    const divClassName = classNames(
      className,
      'rev-Row',
      boolClassNames,
      numberClassNames
    )
 
    return (
      <div {...props} className={divClassName}>
        {children}
      </div>
    )
  }
}