|
| 1 | +import classnames from 'classnames'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import React from 'react'; |
| 4 | + |
| 5 | +const Cell = (props) => { |
| 6 | + const { |
| 7 | + align, |
| 8 | + children, |
| 9 | + className, |
| 10 | + columns, |
| 11 | + desktopColumns, |
| 12 | + order, |
| 13 | + phoneColumns, |
| 14 | + tabletColumns, |
| 15 | + tag: Tag, |
| 16 | + ...otherProps |
| 17 | + } = props; |
| 18 | + |
| 19 | + const classes = classnames('mdc-layout-grid__cell', className, { |
| 20 | + [`mdc-layout-grid__cell--align-${align}`]: !!align, |
| 21 | + [`mdc-layout-grid__cell--order-${order}`]: !!order, |
| 22 | + [`mdc-layout-grid__cell--span-${columns}`]: !!columns, |
| 23 | + [`mdc-layout-grid__cell--span-${desktopColumns}-desktop`]: !!desktopColumns, |
| 24 | + [`mdc-layout-grid__cell--span-${phoneColumns}-phone`]: !!phoneColumns, |
| 25 | + [`mdc-layout-grid__cell--span-${tabletColumns}-tablet`]: !!tabletColumns, |
| 26 | + }); |
| 27 | + |
| 28 | + return ( |
| 29 | + <Tag className={classes} {...otherProps}> |
| 30 | + {children} |
| 31 | + </Tag> |
| 32 | + ); |
| 33 | +}; |
| 34 | + |
| 35 | +Cell.propTypes = { |
| 36 | + align: PropTypes.oneOf(['bottom', 'middle', 'top']), |
| 37 | + children: PropTypes.node, |
| 38 | + className: PropTypes.string, |
| 39 | + columns: PropTypes.oneOf([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), |
| 40 | + desktopColumns: PropTypes.oneOf([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), |
| 41 | + order: PropTypes.oneOf([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), |
| 42 | + phoneColumns: PropTypes.oneOf([1, 2, 3, 4]), |
| 43 | + tabletColumns: PropTypes.oneOf([1, 2, 3, 4, 5, 6, 7, 8]), |
| 44 | + tag: PropTypes.string, |
| 45 | +}; |
| 46 | + |
| 47 | +Cell.defaultProps = { |
| 48 | + align: undefined, |
| 49 | + children: undefined, |
| 50 | + className: '', |
| 51 | + columns: undefined, |
| 52 | + desktopColumns: undefined, |
| 53 | + order: undefined, |
| 54 | + phoneColumns: undefined, |
| 55 | + tabletColumns: undefined, |
| 56 | + tag: 'div', |
| 57 | +}; |
| 58 | + |
| 59 | +export default Cell; |
0 commit comments