2023-09-26 13:42:43 +08:00
|
|
|
import React, { useContext, useMemo } from 'react';
|
2022-11-02 16:25:28 +08:00
|
|
|
import RCTour from '@rc-component/tour';
|
|
|
|
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';
|
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-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,
|
2022-11-02 16:25:28 +08:00
|
|
|
...restProps
|
|
|
|
} = props;
|
|
|
|
const { getPrefixCls, direction } = useContext<ConfigConsumerProps>(ConfigContext);
|
|
|
|
const prefixCls = getPrefixCls('tour', customizePrefixCls);
|
2023-11-29 17:23:45 +08:00
|
|
|
const [wrapCSSVar, hashId] = useStyle(prefixCls);
|
2023-09-07 10:15:58 +08:00
|
|
|
const [, token] = useToken();
|
2023-01-19 11:21:05 +08:00
|
|
|
|
2023-09-26 13:42:43 +08:00
|
|
|
const mergedSteps = useMemo(
|
|
|
|
() =>
|
|
|
|
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-01-19 11:21:05 +08:00
|
|
|
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
|
|
|
|
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}
|
|
|
|
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;
|