1
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
import React from 'react';
|
||||
declare const MotionContent: React.FC<React.PropsWithChildren>;
|
||||
export default MotionContent;
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
"use client";
|
||||
|
||||
import React from 'react';
|
||||
import CSSMotion from '@rc-component/motion';
|
||||
import { clsx } from 'clsx';
|
||||
import { cloneElement } from '../../_util/reactNode';
|
||||
import { ConfigContext } from '../../config-provider/context';
|
||||
const MotionContent = ({
|
||||
children
|
||||
}) => {
|
||||
const {
|
||||
getPrefixCls
|
||||
} = React.useContext(ConfigContext);
|
||||
const rootPrefixCls = getPrefixCls();
|
||||
// This will never reach since we will not render this when no children
|
||||
/* istanbul ignore next */
|
||||
if (! /*#__PURE__*/React.isValidElement(children)) {
|
||||
return children;
|
||||
}
|
||||
return /*#__PURE__*/React.createElement(CSSMotion, {
|
||||
visible: true,
|
||||
motionName: `${rootPrefixCls}-fade`,
|
||||
motionAppear: true,
|
||||
motionEnter: true,
|
||||
motionLeave: false,
|
||||
removeOnLeave: false
|
||||
}, ({
|
||||
style: motionStyle,
|
||||
className: motionClassName
|
||||
}) => {
|
||||
return cloneElement(children, oriProps => ({
|
||||
className: clsx(oriProps.className, motionClassName),
|
||||
style: {
|
||||
...oriProps.style,
|
||||
...motionStyle
|
||||
}
|
||||
}));
|
||||
});
|
||||
};
|
||||
export default MotionContent;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import React from 'react';
|
||||
declare const UniqueProvider: React.FC<React.PropsWithChildren>;
|
||||
export default UniqueProvider;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import React from 'react';
|
||||
import { UniqueProvider as RcUniqueProvider } from '@rc-component/trigger';
|
||||
import MotionContent from './MotionContent';
|
||||
const cachedPlacements = [null, null];
|
||||
function uniqueBuiltinPlacements(ori) {
|
||||
if (cachedPlacements[0] !== ori) {
|
||||
const target = {};
|
||||
Object.keys(ori).forEach(placement => {
|
||||
target[placement] = {
|
||||
...ori[placement],
|
||||
dynamicInset: false
|
||||
};
|
||||
});
|
||||
cachedPlacements[0] = ori;
|
||||
cachedPlacements[1] = target;
|
||||
}
|
||||
return cachedPlacements[1];
|
||||
}
|
||||
const UniqueProvider = ({
|
||||
children
|
||||
}) => {
|
||||
const renderPopup = options => {
|
||||
const {
|
||||
id,
|
||||
builtinPlacements,
|
||||
popup
|
||||
} = options;
|
||||
const popupEle = typeof popup === 'function' ? popup() : popup;
|
||||
const parsedPlacements = uniqueBuiltinPlacements(builtinPlacements);
|
||||
return {
|
||||
...options,
|
||||
getPopupContainer: null,
|
||||
arrow: false,
|
||||
popup: /*#__PURE__*/React.createElement(MotionContent, {
|
||||
key: id
|
||||
}, popupEle),
|
||||
builtinPlacements: parsedPlacements
|
||||
};
|
||||
};
|
||||
return /*#__PURE__*/React.createElement(RcUniqueProvider, {
|
||||
postTriggerProps: renderPopup
|
||||
}, children);
|
||||
};
|
||||
export default UniqueProvider;
|
||||
Reference in New Issue
Block a user