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';
|
2019-08-13 14:07:17 +08:00
|
|
|
import { Up, Left, Down, Right } from '@ant-design/icons';
|
|
|
|
|
2018-08-28 18:56:25 +08:00
|
|
|
import { TabsProps } from './index';
|
|
|
|
|
|
|
|
export default class TabBar extends React.Component<TabsProps> {
|
2018-11-23 13:39:33 +08:00
|
|
|
static defaultProps = {
|
|
|
|
animated: true,
|
|
|
|
type: 'line',
|
|
|
|
};
|
|
|
|
|
2018-08-28 18:56:25 +08:00
|
|
|
render() {
|
|
|
|
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';
|
2019-08-13 14:07:17 +08:00
|
|
|
const prevIconComponent = isVertical ? Up : Left;
|
|
|
|
const nextIconComponent = isVertical ? Down : Right;
|
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);
|
|
|
|
}
|
|
|
|
}
|