mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
26555fcd12
* fix: tour arrow color * test: updte * fix: duplicate class name * test: update snapshot * chore: speedup * fix: update current step props by onChange * chore: optimization * fix: props.current may change * chore: save * test: coverage * chore: optimization * chore: add useMergedType * chore: save * chore: optimization * chore: optimization * chore: optimization * chore: move file * refactor: useMergedType hook * chore: save * chore: optimization * test: ci * chore: remove useMemo * chore: use nullish coalescing operator * chore: rename setInnerCurrent to updateInnerCurrent
93 lines
2.4 KiB
TypeScript
93 lines
2.4 KiB
TypeScript
import RCTour from '@rc-component/tour';
|
|
import classNames from 'classnames';
|
|
import React, { useContext } from 'react';
|
|
import getPlacements from '../_util/placements';
|
|
import type { ConfigConsumerProps } from '../config-provider';
|
|
import { ConfigContext } from '../config-provider';
|
|
import theme from '../theme';
|
|
import PurePanel from './PurePanel';
|
|
import type { TourProps, TourStepProps } from './interface';
|
|
import TourPanel from './panelRender';
|
|
import useStyle from './style';
|
|
import useMergedType from './useMergedType';
|
|
|
|
const Tour: React.FC<TourProps> & { _InternalPanelDoNotUseOrYouWillBeFired: typeof PurePanel } = (
|
|
props,
|
|
) => {
|
|
const {
|
|
prefixCls: customizePrefixCls,
|
|
current,
|
|
defaultCurrent,
|
|
type,
|
|
rootClassName,
|
|
indicatorsRender,
|
|
steps,
|
|
...restProps
|
|
} = props;
|
|
const { getPrefixCls, direction } = useContext<ConfigConsumerProps>(ConfigContext);
|
|
const prefixCls = getPrefixCls('tour', customizePrefixCls);
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
|
const { token } = theme.useToken();
|
|
|
|
const { currentMergedType, updateInnerCurrent } = useMergedType({
|
|
defaultType: type,
|
|
steps,
|
|
current,
|
|
defaultCurrent,
|
|
});
|
|
|
|
const builtinPlacements = getPlacements({
|
|
arrowPointAtCenter: true,
|
|
autoAdjustOverflow: true,
|
|
offset: token.marginXXS,
|
|
arrowWidth: token.sizePopupArrow,
|
|
borderRadius: token.borderRadius,
|
|
});
|
|
|
|
const customClassName = classNames(
|
|
{
|
|
[`${prefixCls}-primary`]: currentMergedType === 'primary',
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
},
|
|
hashId,
|
|
rootClassName,
|
|
);
|
|
|
|
const mergedRenderPanel = (stepProps: TourStepProps, stepCurrent: number): React.ReactNode => (
|
|
<TourPanel
|
|
type={type}
|
|
stepProps={stepProps}
|
|
current={stepCurrent}
|
|
indicatorsRender={indicatorsRender}
|
|
/>
|
|
);
|
|
|
|
const onStepChange = (stepCurrent: number) => {
|
|
updateInnerCurrent(stepCurrent);
|
|
props.onChange?.(stepCurrent);
|
|
};
|
|
|
|
return wrapSSR(
|
|
<RCTour
|
|
{...restProps}
|
|
rootClassName={customClassName}
|
|
prefixCls={prefixCls}
|
|
current={current}
|
|
defaultCurrent={defaultCurrent}
|
|
animated
|
|
renderPanel={mergedRenderPanel}
|
|
builtinPlacements={builtinPlacements}
|
|
onChange={onStepChange}
|
|
steps={steps}
|
|
/>,
|
|
);
|
|
};
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
Tour.displayName = 'Tour';
|
|
}
|
|
|
|
Tour._InternalPanelDoNotUseOrYouWillBeFired = PurePanel;
|
|
|
|
export default Tour;
|