ant-design/components/style/motion/motion.tsx
MadCcc a106459dd1
feat: add zoom animation (#35148)
* feat: support Keyframes as 'animationName' value

* feat: add zoom animation

* chore: code clean

* test: fix anim

* chore: move file

* chore: dep clean
2022-04-21 17:28:02 +08:00

52 lines
1.2 KiB
TypeScript

/* eslint-disable import/prefer-default-export */
import { CSSObject, Keyframes } from '@ant-design/cssinjs';
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 = (
motionName: string,
inKeyframes: Keyframes,
outKeyframes: Keyframes,
duration: string,
): CSSObject => {
const motionCls = `.${motionName}`;
return {
[`
${motionCls}-enter,
${motionCls}-appear
`]: {
...initMotionCommon(duration),
animationPlayState: 'paused',
},
[`${motionCls}-leave`]: {
...initMotionCommonLeave(duration),
animationPlayState: 'paused',
},
[`
${motionCls}-enter${motionCls}-enter-active,
${motionCls}-appear${motionCls}-appear-active
`]: {
animationName: inKeyframes,
animationPlayState: 'running',
},
[`${motionCls}-leave${motionCls}-leave-active`]: {
animationName: outKeyframes,
animationPlayState: 'running',
pointerEvents: 'none',
},
};
};