2018-08-28 18:56:25 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
import ScrollableInkTabBar from 'rc-tabs/lib/ScrollableInkTabBar';
|
2018-11-23 13:39:33 +08:00
|
|
|
import classNames from 'classnames';
|
2020-03-02 12:09:38 +08:00
|
|
|
import UpOutlined from '@ant-design/icons/UpOutlined';
|
|
|
|
import LeftOutlined from '@ant-design/icons/LeftOutlined';
|
|
|
|
import DownOutlined from '@ant-design/icons/DownOutlined';
|
|
|
|
import RightOutlined from '@ant-design/icons/RightOutlined';
|
2019-08-13 14:07:17 +08:00
|
|
|
|
2018-08-28 18:56:25 +08:00
|
|
|
import { TabsProps } from './index';
|
2020-01-02 19:10:16 +08:00
|
|
|
import { ConfigConsumerProps, ConfigConsumer } from '../config-provider';
|
2018-08-28 18:56:25 +08:00
|
|
|
|
|
|
|
export default class TabBar extends React.Component<TabsProps> {
|
2018-11-23 13:39:33 +08:00
|
|
|
static defaultProps = {
|
|
|
|
animated: true,
|
|
|
|
type: 'line',
|
|
|
|
};
|
|
|
|
|
2020-01-02 19:10:16 +08:00
|
|
|
renderTabBar = ({ direction }: ConfigConsumerProps) => {
|
2018-08-28 18:56:25 +08:00
|
|
|
const {
|
|
|
|
tabBarStyle,
|
2018-11-23 13:39:33 +08:00
|
|
|
animated,
|
2018-08-28 18:56:25 +08:00
|
|
|
renderTabBar,
|
|
|
|
tabBarExtraContent,
|
|
|
|
tabPosition,
|
|
|
|
prefixCls,
|
2018-11-23 13:39:33 +08:00
|
|
|
className,
|
|
|
|
size,
|
|
|
|
type,
|
2018-08-28 18:56:25 +08:00
|
|
|
} = this.props;
|
|
|
|
const inkBarAnimated = typeof animated === 'object' ? animated.inkBar : animated;
|
|
|
|
|
|
|
|
const isVertical = tabPosition === 'left' || tabPosition === 'right';
|
2020-01-02 19:10:16 +08:00
|
|
|
let prevIconComponent = isVertical ? UpOutlined : LeftOutlined;
|
|
|
|
let nextIconComponent = isVertical ? DownOutlined : RightOutlined;
|
|
|
|
|
|
|
|
if (direction === 'rtl' && !isVertical) {
|
|
|
|
prevIconComponent = RightOutlined;
|
|
|
|
nextIconComponent = LeftOutlined;
|
|
|
|
}
|
2018-08-28 18:56:25 +08:00
|
|
|
const prevIcon = (
|
|
|
|
<span className={`${prefixCls}-tab-prev-icon`}>
|
2019-08-13 14:07:17 +08:00
|
|
|
{React.createElement(prevIconComponent, {
|
|
|
|
className: `${prefixCls}-tab-prev-icon-target`,
|
|
|
|
})}
|
2018-08-28 18:56:25 +08:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
const nextIcon = (
|
|
|
|
<span className={`${prefixCls}-tab-next-icon`}>
|
2019-08-13 14:07:17 +08:00
|
|
|
{React.createElement(nextIconComponent, {
|
|
|
|
className: `${prefixCls}-tab-next-icon-target`,
|
|
|
|
})}
|
2018-08-28 18:56:25 +08:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
|
2018-11-23 13:39:33 +08:00
|
|
|
// Additional className for style usage
|
|
|
|
const cls: string = classNames(
|
|
|
|
`${prefixCls}-${tabPosition}-bar`,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-${size}-bar`]: !!size,
|
|
|
|
[`${prefixCls}-card-bar`]: type && type.indexOf('card') >= 0,
|
|
|
|
},
|
|
|
|
className,
|
|
|
|
);
|
|
|
|
|
2018-08-28 18:56:25 +08:00
|
|
|
const renderProps = {
|
|
|
|
...this.props,
|
2019-01-16 20:00:23 +08:00
|
|
|
children: null,
|
2018-08-28 18:56:25 +08:00
|
|
|
inkBarAnimated,
|
|
|
|
extraContent: tabBarExtraContent,
|
|
|
|
style: tabBarStyle,
|
|
|
|
prevIcon,
|
|
|
|
nextIcon,
|
2018-11-23 13:39:33 +08:00
|
|
|
className: cls,
|
2018-08-28 18:56:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
let RenderTabBar: React.ReactElement<any>;
|
|
|
|
|
|
|
|
if (renderTabBar) {
|
|
|
|
RenderTabBar = renderTabBar(renderProps, ScrollableInkTabBar);
|
|
|
|
} else {
|
|
|
|
RenderTabBar = <ScrollableInkTabBar {...renderProps} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return React.cloneElement(RenderTabBar);
|
2020-01-02 19:10:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <ConfigConsumer>{this.renderTabBar}</ConfigConsumer>;
|
2018-08-28 18:56:25 +08:00
|
|
|
}
|
|
|
|
}
|