2023-04-23 15:42:36 +08:00
|
|
|
import * as React from 'react';
|
2024-04-08 14:04:08 +08:00
|
|
|
import { Provider as MotionProvider } from 'rc-motion';
|
|
|
|
|
2023-04-23 15:42:36 +08:00
|
|
|
import { useToken } from '../theme/internal';
|
|
|
|
|
|
|
|
export interface MotionWrapperProps {
|
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function MotionWrapper(props: MotionWrapperProps): React.ReactElement {
|
|
|
|
const { children } = props;
|
|
|
|
const [, token] = useToken();
|
|
|
|
const { motion } = token;
|
|
|
|
|
|
|
|
const needWrapMotionProviderRef = React.useRef(false);
|
|
|
|
needWrapMotionProviderRef.current = needWrapMotionProviderRef.current || motion === false;
|
|
|
|
|
|
|
|
if (needWrapMotionProviderRef.current) {
|
|
|
|
return <MotionProvider motion={motion}>{children}</MotionProvider>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return children as React.ReactElement;
|
|
|
|
}
|