ant-design-vue/components/grid/Col.jsx

96 lines
2.5 KiB
Vue
Raw Normal View History

2019-01-12 03:33:27 +00:00
import PropTypes from '../_util/vue-types';
2018-03-19 02:16:27 +00:00
2019-01-12 03:33:27 +00:00
const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
2018-03-08 05:55:49 +00:00
export const ColSize = PropTypes.shape({
span: stringOrNumber,
order: stringOrNumber,
offset: stringOrNumber,
push: stringOrNumber,
pull: stringOrNumber,
2019-01-12 03:33:27 +00:00
}).loose;
2018-03-08 05:55:49 +00:00
2019-01-12 03:33:27 +00:00
const objectOrNumber = PropTypes.oneOfType([PropTypes.number, ColSize]);
2018-03-08 05:55:49 +00:00
export const ColProps = {
2018-12-09 02:58:50 +00: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 05:55:49 +00:00
prefixCls: PropTypes.string,
2019-01-12 03:33:27 +00:00
};
2018-03-08 05:55:49 +00:00
export default {
props: ColProps,
2018-04-08 13:17:20 +00:00
name: 'ACol',
2018-12-09 02:58:50 +00:00
inject: {
rowContext: {
default: null,
},
},
2019-01-12 03:33:27 +00:00
render() {
const {
span,
order,
offset,
push,
pull,
2018-12-09 02:58:50 +00:00
prefixCls = 'ant-col',
2019-01-12 03:33:27 +00:00
$slots,
$attrs,
$listeners,
rowContext,
} = this;
2018-03-08 05:55:49 +00:00
let sizeClassObj = {};
['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].forEach(size => {
2019-01-12 03:33:27 +00:00
let sizeProps = {};
2018-03-08 05:55:49 +00:00
if (typeof this[size] === 'number') {
2019-01-12 03:33:27 +00:00
sizeProps.span = this[size];
2018-03-08 05:55:49 +00:00
} else if (typeof this[size] === 'object') {
2019-01-12 03:33:27 +00:00
sizeProps = this[size] || {};
}
2018-03-08 05:55:49 +00:00
sizeClassObj = {
...sizeClassObj,
[`${prefixCls}-${size}-${sizeProps.span}`]: sizeProps.span !== undefined,
[`${prefixCls}-${size}-order-${sizeProps.order}`]: sizeProps.order || sizeProps.order === 0,
2019-01-12 03:33:27 +00:00
[`${prefixCls}-${size}-offset-${sizeProps.offset}`]:
sizeProps.offset || sizeProps.offset === 0,
2018-03-08 05:55:49 +00:00
[`${prefixCls}-${size}-push-${sizeProps.push}`]: sizeProps.push || sizeProps.push === 0,
[`${prefixCls}-${size}-pull-${sizeProps.pull}`]: sizeProps.pull || sizeProps.pull === 0,
2019-01-12 03:33:27 +00:00
};
});
2018-03-08 05:55:49 +00:00
const classes = {
[`${prefixCls}-${span}`]: span !== undefined,
[`${prefixCls}-order-${order}`]: order,
[`${prefixCls}-offset-${offset}`]: offset,
[`${prefixCls}-push-${push}`]: push,
[`${prefixCls}-pull-${pull}`]: pull,
...sizeClassObj,
2019-01-12 03:33:27 +00:00
};
2018-03-08 05:55:49 +00:00
const divProps = {
on: $listeners,
attrs: $attrs,
class: classes,
2018-12-09 02:58:50 +00:00
style: {},
2019-01-12 03:33:27 +00:00
};
2018-12-09 02:58:50 +00:00
if (rowContext) {
2019-01-12 03:33:27 +00:00
const gutter = rowContext.getGutter();
2018-12-09 02:58:50 +00:00
if (gutter > 0) {
divProps.style = {
paddingLeft: `${gutter / 2}px`,
paddingRight: `${gutter / 2}px`,
2019-01-12 03:33:27 +00:00
};
2018-12-09 02:58:50 +00:00
}
2018-03-08 05:55:49 +00:00
}
2019-01-12 03:33:27 +00:00
return <div {...divProps}>{$slots.default}</div>;
2018-03-08 05:55:49 +00:00
},
2019-01-12 03:33:27 +00:00
};