mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 12:09:14 +08:00
6b1a48d5ed
This reverts commit40433f357d
, reversing changes made to27a498e021
.
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { CSSMotionProps, MotionEventHandler, MotionEndEventHandler } from 'rc-motion';
|
|
import { MotionEvent } from 'rc-motion/lib/interface';
|
|
|
|
// ================== Collapse Motion ==================
|
|
const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 });
|
|
const getRealHeight: MotionEventHandler = node => {
|
|
const { scrollHeight } = node;
|
|
return { height: scrollHeight, opacity: 1 };
|
|
};
|
|
const getCurrentHeight: MotionEventHandler = node => ({ height: node ? node.offsetHeight : 0 });
|
|
const skipOpacityTransition: MotionEndEventHandler = (_, event: MotionEvent) =>
|
|
event?.deadline === true || (event as TransitionEvent).propertyName === 'height';
|
|
|
|
const collapseMotion: CSSMotionProps = {
|
|
motionName: 'ant-motion-collapse',
|
|
onAppearStart: getCollapsedHeight,
|
|
onEnterStart: getCollapsedHeight,
|
|
onAppearActive: getRealHeight,
|
|
onEnterActive: getRealHeight,
|
|
onLeaveStart: getCurrentHeight,
|
|
onLeaveActive: getCollapsedHeight,
|
|
onAppearEnd: skipOpacityTransition,
|
|
onEnterEnd: skipOpacityTransition,
|
|
onLeaveEnd: skipOpacityTransition,
|
|
motionDeadline: 500,
|
|
};
|
|
|
|
const getTransitionName = (rootPrefixCls: string, motion: string, transitionName?: string) => {
|
|
if (transitionName !== undefined) {
|
|
return transitionName;
|
|
}
|
|
return `${rootPrefixCls}-${motion}`;
|
|
};
|
|
export { getTransitionName };
|
|
export default collapseMotion;
|