mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
068584b76c
* chore: init * chore: init single * chore: merge next * chore: select single base * chore: basic all style of select * chore: speed of dropdown * chore: move size in single * chore: single size * chore: lg style * chore: left & right * chore: rtl * chore: auto rtl * chore: rtl * fix: height cal * chore: clean up * chore: status color
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
import { CSSMotionProps, MotionEventHandler, MotionEndEventHandler } from 'rc-motion';
|
|
import { MotionEvent } from 'rc-motion/lib/interface';
|
|
import { tuple } from './type';
|
|
|
|
// ================== 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 SelectPlacements = tuple('bottomLeft', 'bottomRight', 'topLeft', 'topRight');
|
|
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 collapseMotion;
|