2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
import { cloneElement } from '../../_util/vnode'
|
|
|
|
import PropTypes from '../../_util/vue-types'
|
|
|
|
import BaseMixin from '../../_util/BaseMixin'
|
|
|
|
function noop () {
|
|
|
|
}
|
|
|
|
export default {
|
|
|
|
name: 'TabBarRootNode',
|
|
|
|
mixins: [BaseMixin],
|
|
|
|
props: {
|
|
|
|
saveRef: PropTypes.func.def(noop),
|
|
|
|
getRef: PropTypes.func.def(noop),
|
|
|
|
prefixCls: PropTypes.string.def(''),
|
|
|
|
tabBarPosition: PropTypes.string.def('top'),
|
|
|
|
extraContent: PropTypes.any,
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onKeyDown (e) {
|
|
|
|
this.__emit('keydown', e)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
prefixCls, onKeyDown, tabBarPosition, extraContent,
|
|
|
|
} = this
|
|
|
|
const cls = {
|
|
|
|
[`${prefixCls}-bar`]: true,
|
|
|
|
}
|
|
|
|
const topOrBottom = (tabBarPosition === 'top' || tabBarPosition === 'bottom')
|
|
|
|
const tabBarExtraContentStyle = topOrBottom ? { float: 'right' } : {}
|
|
|
|
const children = this.$slots.default
|
|
|
|
let newChildren = children
|
|
|
|
if (extraContent) {
|
|
|
|
newChildren = [
|
|
|
|
cloneElement(extraContent, {
|
|
|
|
key: 'extra',
|
|
|
|
style: {
|
|
|
|
...tabBarExtraContentStyle,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
cloneElement(children, { key: 'content' }),
|
|
|
|
]
|
|
|
|
newChildren = topOrBottom ? newChildren : newChildren.reverse()
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
role='tablist'
|
|
|
|
class={cls}
|
|
|
|
tabIndex='0'
|
|
|
|
onKeydown={onKeyDown}
|
|
|
|
{...{ directives: [{
|
2018-12-14 15:31:02 +00:00
|
|
|
name: 'ant-ref',
|
2018-09-05 13:28:54 +00:00
|
|
|
value: this.saveRef('root'),
|
|
|
|
}] }}
|
|
|
|
>
|
|
|
|
{newChildren}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
}
|