2018-04-11 13:25:16 +00:00
|
|
|
<script>
|
|
|
|
/* eslint no-console:0 */
|
2019-01-12 03:33:27 +00:00
|
|
|
import Tree, { TreeNode } from '../index';
|
|
|
|
import '../assets/index.less';
|
|
|
|
import cssAnimation from '../../_util/css-animation';
|
2018-04-11 13:25:16 +00:00
|
|
|
|
2019-09-28 12:45:07 +00:00
|
|
|
function animate(node, show, done) {
|
2019-01-12 03:33:27 +00:00
|
|
|
let height = node.offsetHeight;
|
2018-04-11 13:25:16 +00:00
|
|
|
return cssAnimation(node, 'collapse', {
|
2019-09-28 12:45:07 +00:00
|
|
|
start() {
|
2018-04-11 13:25:16 +00:00
|
|
|
if (!show) {
|
2019-01-12 03:33:27 +00:00
|
|
|
node.style.height = `${node.offsetHeight}px`;
|
2018-04-11 13:25:16 +00:00
|
|
|
} else {
|
2019-01-12 03:33:27 +00:00
|
|
|
height = node.offsetHeight;
|
|
|
|
node.style.height = 0;
|
2018-04-11 13:25:16 +00:00
|
|
|
}
|
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
active() {
|
2019-01-12 03:33:27 +00:00
|
|
|
node.style.height = `${show ? height : 0}px`;
|
2018-04-11 13:25:16 +00:00
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
end() {
|
2019-01-12 03:33:27 +00:00
|
|
|
node.style.height = '';
|
|
|
|
done();
|
2018-04-11 13:25:16 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-04-11 13:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const animation = {
|
2019-09-28 12:45:07 +00:00
|
|
|
enter(node, done) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return animate(node, true, done);
|
2018-04-11 13:25:16 +00:00
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
leave(node, done) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return animate(node, false, done);
|
2018-04-11 13:25:16 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-11 13:25:16 +00:00
|
|
|
export default {
|
2019-09-28 12:45:07 +00:00
|
|
|
render() {
|
2018-04-11 13:25:16 +00:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h2>expanded</h2>
|
|
|
|
<Tree
|
|
|
|
defaultExpandAll={false}
|
|
|
|
defaultExpandedKeys={['p1']}
|
2019-09-28 12:45:07 +00:00
|
|
|
openAnimation={{ on: animation, props: { appear: true } }}
|
2018-04-11 13:25:16 +00:00
|
|
|
>
|
2019-09-28 12:45:07 +00:00
|
|
|
<TreeNode title="parent 1" key="p1">
|
|
|
|
<TreeNode key="p10" title="leaf" />
|
|
|
|
<TreeNode title="parent 1-1" key="p11">
|
|
|
|
<TreeNode title="parent 2-1" key="p21">
|
|
|
|
<TreeNode title="leaf" />
|
|
|
|
<TreeNode title="leaf" />
|
2018-04-11 13:25:16 +00:00
|
|
|
</TreeNode>
|
2019-09-28 12:45:07 +00:00
|
|
|
<TreeNode key="p22" title="leaf" />
|
2018-04-11 13:25:16 +00:00
|
|
|
</TreeNode>
|
|
|
|
</TreeNode>
|
|
|
|
</Tree>
|
|
|
|
</div>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-04-11 13:25:16 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-11 13:25:16 +00:00
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
.collapse {
|
|
|
|
overflow: hidden;
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.collapse-active {
|
|
|
|
transition: height 0.3s ease-out;
|
|
|
|
}
|
|
|
|
</style>
|