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.
83 lines
2.5 KiB
83 lines
2.5 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import { PropTypes } from 'react';
|
||
9 years ago
|
import classNames from 'classnames';
|
||
9 years ago
|
import assign from 'object-assign';
|
||
8 years ago
|
import splitObject from '../_util/splitObject';
|
||
|
|
||
9 years ago
|
const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
|
||
9 years ago
|
const objectOrNumber = PropTypes.oneOfType([PropTypes.object, PropTypes.number]);
|
||
8 years ago
|
|
||
8 years ago
|
export interface ColSize {
|
||
8 years ago
|
span?: number;
|
||
|
order?: number;
|
||
|
offset?: number;
|
||
|
push?: number;
|
||
|
pull?: number;
|
||
|
}
|
||
|
|
||
|
export interface ColProps {
|
||
8 years ago
|
className?: string;
|
||
8 years ago
|
span?: number;
|
||
|
order?: number;
|
||
|
offset?: number;
|
||
|
push?: number;
|
||
|
pull?: number;
|
||
8 years ago
|
xs?: number | ColSize;
|
||
|
sm?: number | ColSize;
|
||
|
md?: number | ColSize;
|
||
|
lg?: number | ColSize;
|
||
8 years ago
|
prefixCls?: string;
|
||
8 years ago
|
style?: React.CSSProperties;
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
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,
|
||
|
};
|
||
8 years ago
|
|
||
8 years ago
|
render() {
|
||
|
const props = this.props;
|
||
|
const [{ span, order, offset, push, pull, className, children, prefixCls = 'ant-col' }, others] = splitObject(props,
|
||
|
['span', 'order', 'offset', 'push', 'pull', 'className', 'children', 'prefixCls']);
|
||
|
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] || {};
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
delete others[size];
|
||
9 years ago
|
|
||
8 years ago
|
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,
|
||
|
});
|
||
|
});
|
||
|
const classes = classNames(assign({}, {
|
||
|
[`${prefixCls}-${span}`]: span !== undefined,
|
||
|
[`${prefixCls}-order-${order}`]: order,
|
||
|
[`${prefixCls}-offset-${offset}`]: offset,
|
||
|
[`${prefixCls}-push-${push}`]: push,
|
||
|
[`${prefixCls}-pull-${pull}`]: pull,
|
||
|
[className]: !!className,
|
||
|
}, sizeClassObj));
|
||
8 years ago
|
|
||
8 years ago
|
return <div {...others} className={classes}>{children}</div>;
|
||
|
}
|
||
|
}
|