2019-01-12 03:33:27 +00:00
|
|
|
import { cloneElement } from '../../_util/vnode';
|
|
|
|
import PropTypes from '../../_util/vue-types';
|
|
|
|
import BaseMixin from '../../_util/BaseMixin';
|
2020-06-23 09:34:41 +00:00
|
|
|
import createRefHooks from '../../_util/createRefHooks';
|
2019-01-12 03:33:27 +00:00
|
|
|
function noop() {}
|
2018-09-05 13:28:54 +00:00
|
|
|
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,
|
2020-06-23 09:34:41 +00:00
|
|
|
onKeydown: PropTypes.func,
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2019-01-12 03:33:27 +00:00
|
|
|
onKeyDown(e) {
|
|
|
|
this.__emit('keydown', e);
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
const { prefixCls, onKeyDown, tabBarPosition, extraContent } = this;
|
2018-09-05 13:28:54 +00:00
|
|
|
const cls = {
|
|
|
|
[`${prefixCls}-bar`]: true,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
|
|
|
const topOrBottom = tabBarPosition === 'top' || tabBarPosition === 'bottom';
|
|
|
|
const tabBarExtraContentStyle = topOrBottom ? { float: 'right' } : {};
|
|
|
|
const children = this.$slots.default;
|
|
|
|
let newChildren = children;
|
2018-09-05 13:28:54 +00:00
|
|
|
if (extraContent) {
|
|
|
|
newChildren = [
|
|
|
|
cloneElement(extraContent, {
|
|
|
|
key: 'extra',
|
|
|
|
style: {
|
|
|
|
...tabBarExtraContentStyle,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
cloneElement(children, { key: 'content' }),
|
2019-01-12 03:33:27 +00:00
|
|
|
];
|
|
|
|
newChildren = topOrBottom ? newChildren : newChildren.reverse();
|
2018-09-05 13:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2019-01-12 03:33:27 +00:00
|
|
|
role="tablist"
|
2018-09-05 13:28:54 +00:00
|
|
|
class={cls}
|
2019-01-12 03:33:27 +00:00
|
|
|
tabIndex="0"
|
2018-09-05 13:28:54 +00:00
|
|
|
onKeydown={onKeyDown}
|
2020-06-23 09:34:41 +00:00
|
|
|
{...createRefHooks(this.saveRef('root'))}
|
2018-09-05 13:28:54 +00:00
|
|
|
>
|
|
|
|
{newChildren}
|
|
|
|
</div>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|