ant-design/components/layout/row.jsx

46 lines
1.2 KiB
React
Raw Normal View History

2016-02-23 17:34:46 +08:00
import React, { Children, cloneElement } from 'react';
import classNames from 'classnames';
2015-10-27 23:52:17 +08:00
const Row = React.createClass({
2015-10-28 00:02:31 +08:00
propTypes: {
2015-10-27 23:52:17 +08:00
type: React.PropTypes.string,
align: React.PropTypes.string,
justify: React.PropTypes.string,
className: React.PropTypes.string,
2015-10-27 23:52:17 +08:00
children: React.PropTypes.node,
2016-02-23 17:34:46 +08:00
gutter: React.PropTypes.number,
},
getDefaultProps() {
return {
gutter: 0,
};
2015-10-27 23:52:17 +08:00
},
render() {
2016-02-23 17:34:46 +08:00
const { type, justify, align, className, gutter, style, children, ...others } = this.props;
const classes = classNames({
row: true,
[`row-${type}`]: type,
[`row-${type}-${justify}`]: justify,
[`row-${type}-${align}`]: align,
[className]: className,
});
2016-02-23 17:34:46 +08:00
const rowStyle = gutter > 0 ? {
marginLeft: gutter / -2,
marginRight: gutter / -2,
...style,
} : style;
const cols = Children.map(children, col =>
cloneElement(col, {
style: gutter > 0 ? {
paddingLeft: gutter / 2,
paddingRight: gutter / 2,
2016-02-25 18:03:48 +08:00
...col.props.style
} : col.props.style,
2016-02-23 17:34:46 +08:00
})
);
return <div {...others} className={classes} style={rowStyle}>{cols}</div>;
2015-10-27 23:52:17 +08:00
},
});
2015-10-28 00:02:31 +08:00
export default Row;