2018-03-19 10:16:27 +08:00
|
|
|
|
2018-03-08 13:55:49 +08:00
|
|
|
import PropTypes from '../_util/vue-types'
|
2017-10-27 13:24:22 +08:00
|
|
|
|
2018-03-08 13:55:49 +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,
|
|
|
|
}).loose
|
|
|
|
|
|
|
|
const objectOrNumber = PropTypes.oneOfType([PropTypes.number, ColSize])
|
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: ColProps,
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ACol',
|
2018-12-09 10:58:50 +08:00
|
|
|
inject: {
|
|
|
|
rowContext: {
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
},
|
2018-03-08 13:55:49 +08:00
|
|
|
render () {
|
2018-12-09 10:58:50 +08:00
|
|
|
const { span, order, offset, push, pull,
|
|
|
|
prefixCls = 'ant-col',
|
|
|
|
$slots, $attrs, $listeners, rowContext,
|
|
|
|
} = this
|
2018-03-08 13:55:49 +08:00
|
|
|
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] || {}
|
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,
|
|
|
|
[`${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,
|
2018-12-09 10:58:50 +08:00
|
|
|
style: {},
|
|
|
|
}
|
|
|
|
if (rowContext) {
|
|
|
|
const gutter = rowContext.getGutter()
|
|
|
|
if (gutter > 0) {
|
|
|
|
divProps.style = {
|
|
|
|
paddingLeft: `${gutter / 2}px`,
|
|
|
|
paddingRight: `${gutter / 2}px`,
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 13:55:49 +08:00
|
|
|
}
|
|
|
|
return <div {...divProps}>{$slots.default}</div>
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|