-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathmotionUtil.ts
More file actions
25 lines (22 loc) · 903 Bytes
/
motionUtil.ts
File metadata and controls
25 lines (22 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import type {
CSSMotionProps,
MotionEndEventHandler,
MotionEventHandler,
} from '@rc-component/motion';
const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 });
const getRealHeight: MotionEventHandler = (node) => ({ height: node.scrollHeight, opacity: 1 });
const getCurrentHeight: MotionEventHandler = (node) => ({ height: node?.offsetHeight ?? 0 });
const skipOpacityTransition: MotionEndEventHandler = (_, event) =>
(event as TransitionEvent).propertyName === 'height';
const collapseMotion: CSSMotionProps = {
motionName: 'rc-collapse-motion',
onEnterStart: getCollapsedHeight,
onEnterActive: getRealHeight,
onLeaveStart: getCurrentHeight,
onLeaveActive: getCollapsedHeight,
onEnterEnd: skipOpacityTransition,
onLeaveEnd: skipOpacityTransition,
motionDeadline: 500,
leavedClassName: 'rc-collapse-panel-hidden',
};
export default collapseMotion;