2020-09-02 18:30:27 +08:00
|
|
|
import { CSSMotionProps, MotionEventHandler, MotionEndEventHandler } from 'rc-motion';
|
2021-05-18 13:02:17 +08:00
|
|
|
import { MotionEvent } from 'rc-motion/lib/interface';
|
2019-05-06 12:04:39 +08:00
|
|
|
|
|
|
|
// ================== Collapse Motion ==================
|
2020-08-05 21:23:15 +08:00
|
|
|
const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 });
|
2021-06-04 14:44:41 +08:00
|
|
|
const getRealHeight: MotionEventHandler = node => {
|
|
|
|
const { scrollHeight } = node;
|
|
|
|
return { height: scrollHeight, opacity: 1 };
|
|
|
|
};
|
2021-08-18 11:40:44 +08:00
|
|
|
const getCurrentHeight: MotionEventHandler = node => ({ height: node ? node.offsetHeight : 0 });
|
2021-05-18 13:02:17 +08:00
|
|
|
const skipOpacityTransition: MotionEndEventHandler = (_, event: MotionEvent) =>
|
|
|
|
event?.deadline === true || (event as TransitionEvent).propertyName === 'height';
|
2020-07-01 15:41:55 +08:00
|
|
|
|
2020-08-05 21:23:15 +08:00
|
|
|
const collapseMotion: CSSMotionProps = {
|
2019-05-06 12:04:39 +08:00
|
|
|
motionName: 'ant-motion-collapse',
|
|
|
|
onAppearStart: getCollapsedHeight,
|
|
|
|
onEnterStart: getCollapsedHeight,
|
|
|
|
onAppearActive: getRealHeight,
|
|
|
|
onEnterActive: getRealHeight,
|
|
|
|
onLeaveStart: getCurrentHeight,
|
|
|
|
onLeaveActive: getCollapsedHeight,
|
2020-07-01 15:41:55 +08:00
|
|
|
onAppearEnd: skipOpacityTransition,
|
|
|
|
onEnterEnd: skipOpacityTransition,
|
|
|
|
onLeaveEnd: skipOpacityTransition,
|
2020-04-25 11:13:14 +08:00
|
|
|
motionDeadline: 500,
|
2019-05-06 12:04:39 +08:00
|
|
|
};
|
2019-08-05 18:38:10 +08:00
|
|
|
|
2021-02-08 17:09:13 +08:00
|
|
|
const getTransitionName = (rootPrefixCls: string, motion: string, transitionName?: string) => {
|
|
|
|
if (transitionName !== undefined) {
|
|
|
|
return transitionName;
|
|
|
|
}
|
|
|
|
return `${rootPrefixCls}-${motion}`;
|
|
|
|
};
|
|
|
|
export { getTransitionName };
|
2019-08-05 18:38:10 +08:00
|
|
|
export default collapseMotion;
|