mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 11:39:28 +08:00
c979850a5b
* test: ✅ test menu and collapse motion
* chore: move openAnimation into collapse
* add test case
* rm extra openAnimation.tsx
* remove unused code
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
/**
|
|
* Deprecated. We should replace the animation with pure react motion instead of modify style directly.
|
|
* If you are creating new component with animation, please use `./motion`.
|
|
*/
|
|
import cssAnimation from '@ant-design/css-animation';
|
|
import raf from 'raf';
|
|
|
|
function animate(node: HTMLElement, show: boolean, done: () => void) {
|
|
let height: number;
|
|
let requestAnimationFrameId: number;
|
|
return cssAnimation(node, 'ant-motion-collapse-legacy', {
|
|
start() {
|
|
if (!show) {
|
|
node.style.height = `${node.offsetHeight}px`;
|
|
node.style.opacity = '1';
|
|
} else {
|
|
height = node.offsetHeight;
|
|
node.style.height = '0px';
|
|
node.style.opacity = '0';
|
|
}
|
|
},
|
|
active() {
|
|
requestAnimationFrameId = raf(() => {
|
|
node.style.height = `${show ? height : 0}px`;
|
|
node.style.opacity = show ? '1' : '0';
|
|
});
|
|
},
|
|
end() {
|
|
if (requestAnimationFrameId) {
|
|
raf.cancel(requestAnimationFrameId);
|
|
}
|
|
node.style.height = '';
|
|
node.style.opacity = '';
|
|
done();
|
|
},
|
|
});
|
|
}
|
|
|
|
const animation = {
|
|
enter(node: HTMLElement, done: () => void) {
|
|
return animate(node, true, done);
|
|
},
|
|
leave(node: HTMLElement, done: () => void) {
|
|
return animate(node, false, done);
|
|
},
|
|
appear(node: HTMLElement, done: () => void) {
|
|
return animate(node, true, done);
|
|
},
|
|
};
|
|
|
|
export default animation;
|