2020-10-13 09:46:31 +00:00
|
|
|
import { defineComponent, PropType } from 'vue';
|
|
|
|
import { tuple } from '../_util/type';
|
2020-03-30 15:43:35 +00:00
|
|
|
import UpOutlined from '@ant-design/icons-vue/UpOutlined';
|
|
|
|
import DownOutlined from '@ant-design/icons-vue/DownOutlined';
|
|
|
|
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
|
|
|
|
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
|
2019-01-12 03:33:27 +00:00
|
|
|
import ScrollableInkTabBar from '../vc-tabs/src/ScrollableInkTabBar';
|
2020-10-13 09:46:31 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-06-23 14:34:08 +00:00
|
|
|
|
2020-10-13 09:46:31 +00:00
|
|
|
const TabBar = defineComponent({
|
2020-03-26 09:24:13 +00:00
|
|
|
name: 'TabBar',
|
|
|
|
inheritAttrs: false,
|
|
|
|
props: {
|
|
|
|
prefixCls: PropTypes.string,
|
2021-01-10 07:23:53 +00:00
|
|
|
centered: PropTypes.looseBool.def(false),
|
2020-10-13 09:46:31 +00:00
|
|
|
tabBarStyle: PropTypes.style,
|
|
|
|
tabBarExtraContent: PropTypes.VNodeChild,
|
|
|
|
type: PropTypes.oneOf(tuple('line', 'card', 'editable-card')),
|
|
|
|
tabPosition: PropTypes.oneOf(tuple('top', 'right', 'bottom', 'left')).def('top'),
|
|
|
|
tabBarPosition: PropTypes.oneOf(tuple('top', 'right', 'bottom', 'left')),
|
|
|
|
size: PropTypes.oneOf(tuple('default', 'small', 'large')),
|
|
|
|
animated: {
|
|
|
|
type: [Boolean, Object] as PropType<boolean | { inkBar: boolean; tabPane: boolean }>,
|
|
|
|
default: undefined,
|
|
|
|
},
|
2020-03-26 09:24:13 +00:00
|
|
|
renderTabBar: PropTypes.func,
|
|
|
|
panels: PropTypes.array.def([]),
|
|
|
|
activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2020-04-15 12:26:17 +00:00
|
|
|
tabBarGutter: PropTypes.number,
|
2020-03-26 09:24:13 +00:00
|
|
|
},
|
|
|
|
render() {
|
2018-12-12 13:31:18 +00:00
|
|
|
const {
|
2021-01-10 07:23:53 +00:00
|
|
|
centered,
|
2018-12-12 13:31:18 +00:00
|
|
|
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';
|
2018-12-12 13:31:18 +00:00
|
|
|
const prevIcon = (
|
|
|
|
<span class={`${prefixCls}-tab-prev-icon`}>
|
2020-04-15 14:05:10 +00:00
|
|
|
{isVertical ? (
|
|
|
|
<UpOutlined class={`${prefixCls}-tab-prev-icon-target`} />
|
|
|
|
) : (
|
2020-03-30 15:43:35 +00:00
|
|
|
<LeftOutlined class={`${prefixCls}-tab-prev-icon-target`} />
|
2020-04-15 14:05:10 +00:00
|
|
|
)}
|
2018-12-12 13:31:18 +00:00
|
|
|
</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`}>
|
2020-04-15 14:05:10 +00:00
|
|
|
{isVertical ? (
|
|
|
|
<DownOutlined class={`${prefixCls}-tab-next-icon-target`} />
|
|
|
|
) : (
|
2020-03-30 15:43:35 +00:00
|
|
|
<RightOutlined class={`${prefixCls}-tab-next-icon-target`} />
|
2020-04-15 14:05:10 +00:00
|
|
|
)}
|
2018-12-12 13:31:18 +00:00
|
|
|
</span>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-12-14 15:31:02 +00:00
|
|
|
// Additional className for style usage
|
|
|
|
const cls = {
|
2020-10-13 09:46:31 +00:00
|
|
|
[this.$attrs.class as string]: this.$attrs.class,
|
2021-01-10 07:23:53 +00:00
|
|
|
[`${prefixCls}-centered-bar`]: centered,
|
2018-12-14 15:31:02 +00:00
|
|
|
[`${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 = {
|
2020-06-23 14:34:08 +00:00
|
|
|
...this.$props,
|
|
|
|
...this.$attrs,
|
2020-06-24 15:45:36 +00:00
|
|
|
children: null,
|
2020-06-23 14:34:08 +00:00
|
|
|
inkBarAnimated,
|
|
|
|
extraContent: tabBarExtraContent,
|
|
|
|
prevIcon,
|
|
|
|
nextIcon,
|
2018-12-12 13:31:18 +00:00
|
|
|
style: tabBarStyle,
|
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
|
|
|
|
|
|
|
if (renderTabBar) {
|
2020-06-24 08:07:03 +00:00
|
|
|
return renderTabBar({ ...renderProps, DefaultTabBar: ScrollableInkTabBar });
|
2018-12-12 13:31:18 +00:00
|
|
|
} else {
|
2020-04-29 03:35:25 +00:00
|
|
|
return <ScrollableInkTabBar {...renderProps} />;
|
2018-12-12 13:31:18 +00:00
|
|
|
}
|
|
|
|
},
|
2020-10-13 09:46:31 +00:00
|
|
|
});
|
2018-12-12 13:31:18 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default TabBar;
|