|
| 1 | +import React, { PropTypes } from 'react'; |
| 2 | +import classnames from 'classnames'; |
| 3 | +import classList from 'super-simple-flex-grid/src/style.scss'; |
| 4 | + |
| 5 | +const testClassList = prop => ({ |
| 6 | + center: 'test-center', |
| 7 | + centerH: 'test-center-h', |
| 8 | + centerV: 'test-center-v', |
| 9 | + startH: 'test-start-h', |
| 10 | + endH: 'test-end-h', |
| 11 | + startV: 'test-start-v', |
| 12 | + endV: 'test-end-v', |
| 13 | + spaceAround: 'test-space-around', |
| 14 | + spaceBetween: 'test-space-between', |
| 15 | + grow: `test-grow-${prop}`, |
| 16 | + shrink: 'test-shrink', |
| 17 | + ellipsis: 'test-ellipsis', |
| 18 | + noMargin: 'test-no-margin', |
| 19 | +}); |
| 20 | + |
| 21 | +const FlexCell = ({ |
| 22 | + customClass, |
| 23 | + children, |
| 24 | + center, |
| 25 | + centerH, |
| 26 | + centerV, |
| 27 | + startH, |
| 28 | + startV, |
| 29 | + endH, |
| 30 | + endV, |
| 31 | + spaceAround, |
| 32 | + spaceBetween, |
| 33 | + grow, |
| 34 | + shrink, |
| 35 | + ellipsis, |
| 36 | + noMargin, |
| 37 | +}) => { |
| 38 | + const flexCellClass = 'flex-row__cell'; |
| 39 | + const setClass = modifier => `${flexCellClass}--${modifier}`; |
| 40 | + |
| 41 | + const flexCellClassWithModifier = classnames(flexCellClass, { |
| 42 | + [customClass]: customClass, |
| 43 | + [setClass(classList.center || testClassList().center)]: center, |
| 44 | + [setClass(classList.centerH || testClassList().centerH)]: centerH, |
| 45 | + [setClass(classList.centerV || testClassList().centerV)]: centerV, |
| 46 | + [setClass(classList.startH || testClassList().startH)]: startH, |
| 47 | + [setClass(classList.endH || testClassList().endH)]: endH, |
| 48 | + [setClass(classList.startV || testClassList().startV)]: startV, |
| 49 | + [setClass(classList.endV || testClassList().endV)]: endV, |
| 50 | + [setClass(classList.spaceAround || testClassList().spaceAround)]: spaceAround, |
| 51 | + [setClass(classList.spaceBetween || testClassList().spaceBetween)]: spaceBetween, |
| 52 | + [setClass(`${classList.grow || testClassList(grow).grow}`)]: grow, |
| 53 | + [setClass(classList.shrink || testClassList().shrink)]: shrink, |
| 54 | + [setClass(classList.ellipsis || testClassList().ellipsis)]: ellipsis, |
| 55 | + [setClass(classList.noMargin || testClassList().noMargin)]: noMargin, |
| 56 | + }); |
| 57 | + |
| 58 | + return ( |
| 59 | + <div className={flexCellClassWithModifier}> |
| 60 | + {!ellipsis && children} |
| 61 | + { |
| 62 | + ellipsis && |
| 63 | + <div className={`${flexCellClass}--${classnames(classList.ellipsisContent)}`}> |
| 64 | + {children} |
| 65 | + </div> |
| 66 | + } |
| 67 | + </div> |
| 68 | + ); |
| 69 | +}; |
| 70 | + |
| 71 | +FlexCell.propTypes = { |
| 72 | + customClass: PropTypes.string, |
| 73 | + children: PropTypes.any, |
| 74 | + center: PropTypes.bool, |
| 75 | + centerH: PropTypes.bool, |
| 76 | + centerV: PropTypes.bool, |
| 77 | + startH: PropTypes.bool, |
| 78 | + startV: PropTypes.bool, |
| 79 | + endH: PropTypes.bool, |
| 80 | + endV: PropTypes.bool, |
| 81 | + spaceAround: PropTypes.bool, |
| 82 | + spaceBetween: PropTypes.bool, |
| 83 | + grow: PropTypes.string, |
| 84 | + shrink: PropTypes.bool, |
| 85 | + ellipsis: PropTypes.bool, |
| 86 | + noMargin: PropTypes.bool, |
| 87 | +}; |
| 88 | + |
| 89 | +export { testClassList }; |
| 90 | +export default FlexCell; |
0 commit comments