2016-09-21 11:54:53 +08:00
|
|
|
import React from 'react';
|
2016-08-19 17:11:06 +08:00
|
|
|
import { Children, cloneElement } from 'react';
|
2015-11-24 20:03:57 +08:00
|
|
|
import classNames from 'classnames';
|
2016-06-22 13:18:43 +08:00
|
|
|
import assign from 'object-assign';
|
|
|
|
import splitObject from '../_util/splitObject';
|
2016-08-19 17:11:06 +08:00
|
|
|
|
|
|
|
export interface RowProps {
|
2016-08-22 17:26:14 +08:00
|
|
|
className?: string;
|
2016-08-19 17:11:06 +08:00
|
|
|
gutter?: number;
|
|
|
|
type?: 'flex';
|
|
|
|
align?: 'top' | 'middle' | 'bottom';
|
|
|
|
justify?: 'start' | 'end' | 'center' | 'space-around' | 'space-between';
|
2016-08-22 17:26:14 +08:00
|
|
|
style?: React.CSSProperties;
|
2016-09-14 16:18:33 +08:00
|
|
|
prefixCls?: string;
|
2016-08-19 17:11:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class Row extends React.Component<RowProps, any> {
|
2016-03-28 23:21:47 +08:00
|
|
|
static defaultProps = {
|
|
|
|
gutter: 0,
|
2016-09-14 16:18:33 +08:00
|
|
|
prefixCls: 'ant-row',
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-28 23:21:47 +08:00
|
|
|
static propTypes = {
|
2015-10-27 23:52:17 +08:00
|
|
|
type: React.PropTypes.string,
|
|
|
|
align: React.PropTypes.string,
|
|
|
|
justify: React.PropTypes.string,
|
2015-10-28 18:04:56 +08:00
|
|
|
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,
|
2016-09-14 16:18:33 +08:00
|
|
|
prefixCls: React.PropTypes.string,
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2015-10-27 23:52:17 +08:00
|
|
|
render() {
|
2016-09-14 16:18:33 +08:00
|
|
|
const [{ type, justify, align, className, gutter, style, children, prefixCls }, others] = splitObject(this.props,
|
|
|
|
['type', 'justify', 'align', 'className', 'gutter', 'style', 'children', 'prefixCls']);
|
2015-11-24 20:03:57 +08:00
|
|
|
const classes = classNames({
|
2016-09-14 16:18:33 +08:00
|
|
|
[prefixCls]: !type,
|
|
|
|
[`${prefixCls}-${type}`]: type,
|
|
|
|
[`${prefixCls}-${type}-${justify}`]: justify,
|
|
|
|
[`${prefixCls}-${type}-${align}`]: align,
|
2015-10-28 18:04:56 +08:00
|
|
|
[className]: className,
|
|
|
|
});
|
2016-06-22 13:18:43 +08:00
|
|
|
const rowStyle = gutter > 0 ? assign({}, {
|
2016-02-23 17:34:46 +08:00
|
|
|
marginLeft: gutter / -2,
|
|
|
|
marginRight: gutter / -2,
|
2016-07-13 11:14:24 +08:00
|
|
|
}, style) : style;
|
2016-08-24 16:09:55 +08:00
|
|
|
const cols = Children.map(children, (col: React.ReactElement<any>) => {
|
2016-07-13 11:14:24 +08:00
|
|
|
if (!col) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-08-03 20:30:17 +08:00
|
|
|
if (col.props) {
|
|
|
|
return cloneElement(col, {
|
2016-08-04 14:06:09 +08:00
|
|
|
style: gutter > 0 ? assign({}, {
|
2016-08-03 20:30:17 +08:00
|
|
|
paddingLeft: gutter / 2,
|
|
|
|
paddingRight: gutter / 2,
|
2016-08-04 14:06:09 +08:00
|
|
|
}, col.props.style) : col.props.style,
|
2016-08-03 20:30:17 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return col;
|
2016-03-10 09:35:09 +08:00
|
|
|
});
|
2016-02-23 17:34:46 +08:00
|
|
|
return <div {...others} className={classes} style={rowStyle}>{cols}</div>;
|
2016-03-28 23:21:47 +08:00
|
|
|
}
|
|
|
|
}
|