mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-27 18:50:59 +08:00
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { PropTypes } from 'react';
|
|
import * as React from 'react';
|
|
import classNames from 'classnames';
|
|
import assign from 'object-assign';
|
|
const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
|
|
const objectOrNumber = PropTypes.oneOfType([PropTypes.object, PropTypes.number]);
|
|
import splitObject from '../_util/splitObject';
|
|
|
|
export default function Col(props) {
|
|
const [{ span, order, offset, push, pull, className, children }, others] = splitObject(props,
|
|
['span', 'order', 'offset', 'push', 'pull', 'className', 'children']);
|
|
let sizeClassObj = {};
|
|
['xs', 'sm', 'md', 'lg'].forEach(size => {
|
|
let sizeProps = {};
|
|
if (typeof props[size] === 'number') {
|
|
sizeProps.span = props[size];
|
|
} else if (typeof props[size] === 'object') {
|
|
sizeProps = props[size] || {};
|
|
}
|
|
|
|
delete others[size];
|
|
|
|
sizeClassObj = assign({}, sizeClassObj, {
|
|
[`ant-col-${size}-${sizeProps.span}`]: sizeProps.span !== undefined,
|
|
[`ant-col-${size}-order-${sizeProps.order}`]: sizeProps.order,
|
|
[`ant-col-${size}-offset-${sizeProps.offset}`]: sizeProps.offset,
|
|
[`ant-col-${size}-push-${sizeProps.push}`]: sizeProps.push,
|
|
[`ant-col-${size}-pull-${sizeProps.pull}`]: sizeProps.pull,
|
|
});
|
|
});
|
|
const classes = classNames(assign({}, {
|
|
[`ant-col-${span}`]: span !== undefined,
|
|
[`ant-col-order-${order}`]: order,
|
|
[`ant-col-offset-${offset}`]: offset,
|
|
[`ant-col-push-${push}`]: push,
|
|
[`ant-col-pull-${pull}`]: pull,
|
|
[className]: !!className,
|
|
}, sizeClassObj));
|
|
|
|
return <div {...others} className={classes}>{children}</div>;
|
|
}
|
|
|
|
Col.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,
|
|
};
|