2020-09-02 18:30:27 +08:00
|
|
|
import { CSSMotionProps, MotionEventHandler, MotionEndEventHandler } from 'rc-motion';
|
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 });
|
|
|
|
const getRealHeight: MotionEventHandler = node => ({ height: node.scrollHeight, opacity: 1 });
|
|
|
|
const getCurrentHeight: MotionEventHandler = node => ({ height: node.offsetHeight });
|
|
|
|
const skipOpacityTransition: MotionEndEventHandler = (_, event) =>
|
|
|
|
(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
|
|
|
|
|
|
|
export default collapseMotion;
|