2022-11-02 16:25:28 +08:00
|
|
|
import RCTour from '@rc-component/tour';
|
|
|
|
import classNames from 'classnames';
|
2023-02-07 23:36:52 +08:00
|
|
|
import React, { useContext } from 'react';
|
2022-11-02 16:25:28 +08:00
|
|
|
import type { ConfigConsumerProps } from '../config-provider';
|
|
|
|
import { ConfigContext } from '../config-provider';
|
2023-01-19 11:21:05 +08:00
|
|
|
import theme from '../theme';
|
|
|
|
import getPlacements from '../_util/placements';
|
2023-02-07 23:36:52 +08:00
|
|
|
import type { TourProps, TourStepProps } from './interface';
|
2023-02-13 14:30:08 +08:00
|
|
|
import TourPanel from './panelRender';
|
2023-02-07 23:36:52 +08:00
|
|
|
import PurePanel from './PurePanel';
|
|
|
|
import useStyle from './style';
|
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,
|
2023-02-07 23:36:52 +08:00
|
|
|
indicatorsRender,
|
2022-11-02 16:25:28 +08:00
|
|
|
...restProps
|
|
|
|
} = props;
|
|
|
|
const { getPrefixCls, direction } = useContext<ConfigConsumerProps>(ConfigContext);
|
|
|
|
const prefixCls = getPrefixCls('tour', customizePrefixCls);
|
|
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
2023-01-19 11:21:05 +08:00
|
|
|
const { token } = theme.useToken();
|
|
|
|
|
|
|
|
const builtinPlacements = getPlacements({
|
|
|
|
arrowPointAtCenter: true,
|
|
|
|
autoAdjustOverflow: true,
|
|
|
|
offset: token.marginXXS,
|
|
|
|
arrowWidth: token.sizePopupArrow,
|
2023-02-15 10:21:28 +08:00
|
|
|
borderRadius: token.borderRadius,
|
2023-01-19 11:21:05 +08:00
|
|
|
});
|
2022-11-02 16:25:28 +08:00
|
|
|
|
|
|
|
const customClassName = classNames(
|
|
|
|
{
|
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
|
|
},
|
|
|
|
hashId,
|
|
|
|
rootClassName,
|
|
|
|
);
|
|
|
|
|
2023-02-13 14:30:08 +08:00
|
|
|
const mergedRenderPanel = (stepProps: TourStepProps, stepCurrent: number): React.ReactNode => (
|
|
|
|
<TourPanel
|
|
|
|
type={type}
|
|
|
|
stepProps={stepProps}
|
|
|
|
current={stepCurrent}
|
|
|
|
indicatorsRender={indicatorsRender}
|
|
|
|
/>
|
|
|
|
);
|
2022-11-02 16:25:28 +08:00
|
|
|
|
|
|
|
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}
|
2023-01-19 11:21:05 +08:00
|
|
|
builtinPlacements={builtinPlacements}
|
2022-11-02 16:25:28 +08:00
|
|
|
/>,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|