ant-design/components/layout/row.tsx
马斯特 a25ec29fb8 refactor: 保证所有的tsx和less都正确使用prefix (#3024)
* refactor: extract prefix cls as less variable

* refactor: apply ant icon prefix cls in less files

* refactor: all components support prefixCls props
2016-09-14 16:18:33 +08:00

62 lines
1.9 KiB
TypeScript

import * as React from 'react';
import { Children, cloneElement } from 'react';
import classNames from 'classnames';
import assign from 'object-assign';
import splitObject from '../_util/splitObject';
export interface RowProps {
className?: string;
gutter?: number;
type?: 'flex';
align?: 'top' | 'middle' | 'bottom';
justify?: 'start' | 'end' | 'center' | 'space-around' | 'space-between';
style?: React.CSSProperties;
prefixCls?: string;
}
export default class Row extends React.Component<RowProps, any> {
static defaultProps = {
gutter: 0,
prefixCls: 'ant-row',
};
static propTypes = {
type: React.PropTypes.string,
align: React.PropTypes.string,
justify: React.PropTypes.string,
className: React.PropTypes.string,
children: React.PropTypes.node,
gutter: React.PropTypes.number,
prefixCls: React.PropTypes.string,
};
render() {
const [{ type, justify, align, className, gutter, style, children, prefixCls }, others] = splitObject(this.props,
['type', 'justify', 'align', 'className', 'gutter', 'style', 'children', 'prefixCls']);
const classes = classNames({
[prefixCls]: !type,
[`${prefixCls}-${type}`]: type,
[`${prefixCls}-${type}-${justify}`]: justify,
[`${prefixCls}-${type}-${align}`]: align,
[className]: className,
});
const rowStyle = gutter > 0 ? assign({}, {
marginLeft: gutter / -2,
marginRight: gutter / -2,
}, style) : style;
const cols = Children.map(children, (col: React.ReactElement<any>) => {
if (!col) {
return null;
}
if (col.props) {
return cloneElement(col, {
style: gutter > 0 ? assign({}, {
paddingLeft: gutter / 2,
paddingRight: gutter / 2,
}, col.props.style) : col.props.style,
});
}
return col;
});
return <div {...others} className={classes} style={rowStyle}>{cols}</div>;
}
}