2019-01-12 03:33:27 +00:00
|
|
|
import Icon from '../icon';
|
|
|
|
import ScrollableInkTabBar from '../vc-tabs/src/ScrollableInkTabBar';
|
|
|
|
import { cloneElement } from '../_util/vnode';
|
2020-03-26 09:24:13 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import { getListeners } from '../_util/props-util';
|
2018-12-12 13:31:18 +00:00
|
|
|
const TabBar = {
|
2020-03-26 09:24:13 +00:00
|
|
|
name: 'TabBar',
|
|
|
|
inheritAttrs: false,
|
|
|
|
props: {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
tabBarStyle: PropTypes.object,
|
|
|
|
tabBarExtraContent: PropTypes.any,
|
|
|
|
type: PropTypes.oneOf(['line', 'card', 'editable-card']),
|
|
|
|
tabPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']).def('top'),
|
|
|
|
tabBarPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
|
|
|
|
size: PropTypes.oneOf(['default', 'small', 'large']),
|
|
|
|
animated: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
|
|
|
renderTabBar: PropTypes.func,
|
|
|
|
panels: PropTypes.array.def([]),
|
|
|
|
activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
|
|
},
|
|
|
|
render() {
|
2018-12-12 13:31:18 +00:00
|
|
|
const {
|
|
|
|
tabBarStyle,
|
|
|
|
animated = true,
|
|
|
|
renderTabBar,
|
|
|
|
tabBarExtraContent,
|
|
|
|
tabPosition,
|
|
|
|
prefixCls,
|
2018-12-14 15:31:02 +00:00
|
|
|
type = 'line',
|
|
|
|
size,
|
2020-03-26 09:24:13 +00:00
|
|
|
} = this.$props;
|
2019-01-12 03:33:27 +00:00
|
|
|
const inkBarAnimated = typeof animated === 'object' ? animated.inkBar : animated;
|
2018-12-12 13:31:18 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const isVertical = tabPosition === 'left' || tabPosition === 'right';
|
|
|
|
const prevIconType = isVertical ? 'up' : 'left';
|
|
|
|
const nextIconType = isVertical ? 'down' : 'right';
|
2018-12-12 13:31:18 +00:00
|
|
|
const prevIcon = (
|
|
|
|
<span class={`${prefixCls}-tab-prev-icon`}>
|
|
|
|
<Icon type={prevIconType} class={`${prefixCls}-tab-prev-icon-target`} />
|
|
|
|
</span>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-12-12 13:31:18 +00:00
|
|
|
const nextIcon = (
|
|
|
|
<span class={`${prefixCls}-tab-next-icon`}>
|
|
|
|
<Icon type={nextIconType} class={`${prefixCls}-tab-next-icon-target`} />
|
|
|
|
</span>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-12-12 13:31:18 +00:00
|
|
|
|
2018-12-14 15:31:02 +00:00
|
|
|
// Additional className for style usage
|
|
|
|
const cls = {
|
|
|
|
[`${prefixCls}-${tabPosition}-bar`]: true,
|
|
|
|
[`${prefixCls}-${size}-bar`]: !!size,
|
|
|
|
[`${prefixCls}-card-bar`]: type && type.indexOf('card') >= 0,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-12-14 15:31:02 +00:00
|
|
|
|
2018-12-12 13:31:18 +00:00
|
|
|
const renderProps = {
|
|
|
|
props: {
|
2020-03-26 09:24:13 +00:00
|
|
|
...this.$props,
|
|
|
|
...this.$attrs,
|
2018-12-12 13:31:18 +00:00
|
|
|
inkBarAnimated,
|
|
|
|
extraContent: tabBarExtraContent,
|
|
|
|
prevIcon,
|
|
|
|
nextIcon,
|
|
|
|
},
|
|
|
|
style: tabBarStyle,
|
2020-03-26 09:24:13 +00:00
|
|
|
on: getListeners(this),
|
2018-12-14 15:31:02 +00:00
|
|
|
class: cls,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-12-12 13:31:18 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
let RenderTabBar;
|
2018-12-12 13:31:18 +00:00
|
|
|
|
|
|
|
if (renderTabBar) {
|
2019-01-12 03:33:27 +00:00
|
|
|
RenderTabBar = renderTabBar(renderProps, ScrollableInkTabBar);
|
2018-12-12 13:31:18 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
RenderTabBar = <ScrollableInkTabBar {...renderProps} />;
|
2018-12-12 13:31:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 09:24:13 +00:00
|
|
|
return cloneElement(RenderTabBar);
|
2018-12-12 13:31:18 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-12-12 13:31:18 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default TabBar;
|