mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-25 19:50:05 +08:00
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
|
import React, { useContext } from 'react';
|
||
|
import RCTour from '@rc-component/tour';
|
||
|
import classNames from 'classnames';
|
||
|
import panelRender from './panelRender';
|
||
|
import type { ConfigConsumerProps } from '../config-provider';
|
||
|
import { ConfigContext } from '../config-provider';
|
||
|
import useStyle from './style';
|
||
|
import type { TourProps, TourStepProps } from './interface';
|
||
|
|
||
|
const Tour: React.ForwardRefRenderFunction<HTMLDivElement, TourProps> = props => {
|
||
|
const {
|
||
|
prefixCls: customizePrefixCls,
|
||
|
steps,
|
||
|
current,
|
||
|
type,
|
||
|
rootClassName,
|
||
|
...restProps
|
||
|
} = props;
|
||
|
const { getPrefixCls, direction } = useContext<ConfigConsumerProps>(ConfigContext);
|
||
|
const prefixCls = getPrefixCls('tour', customizePrefixCls);
|
||
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
||
|
|
||
|
const customClassName = classNames(
|
||
|
{
|
||
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
||
|
},
|
||
|
{
|
||
|
[`${prefixCls}-primary`]: type === 'primary',
|
||
|
},
|
||
|
hashId,
|
||
|
rootClassName,
|
||
|
);
|
||
|
|
||
|
const mergedRenderPanel = (stepProps: TourStepProps, stepCurrent: number) =>
|
||
|
panelRender(stepProps, stepCurrent, type);
|
||
|
|
||
|
return wrapSSR(
|
||
|
<RCTour
|
||
|
{...restProps}
|
||
|
rootClassName={customClassName}
|
||
|
prefixCls={prefixCls}
|
||
|
steps={steps}
|
||
|
current={current}
|
||
|
renderPanel={mergedRenderPanel}
|
||
|
/>,
|
||
|
);
|
||
|
};
|
||
|
|
||
|
if (process.env.NODE_ENV !== 'production') {
|
||
|
Tour.displayName = 'Tour';
|
||
|
}
|
||
|
|
||
|
export default Tour;
|