# react-power-tree

> Data and event driven tree view as react component

Latest version **0.0.21** (published 2019-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-power-tree
pnpm add react-power-tree
yarn add react-power-tree
bun add react-power-tree
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.21 |
| Published | 2019-07-11 |
| First published | 2019-05-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 67.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Naitian Liu |
| Maintainers | naitianliu |
| Keywords | react, tree, treeview, customization |

## Links

- npm: https://www.npmjs.com/package/react-power-tree
- Repository: https://github.com/naitianliu/react-power-tree
- Homepage: https://github.com/naitianliu/react-power-tree#readme
- Issues: https://github.com/naitianliu/react-power-tree/issues
- npm.io page: https://npm.io/package/react-power-tree

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [classnames](https://npm.io/package/classnames.md) ^2.2.6
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.21 (latest) — 2019-07-11
- 0.0.20 — 2019-07-11
- 0.0.19 — 2019-07-10
- 0.0.18 — 2019-05-31
- 0.0.17 — 2019-05-17
- 0.0.16 — 2019-05-14
- 0.0.14 — 2019-05-14
- 0.0.13 — 2019-05-13
- 0.0.12 — 2019-05-13
- 0.0.11 — 2019-05-13
- 0.0.10 — 2019-05-13
- 0.0.9 — 2019-05-13
- 0.0.8 — 2019-05-13
- 0.0.7 — 2019-05-13
- 0.0.6 — 2019-05-13
- … 5 more at https://npm.io/package/react-power-tree/versions

## README

# react-power-tree

![npm version](https://img.shields.io/npm/v/react-power-tree/latest.svg?registry_uri=https%3A%2F%2Fregistry.npmjs.com) ![stage](https://img.shields.io/badge/stage-alpha-red.svg) ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)

## Installation

```npm
npm install react-power-tree
```

Current version requires `react` and `material-ui` as dependencies. Please check `peerDependencies` in `package.json`. 

## Usage

```javascript
import PowerTree from 'react-power-tree';
```

Developers can choose to provide static data to render tree view or recursively add child nodes in dynamic way. 

### [Online Examples](https://naitianliu.github.io/react-power-tree/)

### Static tree view

```jsx harmony
<PowerTree
    data={data}
    options={options} // optional
    onNodeSelect={(nodeData) => {
        console.log(nodeData);
    }}
/>
```

### Attributes of node

| Key | Type | Required |  Detail |
|:---|:---|:---:|:---|
| name | `string` | Y | The name of child nodes with same parent node must be different from each other |
| children | `array` | N | Array of child node data |
| defaultExpanded | `boolean` | N | Default value is `false` |
| icon | `react component` | N | Default value is `directory` or `file` icon |

### Options

#### `contextMenu`

Popup when right clicking node. If null or empty, right click won't show the menu 

| Field | Type | Required | Details |
|:---|:---|:---:|:---|
| items | `array` | Y | menu items. keys: `icon`, `label` |
| onSelect | `func` | Y | `onSelect(label, nodeData) => {}` |

### Dynamic tree view

```jsx harmony
<PowerTree
    data={initData}
    options={options}
    onNodeSelect={(nodeData) => {
        console.log(nodeData)
    }}
    onNodeExpand={(nodeData, operations) => {
        const {addChildren} = operations;
        const childNodes = [...data];
        addChildren(childNodes);
    }}
/>
```

---
_Source: https://npm.io/package/react-power-tree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
