2022-02-24 09:58:58 +08:00
|
|
|
import { nextTick } from 'vue';
|
2022-03-12 09:56:32 +08:00
|
|
|
import { addClass, removeClass } from '../vc-util/Dom/class';
|
|
|
|
import type { CSSMotionProps } from './transition';
|
2022-02-24 09:58:58 +08:00
|
|
|
|
2022-03-12 09:56:32 +08:00
|
|
|
const collapseMotion = (name = 'ant-motion-collapse', appear = true): CSSMotionProps => {
|
2022-02-24 09:58:58 +08:00
|
|
|
return {
|
|
|
|
name,
|
2022-03-12 09:56:32 +08:00
|
|
|
appear,
|
2022-02-24 09:58:58 +08:00
|
|
|
css: true,
|
|
|
|
onBeforeEnter: (node: HTMLDivElement) => {
|
|
|
|
node.style.height = '0px';
|
|
|
|
node.style.opacity = '0';
|
2022-03-02 14:05:33 +08:00
|
|
|
addClass(node, name);
|
2022-02-24 09:58:58 +08:00
|
|
|
},
|
|
|
|
onEnter: (node: HTMLDivElement) => {
|
|
|
|
nextTick(() => {
|
|
|
|
node.style.height = `${node.scrollHeight}px`;
|
|
|
|
node.style.opacity = '1';
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onAfterEnter: (node: HTMLDivElement) => {
|
2022-03-02 14:05:33 +08:00
|
|
|
if (node) {
|
|
|
|
removeClass(node, name);
|
|
|
|
node.style.height = null;
|
|
|
|
node.style.opacity = null;
|
|
|
|
}
|
2022-02-24 09:58:58 +08:00
|
|
|
},
|
|
|
|
onBeforeLeave: (node: HTMLDivElement) => {
|
|
|
|
addClass(node, name);
|
|
|
|
node.style.height = `${node.offsetHeight}px`;
|
2022-03-02 14:05:33 +08:00
|
|
|
node.style.opacity = null;
|
2022-02-24 09:58:58 +08:00
|
|
|
},
|
|
|
|
onLeave: (node: HTMLDivElement) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
node.style.height = '0px';
|
|
|
|
node.style.opacity = '0';
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onAfterLeave: (node: HTMLDivElement) => {
|
2022-03-02 14:05:33 +08:00
|
|
|
if (node) {
|
|
|
|
removeClass(node, name);
|
|
|
|
if (node.style) {
|
|
|
|
node.style.height = null;
|
|
|
|
node.style.opacity = null;
|
|
|
|
}
|
|
|
|
}
|
2022-02-24 09:58:58 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
2022-03-12 09:56:32 +08:00
|
|
|
export default collapseMotion;
|