2016-10-24 23:58:09 +03:00
|
|
|
/*
|
|
|
|
* based on
|
2016-10-26 12:51:06 +03:00
|
|
|
* github.com/roylee0704/react-flexbox-grid/blob/master/src/components/Col.js
|
2016-10-24 23:58:09 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
const flatten = require('lodash.flatten');
|
|
|
|
const classNames = require('classnames');
|
|
|
|
const React = require('react');
|
|
|
|
const styles = require('./style.css');
|
|
|
|
|
|
|
|
const breakpoints = [
|
|
|
|
'xs',
|
|
|
|
'sm',
|
|
|
|
'md',
|
|
|
|
'lg'
|
|
|
|
];
|
|
|
|
|
|
|
|
const getClasses = (props) => {
|
|
|
|
return flatten(breakpoints.map((size) => {
|
|
|
|
const number = props[size];
|
|
|
|
const offset = props[`${size}Offset`];
|
|
|
|
|
|
|
|
return [
|
|
|
|
number ? styles[`${size}-${number}`] : '',
|
|
|
|
offset ? styles[`${size}-offset-${offset}`] : ''
|
|
|
|
];
|
|
|
|
})).filter(Boolean);
|
|
|
|
};
|
|
|
|
|
2016-10-25 22:15:33 +03:00
|
|
|
const Column = (props) => {
|
2016-10-24 23:58:09 +03:00
|
|
|
const {
|
2016-10-25 22:15:33 +03:00
|
|
|
children,
|
2016-10-24 23:58:09 +03:00
|
|
|
className,
|
|
|
|
reverse,
|
|
|
|
style
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const cn = classNames(
|
|
|
|
className,
|
|
|
|
styles.column,
|
|
|
|
reverse ? styles.reverse : '',
|
|
|
|
...getClasses(props)
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2016-10-25 22:15:33 +03:00
|
|
|
<div className={cn} style={style}>
|
2016-10-24 23:58:09 +03:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Column.propTypes = {
|
2016-10-25 22:15:33 +03:00
|
|
|
children: React.PropTypes.node,
|
2016-10-24 23:58:09 +03:00
|
|
|
className: React.PropTypes.string,
|
2016-10-25 22:15:33 +03:00
|
|
|
reverse: React.PropTypes.bool,
|
2016-10-24 23:58:09 +03:00
|
|
|
style: React.PropTypes.object,
|
|
|
|
...breakpoints.reduce((all, bp) => ({
|
|
|
|
...all,
|
|
|
|
[`${bp}Offset`]: React.PropTypes.number,
|
|
|
|
[bp]: React.PropTypes.number
|
|
|
|
}), {})
|
|
|
|
};
|
2016-10-25 22:15:33 +03:00
|
|
|
|
|
|
|
module.exports = Column;
|