2022-11-02 16:25:28 +08:00
|
|
|
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';
|
2022-11-03 00:43:26 +08:00
|
|
|
import PurePanel from './PurePanel';
|
2022-11-02 16:25:28 +08:00
|
|
|
|
2022-12-30 17:23:39 +08:00
|
|
|
const Tour: React.FC<TourProps> & { _InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel } = (
|
|
|
|
props,
|
|
|
|
) => {
|
2022-11-02 16:25:28 +08:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
hashId,
|
|
|
|
rootClassName,
|
|
|
|
);
|
|
|
|
|
|
|
|
const mergedRenderPanel = (stepProps: TourStepProps, stepCurrent: number) =>
|
|
|
|
panelRender(stepProps, stepCurrent, type);
|
|
|
|
|
|
|
|
return wrapSSR(
|
|
|
|
<RCTour
|
|
|
|
{...restProps}
|
|
|
|
rootClassName={customClassName}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
steps={steps}
|
|
|
|
current={current}
|
2022-11-10 22:30:48 +08:00
|
|
|
animated
|
2022-11-02 16:25:28 +08:00
|
|
|
renderPanel={mergedRenderPanel}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
Tour.displayName = 'Tour';
|
|
|
|
}
|
|
|
|
|
2022-11-03 00:43:26 +08:00
|
|
|
Tour._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
|
|
|
|
2022-11-02 16:25:28 +08:00
|
|
|
export default Tour;
|