2022-03-08 10:29:00 +08:00
|
|
|
/* eslint-disable import/prefer-default-export */
|
2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSObject, Keyframes } from '@ant-design/cssinjs';
|
2022-03-08 10:29:00 +08:00
|
|
|
|
|
|
|
const initMotionCommon = (duration: string): CSSObject => ({
|
|
|
|
animationDuration: duration,
|
|
|
|
animationFillMode: 'both',
|
|
|
|
});
|
|
|
|
|
|
|
|
// FIXME: origin less code seems same as initMotionCommon. Maybe we can safe remove
|
|
|
|
const initMotionCommonLeave = (duration: string): CSSObject => ({
|
|
|
|
animationDuration: duration,
|
|
|
|
animationFillMode: 'both',
|
|
|
|
});
|
|
|
|
|
|
|
|
export const initMotion = (
|
2022-06-21 00:34:51 +08:00
|
|
|
motionCls: string,
|
2022-03-08 10:29:00 +08:00
|
|
|
inKeyframes: Keyframes,
|
|
|
|
outKeyframes: Keyframes,
|
|
|
|
duration: string,
|
2022-11-10 21:27:37 +08:00
|
|
|
sameLevel = false,
|
|
|
|
): CSSObject => {
|
|
|
|
const sameLevelPrefix = sameLevel ? '&' : '';
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-11-10 21:27:37 +08:00
|
|
|
return {
|
|
|
|
[`
|
|
|
|
${sameLevelPrefix}${motionCls}-enter,
|
|
|
|
${sameLevelPrefix}${motionCls}-appear
|
|
|
|
`]: {
|
|
|
|
...initMotionCommon(duration),
|
|
|
|
animationPlayState: 'paused',
|
|
|
|
},
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-11-10 21:27:37 +08:00
|
|
|
[`${sameLevelPrefix}${motionCls}-leave`]: {
|
|
|
|
...initMotionCommonLeave(duration),
|
|
|
|
animationPlayState: 'paused',
|
|
|
|
},
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-11-10 21:27:37 +08:00
|
|
|
[`
|
|
|
|
${sameLevelPrefix}${motionCls}-enter${motionCls}-enter-active,
|
|
|
|
${sameLevelPrefix}${motionCls}-appear${motionCls}-appear-active
|
|
|
|
`]: {
|
|
|
|
animationName: inKeyframes,
|
|
|
|
animationPlayState: 'running',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${sameLevelPrefix}${motionCls}-leave${motionCls}-leave-active`]: {
|
|
|
|
animationName: outKeyframes,
|
|
|
|
animationPlayState: 'running',
|
|
|
|
pointerEvents: 'none',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|