2023-07-15 12:57:03 +08:00
|
|
|
'use client';
|
|
|
|
|
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';
|
2023-04-19 13:13:50 +08:00
|
|
|
import getPlacements from '../_util/placements';
|
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';
|
2023-04-19 13:13:50 +08:00
|
|
|
import PurePanel from './PurePanel';
|
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 useStyle from './style';
|
2023-04-19 13:13:50 +08:00
|
|
|
import useMergedType from './useMergedType';
|
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,
|
|
|
|
current,
|
2023-04-19 13:13:50 +08:00
|
|
|
defaultCurrent,
|
2022-11-02 16:25:28 +08:00
|
|
|
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);
|
|
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
2023-01-19 11:21:05 +08:00
|
|
|
const { token } = theme.useToken();
|
|
|
|
|
2023-04-19 13:13:50 +08:00
|
|
|
const { currentMergedType, updateInnerCurrent } = useMergedType({
|
|
|
|
defaultType: type,
|
|
|
|
steps,
|
|
|
|
current,
|
|
|
|
defaultCurrent,
|
|
|
|
});
|
|
|
|
|
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(
|
|
|
|
{
|
2023-04-19 13:13:50 +08:00
|
|
|
[`${prefixCls}-primary`]: currentMergedType === 'primary',
|
2022-11-02 16:25:28 +08:00
|
|
|
[`${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-04-19 13:13:50 +08:00
|
|
|
const onStepChange = (stepCurrent: number) => {
|
|
|
|
updateInnerCurrent(stepCurrent);
|
|
|
|
props.onChange?.(stepCurrent);
|
|
|
|
};
|
|
|
|
|
2022-11-02 16:25:28 +08:00
|
|
|
return wrapSSR(
|
|
|
|
<RCTour
|
|
|
|
{...restProps}
|
|
|
|
rootClassName={customClassName}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
current={current}
|
2023-04-19 13:13:50 +08:00
|
|
|
defaultCurrent={defaultCurrent}
|
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}
|
2023-04-19 13:13:50 +08:00
|
|
|
onChange={onStepChange}
|
|
|
|
steps={steps}
|
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;
|