mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 06:09:34 +08:00
daa9804824
* feat: select components add placement api * feat: select components add placement api * fix: delete placement * fix: change md demo and delete export * feat: cascader and tree-select add placement * feat: datapicker add placement api * fix: change repeat static declaration to single * test: updata test units * doc: change doc * fix: delete merge message & delete decalare ts * test: fix unit test * fix: add transName in select & treeSelect & cascader * fix: change common api in utils * fix: change useless if block to only * fix: change placement string to enum * fix: lint done Co-authored-by: 礼检 <ljj337009@antgroup.com>
47 lines
1.8 KiB
TypeScript
47 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;
|