UNPKG

5.51 kBMarkdownView Raw
1## One more React Tree component
2
3> Most expected tree ui component for React.
4
5[![NPM version](https://img.shields.io/npm/v/eyzy-tree.svg?style=flat)](https://npmjs.com/package/eyzy-tree)
6![NPM license](https://img.shields.io/npm/l/eyzy-tree.svg?style=flat)
7[![NPM total downloads](https://img.shields.io/npm/dt/eyzy-tree.svg?style=flat)](https://npmcharts.com/compare/eyzy-tree?minimal=true)
8[![NPM monthly downloads](https://img.shields.io/npm/dm/eyzy-tree.svg?style=flat)](https://npmcharts.com/compare/eyzy-tree?minimal=true)
9
10[Documentation](https://eyzy.gitbook.io/tree/) | [Examples](https://eyzy.gitbook.io/tree/examples)
11
12![assets_-LIk7qYrBMivIw5dM3CP_-LXrbHDPWExqQURbPB5D_-LXrfVI_P7Wt8GJVXrVe_red](https://user-images.githubusercontent.com/1006120/57123062-0f878e80-6d89-11e9-8dac-d0b60e7710fb.png)
13
14
15### Features
16- flexible configuration
17- rich options
18- rich API
19- events for every action
20- keyboard navigation
21- check boxes
22- multi-selection
23- async support
24
25### Table of Contents
26- [Getting Started](#getting-started)
27- [Usage](#usage)
28- [Customization](#customization)
29- [Tree Props](#tree-props)
30- [Tree Events](#tree-events)
31- [Node Props](#node-props)
32
33### Getting Started
34
35Installing a package using the package manager.
36
37```sh
38# NPM
39npm install eyzy-tree
40
41# YARN
42yarn add eyzy-tree
43```
44
45Connect in browser.
46
47```html
48<script src="https://cdn.jsdelivr.net/npm/eyzy-tree/dist/eyzy-tree.min.js"></script>
49<link href="https://cdn.jsdelivr.net/npm/eyzy-tree/dist/style.css" rel="stylesheet" />
50```
51
52### Usage
53
54```javascript
55import React, { Component } from 'react'
56import EyzyTree from 'eyzy-tree'
57import 'eyzy-tree/style.css'
58
59export default class Tree extends Component {
60 constructor(props) {
61 super(props);
62
63 this.state = {
64 data: [
65 { text: 'Item 1' },
66 { text: 'Item 2' },
67 { text: 'Item 3' },
68 ],
69 };
70 }
71
72 render() {
73 return (
74 <div style={{ height: 400 }}>
75 <EyzyTree
76 data={this.state.data}
77 />
78 </div>
79 );
80 }
81}
82
83```
84
85### Customization
86[Click here](https://eyzy.gitbook.io/tree/customization) to find out how to configure the component.
87
88### Tree Props
89
90| Property | Type | Description | Default |
91|:---------|:--------|:-----------------|:-----|
92| `data` (required) | array | Specifies the tree nodes ||
93| `fetchData` | function | Fetch child node if it has `isBatch` property ||
94| `textRenderer` | ReactNode | Overrides `text container`. Gets the `Node` by argument ||
95| `arrowRenderer` | ReactNode | Overrides `arrow container`. Gets the `Node` by argument ||
96| `checkboxRenderer` | ReactNode | Overrides `checkbox container`. Gets the `Node` by argument ||
97| `checkable` | boolean | Adds a **checkbox** before the tree nodes | false |
98| `noCascade` | boolean | Whether to apply checkbox state to child nodes recursively | true |
99| `useIndeterminateState` | boolean | Whether to show `indeterminate` state for node | true |
100| `preventSelectParent` | boolean | Whether to allow to select node which has child (it will expand if `true`) | false |
101| `keyboardNavigation` | boolean | Whether to allow navigate via keyboard | true |
102| `selectOnExpand` | boolean | Whether to select a node if it has children | false |
103| `expandOnSelect` | boolean | Whether to expand a node if it has children | false |
104| `checkOnSelect` | boolean | Selects a node and changes the state of the checkbox. | false |
105| `selectOnCheck` | boolean | Whether to select a node if it checked (during the click) | false |
106| `theme` | string | Additional class for tree container. | eyzy-theme |
107
108
109### Tree Events
110
111| Property | Arguments | Description |
112|:---------|:--------|:-----------------|
113| `onReady` | [API](https://eyzy.gitbook.io/tree/api/basic) | Call once when tree is ready (componentDidMount). |
114| `onSelect` | `TreeNode` | Calls every time when node is selected. |
115| `onUnSelect` | `TreeNode` | Calls every time when node is unselected. |
116| `onCheck` | `TreeNode` | Calls every time when node is checked. |
117| `onExpand` | `TreeNode` | Calls every time when node is expanded. |
118| `onRemove` | `TreeNode` | Calls every time when node is removed. |
119| `onAdd` | `TreeNode` | Calls every time when node is added. |
120| `onDoubleClick` | `TreeNode` | Calls every time when user do double click on the node. Works only when `expandOnSelect` is not defined or false |
121
122
123### Node Props
124
125| Property | Type | Description |
126|:---------|:--------|:-----------------------------------------|
127| `id` | string | Node id. If not transmitted, automatically generated. |
128| `text` (required) | string | Node text |
129| `child` | Array<TreeNode> | List of child nodes |
130| `data` | object | Any type of data |
131| `isBatch` | boolean | Check the [API](https://app.gitbook.com/@eyzy/s/tree/guides/async) |
132| `className` | string | Node class name |
133| `checkable` | boolean | Whether to possible to check a node (checkbox will be hidden) |
134| `loading` | boolean | Will be added `loading` class (indicator is added via CSS) |
135| `selected` | boolean | Whether to select a node |
136| `expanded` | boolean | Whether to expand a node |
137| `checked` | boolean | Whether to check a node (if tree is checkable) |
138| `disabled` | boolean | Whether to disable a node |
139| `disabledCheckbox` | boolean | Whether to disable a node's checkbox |
140
141
142### Licence
143[MIT](https://opensource.org/licenses/MIT)