2019-05-06 12:04:39 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
type MotionFunc = (element: HTMLElement) => React.CSSProperties;
|
2020-07-01 15:41:55 +08:00
|
|
|
type MotionEndFunc = (element: HTMLElement, event: TransitionEvent) => boolean;
|
2019-05-06 12:04:39 +08:00
|
|
|
|
|
|
|
interface Motion {
|
|
|
|
visible?: boolean;
|
|
|
|
motionName?: string; // It also support object, but we only use string here.
|
|
|
|
motionAppear?: boolean;
|
|
|
|
motionEnter?: boolean;
|
|
|
|
motionLeave?: boolean;
|
|
|
|
motionLeaveImmediately?: boolean; // Trigger leave motion immediately
|
2020-04-25 11:13:14 +08:00
|
|
|
motionDeadline?: number;
|
2019-05-06 12:04:39 +08:00
|
|
|
removeOnLeave?: boolean;
|
|
|
|
leavedClassName?: string;
|
|
|
|
onAppearStart?: MotionFunc;
|
|
|
|
onAppearActive?: MotionFunc;
|
2020-07-01 15:41:55 +08:00
|
|
|
onAppearEnd?: MotionEndFunc;
|
2019-05-06 12:04:39 +08:00
|
|
|
onEnterStart?: MotionFunc;
|
|
|
|
onEnterActive?: MotionFunc;
|
2020-07-01 15:41:55 +08:00
|
|
|
onEnterEnd?: MotionEndFunc;
|
2019-05-06 12:04:39 +08:00
|
|
|
onLeaveStart?: MotionFunc;
|
|
|
|
onLeaveActive?: MotionFunc;
|
2020-07-01 15:41:55 +08:00
|
|
|
onLeaveEnd?: MotionEndFunc;
|
2019-05-06 12:04:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ================== Collapse Motion ==================
|
|
|
|
const getCollapsedHeight: MotionFunc = () => ({ height: 0, opacity: 0 });
|
|
|
|
const getRealHeight: MotionFunc = node => ({ height: node.scrollHeight, opacity: 1 });
|
|
|
|
const getCurrentHeight: MotionFunc = node => ({ height: node.offsetHeight });
|
|
|
|
|
2020-07-01 15:41:55 +08:00
|
|
|
function skipOpacityTransition(_: HTMLElement, event: TransitionEvent) {
|
|
|
|
return event.propertyName === 'height';
|
|
|
|
}
|
|
|
|
|
2019-08-05 18:38:10 +08:00
|
|
|
const collapseMotion: Motion = {
|
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;
|