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';
|
2018-08-28 18:56:25 +08:00
|
|
|
import { TabsProps } from './index';
|
2018-11-23 13:39:33 +08:00
|
|
|
import Icon from '../icon';
|
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',
|
|
|
|
};
|
|
|
|
|
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';
|
|
|
|
const prevIconType = isVertical ? 'up' : 'left';
|
|
|
|
const nextIconType = isVertical ? 'down' : 'right';
|
|
|
|
const prevIcon = (
|
|
|
|
<span className={`${prefixCls}-tab-prev-icon`}>
|
|
|
|
<Icon type={prevIconType} className={`${prefixCls}-tab-prev-icon-target`} />
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
const nextIcon = (
|
|
|
|
<span className={`${prefixCls}-tab-next-icon`}>
|
|
|
|
<Icon type={nextIconType} className={`${prefixCls}-tab-next-icon-target`} />
|
|
|
|
</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,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|