adityasonel / react-animated-tree-v2

🌲 Simple to use, configurable tree view with full support for drop-in animations, react-animated-tree-v2.
https://adityasonel.github.io/react-animated-tree-v2
MIT License
11 stars 5 forks source link
react-spring reactjs

Build Status npm version

Port of react-animated-tree, with updated libraries, custom svg icons and many more new features.

npm install react-animated-tree-v2

A simple, configurable tree view control for React.

Demo: https://codesandbox.io/embed/react-animated-tree-v2-33u37

Customised icon demo: https://codesandbox.io/embed/react-animated-tree-v2-custom-icons-mz23x

import Tree from "react-animated-tree-v2";

<Tree
    content="Apple"
    type="Fruit"
    open
    canHide
    visible
    onClick={console.log}
    itemId={"apple"}
    onItemClick={(itemId) => console.log(itemId)}
>
    <Tree content="Contents">
        <Tree content="Seeds" />
    </Tree>
</Tree>;

Create your own effects by passing a react-spring config. The config below is the default (items fade in while moving in 20px from the right). You can go wild here by rotating, flipping, etc.

config = open => ({
  from: { height: 0, opacity: 0, transform: 'translate3d(20px,0,0)' },
  to: {
    height: open ? 'auto' : 0,
    opacity: open ? 1 : 0,
    transform: open ? 'translate3d(0px,0,0)' : 'translate3d(20px,0,0)',
  },
})

const SpecialTree = props => <Tree {...props} springConfig={config} />

<SpecialTree content="Orange">
  <SpecialTree content="Juice" />
</SpecialTree>