2016-09-21 11:54:53 +08:00
|
|
|
import React from 'react';
|
2016-08-22 17:26:14 +08:00
|
|
|
import { PropTypes } 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';
|
2016-08-22 17:26:14 +08:00
|
|
|
|
2016-02-25 16:48:03 +08:00
|
|
|
const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
|
2016-03-07 21:03:17 +08:00
|
|
|
const objectOrNumber = PropTypes.oneOfType([PropTypes.object, PropTypes.number]);
|
2016-07-13 11:14:24 +08:00
|
|
|
|
2016-09-13 15:31:29 +08:00
|
|
|
export interface ColSize {
|
2016-08-19 17:11:06 +08:00
|
|
|
span?: number;
|
|
|
|
order?: number;
|
|
|
|
offset?: number;
|
|
|
|
push?: number;
|
|
|
|
pull?: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ColProps {
|
2016-08-22 17:26:14 +08:00
|
|
|
className?: string;
|
2016-08-19 17:11:06 +08:00
|
|
|
span?: number;
|
|
|
|
order?: number;
|
|
|
|
offset?: number;
|
|
|
|
push?: number;
|
|
|
|
pull?: number;
|
2016-09-19 10:17:07 +08:00
|
|
|
xs?: number | ColSize;
|
|
|
|
sm?: number | ColSize;
|
|
|
|
md?: number | ColSize;
|
|
|
|
lg?: number | ColSize;
|
2016-09-14 16:18:33 +08:00
|
|
|
prefixCls?: string;
|
2016-09-19 17:35:17 +08:00
|
|
|
style?: React.CSSProperties;
|
2016-08-19 17:11:06 +08:00
|
|
|
}
|
|
|
|
|
2016-10-24 12:04:26 +08:00
|
|
|
export default class Col extends React.Component<ColProps, any> {
|
|
|
|
static propTypes = {
|
|
|
|
span: stringOrNumber,
|
|
|
|
order: stringOrNumber,
|
|
|
|
offset: stringOrNumber,
|
|
|
|
push: stringOrNumber,
|
|
|
|
pull: stringOrNumber,
|
|
|
|
className: PropTypes.string,
|
|
|
|
children: PropTypes.node,
|
|
|
|
xs: objectOrNumber,
|
|
|
|
sm: objectOrNumber,
|
|
|
|
md: objectOrNumber,
|
|
|
|
lg: objectOrNumber,
|
|
|
|
};
|
2016-07-13 11:14:24 +08:00
|
|
|
|
2016-10-24 12:04:26 +08:00
|
|
|
render() {
|
|
|
|
const props = this.props;
|
2016-12-19 15:19:15 +08:00
|
|
|
const { span, order, offset, push, pull, className, children, prefixCls = 'ant-col', ...others } = props;
|
2016-10-24 12:04:26 +08:00
|
|
|
let sizeClassObj = {};
|
|
|
|
['xs', 'sm', 'md', 'lg'].forEach(size => {
|
|
|
|
let sizeProps: ColSize = {};
|
|
|
|
if (typeof props[size] === 'number') {
|
|
|
|
sizeProps.span = props[size];
|
|
|
|
} else if (typeof props[size] === 'object') {
|
|
|
|
sizeProps = props[size] || {};
|
|
|
|
}
|
2016-07-04 15:19:35 +08:00
|
|
|
|
2016-10-24 12:04:26 +08:00
|
|
|
delete others[size];
|
2016-04-13 17:38:53 +08:00
|
|
|
|
2016-10-24 12:04:26 +08:00
|
|
|
sizeClassObj = assign({}, sizeClassObj, {
|
|
|
|
[`${prefixCls}-${size}-${sizeProps.span}`]: sizeProps.span !== undefined,
|
|
|
|
[`${prefixCls}-${size}-order-${sizeProps.order}`]: sizeProps.order,
|
|
|
|
[`${prefixCls}-${size}-offset-${sizeProps.offset}`]: sizeProps.offset,
|
|
|
|
[`${prefixCls}-${size}-push-${sizeProps.push}`]: sizeProps.push,
|
|
|
|
[`${prefixCls}-${size}-pull-${sizeProps.pull}`]: sizeProps.pull,
|
|
|
|
});
|
|
|
|
});
|
2016-11-30 10:20:23 +08:00
|
|
|
const classes = classNames({
|
2016-10-24 12:04:26 +08:00
|
|
|
[`${prefixCls}-${span}`]: span !== undefined,
|
|
|
|
[`${prefixCls}-order-${order}`]: order,
|
|
|
|
[`${prefixCls}-offset-${offset}`]: offset,
|
|
|
|
[`${prefixCls}-push-${push}`]: push,
|
|
|
|
[`${prefixCls}-pull-${pull}`]: pull,
|
2016-11-30 10:20:23 +08:00
|
|
|
}, className, sizeClassObj);
|
2016-08-22 17:26:14 +08:00
|
|
|
|
2016-10-24 12:04:26 +08:00
|
|
|
return <div {...others} className={classes}>{children}</div>;
|
|
|
|
}
|
|
|
|
}
|