You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
9 years ago
|
import React, { Children, cloneElement } from 'react';
|
||
9 years ago
|
import classNames from 'classnames';
|
||
9 years ago
|
import assign from 'object-assign';
|
||
|
import splitObject from '../_util/splitObject';
|
||
9 years ago
|
export default class Row extends React.Component {
|
||
|
static defaultProps = {
|
||
|
gutter: 0,
|
||
|
}
|
||
|
static propTypes = {
|
||
9 years ago
|
type: React.PropTypes.string,
|
||
|
align: React.PropTypes.string,
|
||
|
justify: React.PropTypes.string,
|
||
9 years ago
|
className: React.PropTypes.string,
|
||
9 years ago
|
children: React.PropTypes.node,
|
||
9 years ago
|
gutter: React.PropTypes.number,
|
||
9 years ago
|
}
|
||
9 years ago
|
render() {
|
||
9 years ago
|
const [{type, justify, align, className, gutter, style, children}, others] = splitObject(this.props,
|
||
|
['type', 'justify','align', 'className','gutter', 'style','children']);
|
||
9 years ago
|
const classes = classNames({
|
||
9 years ago
|
'ant-row': !type,
|
||
|
[`ant-row-${type}`]: type,
|
||
|
[`ant-row-${type}-${justify}`]: justify,
|
||
|
[`ant-row-${type}-${align}`]: align,
|
||
9 years ago
|
[className]: className,
|
||
|
});
|
||
9 years ago
|
const rowStyle = gutter > 0 ? assign({}, {
|
||
9 years ago
|
marginLeft: gutter / -2,
|
||
|
marginRight: gutter / -2,
|
||
9 years ago
|
},style) : style;
|
||
9 years ago
|
const cols = Children.map(children, col => {
|
||
9 years ago
|
if (!col) return null;
|
||
9 years ago
|
|
||
|
return cloneElement(col, {
|
||
9 years ago
|
style: gutter > 0 ? assign({}, {
|
||
9 years ago
|
paddingLeft: gutter / 2,
|
||
|
paddingRight: gutter / 2,
|
||
9 years ago
|
}, col.props.style) : col.props.style,
|
||
9 years ago
|
});
|
||
|
});
|
||
9 years ago
|
return <div {...others} className={classes} style={rowStyle}>{cols}</div>;
|
||
9 years ago
|
}
|
||
|
}
|