2024-01-29 11:01:30 +08:00
|
|
|
import React, { useContext } from 'react';
|
2024-04-08 14:04:08 +08:00
|
|
|
import RCTour from '@rc-component/tour';
|
|
|
|
import type { TourProps as RcTourProps } from '@rc-component/tour';
|
2022-11-02 16:25:28 +08:00
|
|
|
import classNames from 'classnames';
|
2023-09-07 10:15:58 +08:00
|
|
|
|
2023-10-20 15:33:38 +08:00
|
|
|
import { useZIndex } from '../_util/hooks/useZIndex';
|
2023-04-19 13:13:50 +08:00
|
|
|
import getPlacements from '../_util/placements';
|
2023-10-20 15:33:38 +08:00
|
|
|
import zIndexContext from '../_util/zindexContext';
|
2022-11-02 16:25:28 +08:00
|
|
|
import type { ConfigConsumerProps } from '../config-provider';
|
|
|
|
import { ConfigContext } from '../config-provider';
|
2023-09-07 10:15:58 +08:00
|
|
|
import { useToken } from '../theme/internal';
|
2024-03-08 21:31:27 +08:00
|
|
|
import type { TourProps } from './interface';
|
2023-02-13 14:30:08 +08:00
|
|
|
import TourPanel from './panelRender';
|
2023-09-07 10:15:58 +08:00
|
|
|
import PurePanel from './PurePanel';
|
2023-02-07 23:36:52 +08:00
|
|
|
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,
|
|
|
|
type,
|
|
|
|
rootClassName,
|
2023-02-07 23:36:52 +08:00
|
|
|
indicatorsRender,
|
2023-04-19 13:13:50 +08:00
|
|
|
steps,
|
2024-03-08 21:31:27 +08:00
|
|
|
closeIcon,
|
2022-11-02 16:25:28 +08:00
|
|
|
...restProps
|
|
|
|
} = props;
|
2024-01-29 11:01:30 +08:00
|
|
|
const { getPrefixCls, direction, tour } = useContext<ConfigConsumerProps>(ConfigContext);
|
2022-11-02 16:25:28 +08:00
|
|
|
const prefixCls = getPrefixCls('tour', customizePrefixCls);
|
2023-12-14 14:58:53 +08:00
|
|
|
const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);
|
2023-09-07 10:15:58 +08:00
|
|
|
const [, token] = useToken();
|
2023-01-19 11:21:05 +08:00
|
|
|
|
2024-01-29 11:01:30 +08:00
|
|
|
const mergedSteps = React.useMemo<TourProps['steps']>(
|
2023-09-26 13:42:43 +08:00
|
|
|
() =>
|
|
|
|
steps?.map((step) => ({
|
|
|
|
...step,
|
|
|
|
className: classNames(step.className, {
|
|
|
|
[`${prefixCls}-primary`]: (step.type ?? type) === 'primary',
|
|
|
|
}),
|
|
|
|
})),
|
|
|
|
[steps, type],
|
|
|
|
);
|
2023-04-19 13:13:50 +08:00
|
|
|
|
2023-12-07 13:57:26 +08:00
|
|
|
const builtinPlacements: TourProps['builtinPlacements'] = (config) =>
|
|
|
|
getPlacements({
|
|
|
|
arrowPointAtCenter: config?.arrowPointAtCenter ?? true,
|
|
|
|
autoAdjustOverflow: true,
|
|
|
|
offset: token.marginXXS,
|
|
|
|
arrowWidth: token.sizePopupArrow,
|
|
|
|
borderRadius: token.borderRadius,
|
|
|
|
});
|
2022-11-02 16:25:28 +08:00
|
|
|
|
|
|
|
const customClassName = classNames(
|
|
|
|
{
|
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
|
|
},
|
|
|
|
hashId,
|
2023-12-14 14:58:53 +08:00
|
|
|
cssVarCls,
|
2022-11-02 16:25:28 +08:00
|
|
|
rootClassName,
|
|
|
|
);
|
|
|
|
|
2024-03-08 21:31:27 +08:00
|
|
|
const mergedRenderPanel: RcTourProps['renderPanel'] = (stepProps, stepCurrent) => (
|
2023-02-13 14:30:08 +08:00
|
|
|
<TourPanel
|
|
|
|
type={type}
|
|
|
|
stepProps={stepProps}
|
|
|
|
current={stepCurrent}
|
|
|
|
indicatorsRender={indicatorsRender}
|
|
|
|
/>
|
|
|
|
);
|
2022-11-02 16:25:28 +08:00
|
|
|
|
2023-10-20 15:33:38 +08:00
|
|
|
// ============================ zIndex ============================
|
|
|
|
const [zIndex, contextZIndex] = useZIndex('Tour', restProps.zIndex);
|
|
|
|
|
2023-11-08 14:56:15 +08:00
|
|
|
return wrapCSSVar(
|
2023-10-20 15:33:38 +08:00
|
|
|
<zIndexContext.Provider value={contextZIndex}>
|
|
|
|
<RCTour
|
|
|
|
{...restProps}
|
2024-03-08 21:31:27 +08:00
|
|
|
closeIcon={closeIcon ?? tour?.closeIcon}
|
2023-10-20 15:33:38 +08:00
|
|
|
zIndex={zIndex}
|
|
|
|
rootClassName={customClassName}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
animated
|
|
|
|
renderPanel={mergedRenderPanel}
|
|
|
|
builtinPlacements={builtinPlacements}
|
|
|
|
steps={mergedSteps}
|
|
|
|
/>
|
|
|
|
</zIndexContext.Provider>,
|
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;
|