All files / src/components/Grid/Group index.jsx

100% Statements 10/10
100% Branches 4/4
100% Functions 3/3
100% Lines 10/10
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          2x 12x         12x       16x 1x     15x 2x     13x       2x         2x          
import React from 'react';
import Item from '../Item';
import classnames from 'classnames';
import PropTypes from 'prop-types';
 
const Group = (props, { grid }) => {
  return <div className={classnames(grid.row, props.className)}>
    {buildChildren()}
  </div>;
 
  function buildChildren() {
    return React.Children.map(props.children, wrapChildIfNeeded);
  }
 
  function wrapChildIfNeeded(child) {
    if (! child) {
      return null;
    }
 
    if (child.type === Item) {
      return child;
    }
 
    return <Item>{child}</Item>;
  }
};
 
Group.propTypes = {
  children: PropTypes.node,
  className: PropTypes.string,
};
 
Group.contextTypes = {
  grid: PropTypes.object,
};
 
export default Group;