You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.3 KiB
35 lines
1.3 KiB
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;
|
|
|