2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2019-03-15 15:12:28 +08:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2020-01-19 16:58:38 +08:00
|
|
|
import { getListeners } from '../_util/props-util';
|
2018-03-19 10:16:27 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
|
2017-10-27 13:24:22 +08:00
|
|
|
|
2018-03-08 13:55:49 +08:00
|
|
|
export const ColSize = PropTypes.shape({
|
|
|
|
span: stringOrNumber,
|
|
|
|
order: stringOrNumber,
|
|
|
|
offset: stringOrNumber,
|
|
|
|
push: stringOrNumber,
|
|
|
|
pull: stringOrNumber,
|
2019-01-12 11:33:27 +08:00
|
|
|
}).loose;
|
2018-03-08 13:55:49 +08:00
|
|
|
|
2019-09-10 21:54:22 +08:00
|
|
|
const objectOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number, ColSize]);
|
2018-03-08 13:55:49 +08:00
|
|
|
|
|
|
|
export const ColProps = {
|
2018-12-09 10:58:50 +08:00
|
|
|
span: stringOrNumber,
|
|
|
|
order: stringOrNumber,
|
|
|
|
offset: stringOrNumber,
|
|
|
|
push: stringOrNumber,
|
|
|
|
pull: stringOrNumber,
|
|
|
|
xs: objectOrNumber,
|
|
|
|
sm: objectOrNumber,
|
|
|
|
md: objectOrNumber,
|
|
|
|
lg: objectOrNumber,
|
|
|
|
xl: objectOrNumber,
|
|
|
|
xxl: objectOrNumber,
|
2018-03-08 13:55:49 +08:00
|
|
|
prefixCls: PropTypes.string,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-08 13:55:49 +08:00
|
|
|
|
|
|
|
export default {
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ACol',
|
2019-02-01 17:23:00 +08:00
|
|
|
props: ColProps,
|
2018-12-09 10:58:50 +08:00
|
|
|
inject: {
|
2019-09-11 22:35:25 +08:00
|
|
|
configProvider: { default: () => ConfigConsumerProps },
|
2018-12-09 10:58:50 +08:00
|
|
|
rowContext: {
|
2019-01-28 21:09:13 +08:00
|
|
|
default: () => null,
|
2018-12-09 10:58:50 +08:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
span,
|
|
|
|
order,
|
|
|
|
offset,
|
|
|
|
push,
|
|
|
|
pull,
|
2019-03-15 15:12:28 +08:00
|
|
|
prefixCls: customizePrefixCls,
|
2019-01-12 11:33:27 +08:00
|
|
|
$slots,
|
|
|
|
rowContext,
|
|
|
|
} = this;
|
2019-09-11 22:35:25 +08:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-03-15 15:12:28 +08:00
|
|
|
const prefixCls = getPrefixCls('col', customizePrefixCls);
|
|
|
|
|
2018-03-08 13:55:49 +08:00
|
|
|
let sizeClassObj = {};
|
|
|
|
['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].forEach(size => {
|
2019-01-12 11:33:27 +08:00
|
|
|
let sizeProps = {};
|
2020-03-07 19:45:13 +08:00
|
|
|
const propSize = this[size];
|
|
|
|
if (typeof propSize === 'number') {
|
|
|
|
sizeProps.span = propSize;
|
|
|
|
} else if (typeof propSize === 'object') {
|
|
|
|
sizeProps = propSize || {};
|
2017-10-27 13:24:22 +08:00
|
|
|
}
|
2018-03-08 13:55:49 +08:00
|
|
|
|
|
|
|
sizeClassObj = {
|
|
|
|
...sizeClassObj,
|
|
|
|
[`${prefixCls}-${size}-${sizeProps.span}`]: sizeProps.span !== undefined,
|
|
|
|
[`${prefixCls}-${size}-order-${sizeProps.order}`]: sizeProps.order || sizeProps.order === 0,
|
2019-01-12 11:33:27 +08:00
|
|
|
[`${prefixCls}-${size}-offset-${sizeProps.offset}`]:
|
|
|
|
sizeProps.offset || sizeProps.offset === 0,
|
2018-03-08 13:55:49 +08:00
|
|
|
[`${prefixCls}-${size}-push-${sizeProps.push}`]: sizeProps.push || sizeProps.push === 0,
|
|
|
|
[`${prefixCls}-${size}-pull-${sizeProps.pull}`]: sizeProps.pull || sizeProps.pull === 0,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
});
|
2018-03-08 13:55:49 +08:00
|
|
|
const classes = {
|
2020-03-07 19:45:13 +08:00
|
|
|
[`${prefixCls}`]: true,
|
2018-03-08 13:55:49 +08:00
|
|
|
[`${prefixCls}-${span}`]: span !== undefined,
|
|
|
|
[`${prefixCls}-order-${order}`]: order,
|
|
|
|
[`${prefixCls}-offset-${offset}`]: offset,
|
|
|
|
[`${prefixCls}-push-${push}`]: push,
|
|
|
|
[`${prefixCls}-pull-${pull}`]: pull,
|
|
|
|
...sizeClassObj,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-08 13:55:49 +08:00
|
|
|
const divProps = {
|
2020-01-19 16:58:38 +08:00
|
|
|
on: getListeners(this),
|
2018-03-08 13:55:49 +08:00
|
|
|
class: classes,
|
2018-12-09 10:58:50 +08:00
|
|
|
style: {},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-12-09 10:58:50 +08:00
|
|
|
if (rowContext) {
|
2019-01-12 11:33:27 +08:00
|
|
|
const gutter = rowContext.getGutter();
|
2020-03-07 19:45:13 +08:00
|
|
|
if (gutter) {
|
2018-12-09 10:58:50 +08:00
|
|
|
divProps.style = {
|
2020-03-07 19:45:13 +08:00
|
|
|
...(gutter[0] > 0
|
|
|
|
? {
|
|
|
|
paddingLeft: `${gutter[0] / 2}px`,
|
|
|
|
paddingRight: `${gutter[0] / 2}px`,
|
|
|
|
}
|
|
|
|
: {}),
|
|
|
|
...(gutter[1] > 0
|
|
|
|
? {
|
|
|
|
paddingTop: `${gutter[1] / 2}px`,
|
|
|
|
paddingBottom: `${gutter[1] / 2}px`,
|
|
|
|
}
|
|
|
|
: {}),
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-12-09 10:58:50 +08:00
|
|
|
}
|
2018-03-08 13:55:49 +08:00
|
|
|
}
|
2019-01-12 11:33:27 +08:00
|
|
|
return <div {...divProps}>{$slots.default}</div>;
|
2018-03-08 13:55:49 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|