ant-design/components/_util/motion.tsx
lijianan 12543277b7
type: remove tuple、tupleNum、ElementOf (#39478)
* type: remove tuple

* type: remove tuple

* type: remove tuple

* fix

* fix

* fix type

* fix type

* fix type

* fix type

* fix type

* Update ColorPicker.tsx

* Update components/badge/utils.tsx

Co-authored-by: MadCcc <1075746765@qq.com>

* fix type

* fix type

* fix type

* fix

* fix

* fix type

* fix type

* fix type

* update snap

* update snap

Co-authored-by: MadCcc <1075746765@qq.com>
2022-12-13 14:57:40 +08:00

48 lines
1.8 KiB
TypeScript

import type { CSSMotionProps, MotionEndEventHandler, MotionEventHandler } from 'rc-motion';
import type { 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 initCollapseMotion = (rootCls: string = 'ant'): CSSMotionProps => ({
motionName: `${rootCls}-motion-collapse`,
onAppearStart: getCollapsedHeight,
onEnterStart: getCollapsedHeight,
onAppearActive: getRealHeight,
onEnterActive: getRealHeight,
onLeaveStart: getCurrentHeight,
onLeaveActive: getCollapsedHeight,
onAppearEnd: skipOpacityTransition,
onEnterEnd: skipOpacityTransition,
onLeaveEnd: skipOpacityTransition,
motionDeadline: 500,
});
const SelectPlacements = ['bottomLeft', 'bottomRight', 'topLeft', 'topRight'] as const;
export type SelectCommonPlacement = typeof SelectPlacements[number];
const getTransitionDirection = (placement: SelectCommonPlacement | undefined) => {
if (placement !== undefined && (placement === 'topLeft' || placement === 'topRight')) {
return `slide-down`;
}
return `slide-up`;
};
const getTransitionName = (rootPrefixCls: string, motion: string, transitionName?: string) => {
if (transitionName !== undefined) {
return transitionName;
}
return `${rootPrefixCls}-${motion}`;
};
export { getTransitionName, getTransitionDirection };
export default initCollapseMotion;