mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-04 04:58:16 +08:00
89 lines
2.4 KiB
Vue
89 lines
2.4 KiB
Vue
|
|
import PropTypes from '../_util/vue-types'
|
|
|
|
const stringOrNumber = PropTypes.oneOfType([PropTypes.string, PropTypes.number])
|
|
|
|
export const ColSize = PropTypes.shape({
|
|
span: stringOrNumber,
|
|
order: stringOrNumber,
|
|
offset: stringOrNumber,
|
|
push: stringOrNumber,
|
|
pull: stringOrNumber,
|
|
}).loose
|
|
|
|
const objectOrNumber = PropTypes.oneOfType([PropTypes.number, ColSize])
|
|
|
|
export const ColProps = {
|
|
span: stringOrNumber,
|
|
order: stringOrNumber,
|
|
offset: stringOrNumber,
|
|
push: stringOrNumber,
|
|
pull: stringOrNumber,
|
|
xs: objectOrNumber,
|
|
sm: objectOrNumber,
|
|
md: objectOrNumber,
|
|
lg: objectOrNumber,
|
|
xl: objectOrNumber,
|
|
xxl: objectOrNumber,
|
|
prefixCls: PropTypes.string,
|
|
}
|
|
|
|
export default {
|
|
props: ColProps,
|
|
name: 'ACol',
|
|
inject: {
|
|
rowContext: {
|
|
default: null,
|
|
},
|
|
},
|
|
render () {
|
|
const { span, order, offset, push, pull,
|
|
prefixCls = 'ant-col',
|
|
$slots, $attrs, $listeners, rowContext,
|
|
} = this
|
|
let sizeClassObj = {};
|
|
['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].forEach(size => {
|
|
let sizeProps = {}
|
|
if (typeof this[size] === 'number') {
|
|
sizeProps.span = this[size]
|
|
} else if (typeof this[size] === 'object') {
|
|
sizeProps = this[size] || {}
|
|
}
|
|
|
|
sizeClassObj = {
|
|
...sizeClassObj,
|
|
[`${prefixCls}-${size}-${sizeProps.span}`]: sizeProps.span !== undefined,
|
|
[`${prefixCls}-${size}-order-${sizeProps.order}`]: sizeProps.order || sizeProps.order === 0,
|
|
[`${prefixCls}-${size}-offset-${sizeProps.offset}`]: sizeProps.offset || sizeProps.offset === 0,
|
|
[`${prefixCls}-${size}-push-${sizeProps.push}`]: sizeProps.push || sizeProps.push === 0,
|
|
[`${prefixCls}-${size}-pull-${sizeProps.pull}`]: sizeProps.pull || sizeProps.pull === 0,
|
|
}
|
|
})
|
|
const classes = {
|
|
[`${prefixCls}-${span}`]: span !== undefined,
|
|
[`${prefixCls}-order-${order}`]: order,
|
|
[`${prefixCls}-offset-${offset}`]: offset,
|
|
[`${prefixCls}-push-${push}`]: push,
|
|
[`${prefixCls}-pull-${pull}`]: pull,
|
|
...sizeClassObj,
|
|
}
|
|
const divProps = {
|
|
on: $listeners,
|
|
attrs: $attrs,
|
|
class: classes,
|
|
style: {},
|
|
}
|
|
if (rowContext) {
|
|
const gutter = rowContext.getGutter()
|
|
if (gutter > 0) {
|
|
divProps.style = {
|
|
paddingLeft: `${gutter / 2}px`,
|
|
paddingRight: `${gutter / 2}px`,
|
|
}
|
|
}
|
|
}
|
|
return <div {...divProps}>{$slots.default}</div>
|
|
},
|
|
}
|
|
|