|
|
@ -1,36 +1,14 @@ |
|
|
|
import * as React from 'react'; |
|
|
|
|
|
|
|
type MotionFunc = (element: HTMLElement) => React.CSSProperties; |
|
|
|
type MotionEndFunc = (element: HTMLElement, event: TransitionEvent) => boolean; |
|
|
|
|
|
|
|
interface Motion { |
|
|
|
visible?: boolean; |
|
|
|
motionName?: string; // It also support object, but we only use string here.
|
|
|
|
motionAppear?: boolean; |
|
|
|
motionEnter?: boolean; |
|
|
|
motionLeave?: boolean; |
|
|
|
motionLeaveImmediately?: boolean; // Trigger leave motion immediately
|
|
|
|
motionDeadline?: number; |
|
|
|
removeOnLeave?: boolean; |
|
|
|
leavedClassName?: string; |
|
|
|
onAppearStart?: MotionFunc; |
|
|
|
onAppearActive?: MotionFunc; |
|
|
|
onAppearEnd?: MotionEndFunc; |
|
|
|
onEnterStart?: MotionFunc; |
|
|
|
onEnterActive?: MotionFunc; |
|
|
|
onEnterEnd?: MotionEndFunc; |
|
|
|
onLeaveStart?: MotionFunc; |
|
|
|
onLeaveActive?: MotionFunc; |
|
|
|
onLeaveEnd?: MotionEndFunc; |
|
|
|
} |
|
|
|
import { CSSMotionProps } from 'rc-motion'; |
|
|
|
import { MotionEventHandler, MotionEndEventHandler } from 'rc-motion/lib/CSSMotion'; |
|
|
|
|
|
|
|
// ================== Collapse Motion ==================
|
|
|
|
const getCollapsedHeight: MotionFunc = () => ({ height: 0, opacity: 0 }); |
|
|
|
const getRealHeight: MotionFunc = node => ({ height: node.scrollHeight, opacity: 1 }); |
|
|
|
const getCurrentHeight: MotionFunc = node => ({ height: node.offsetHeight }); |
|
|
|
const skipOpacityTransition: MotionEndFunc = (_, event) => event.propertyName === 'height'; |
|
|
|
const getCollapsedHeight: MotionEventHandler = () => ({ height: 0, opacity: 0 }); |
|
|
|
const getRealHeight: MotionEventHandler = node => ({ height: node.scrollHeight, opacity: 1 }); |
|
|
|
const getCurrentHeight: MotionEventHandler = node => ({ height: node.offsetHeight }); |
|
|
|
const skipOpacityTransition: MotionEndEventHandler = (_, event) => |
|
|
|
(event as TransitionEvent).propertyName === 'height'; |
|
|
|
|
|
|
|
const collapseMotion: Motion = { |
|
|
|
const collapseMotion: CSSMotionProps = { |
|
|
|
motionName: 'ant-motion-collapse', |
|
|
|
onAppearStart: getCollapsedHeight, |
|
|
|
onEnterStart: getCollapsedHeight, |
|
|
|