42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
import { defaultPrefixCls } from '../config-provider';
|
|
import { isPlainObject } from './is';
|
|
// ================== Collapse Motion ==================
|
|
const getCollapsedHeight = () => ({
|
|
height: 0,
|
|
opacity: 0
|
|
});
|
|
const getRealHeight = node => ({
|
|
height: node?.scrollHeight ?? 0,
|
|
opacity: node ? 1 : 0
|
|
});
|
|
const getCurrentHeight = node => ({
|
|
height: node?.offsetHeight ?? 0
|
|
});
|
|
const isTransitionEvent = event => {
|
|
return isPlainObject(event) && 'propertyName' in event;
|
|
};
|
|
const skipOpacityTransition = (_, event) => {
|
|
return event?.deadline === true || (isTransitionEvent(event) ? event.propertyName === 'height' : false);
|
|
};
|
|
const initCollapseMotion = (rootCls = defaultPrefixCls) => ({
|
|
motionName: `${rootCls}-motion-collapse`,
|
|
onAppearStart: getCollapsedHeight,
|
|
onEnterStart: getCollapsedHeight,
|
|
onAppearActive: getRealHeight,
|
|
onEnterActive: getRealHeight,
|
|
onLeaveStart: getCurrentHeight,
|
|
onLeaveActive: getCollapsedHeight,
|
|
onAppearEnd: skipOpacityTransition,
|
|
onEnterEnd: skipOpacityTransition,
|
|
onLeaveEnd: skipOpacityTransition,
|
|
motionDeadline: 500
|
|
});
|
|
const _SelectPlacements = ['bottomLeft', 'bottomRight', 'topLeft', 'topRight'];
|
|
const getTransitionName = (rootPrefixCls, motion, transitionName) => {
|
|
if (transitionName !== undefined) {
|
|
return transitionName;
|
|
}
|
|
return `${rootPrefixCls}-${motion}`;
|
|
};
|
|
export { getTransitionName };
|
|
export default initCollapseMotion; |