1
1
# React Folder Tree
2
- A powerful and customizable react treeview library. It supports:
3
- - ✅ customizable icons
4
- - ✅ customizable callbacks
5
- - ✅ inline add, modify, and delete operations
6
- - ✅ checkbox with half check (indeterminate check) support
7
- ## Quick Preview
2
+ A versatile and customizable react treeview library. It supports:
3
+ - ✅ customize icons
4
+ - ✅ customize event handlers
5
+ - ✅ inline add, modify, and delete tree nodes
6
+ - ✅ checkbox with half check (indeterminate check)
7
+ ### Quick Preview
8
8
![ folder-tree-demo] ( /assets/folder-tree-demo.gif )
9
9
10
- live demos and code examples can be found [ HERE] ( https://shunjizhan.github.io/react-folder-tree-demos/ )
10
+ ### Live Demos
11
+ live demos and code examples can be found [ here] ( https://shunjizhan.github.io/react-folder-tree-demos/ )
11
12
12
13
---
13
14
## Basic Usage
@@ -47,6 +48,7 @@ tree state is an object that looks like:
47
48
url (optional): ' url of this node for example' ,
48
49
}
49
50
```
51
+ This example shows how to render a tree with custom initial state
50
52
``` tsx
51
53
const treeState = {
52
54
name: ' root [half checked and opened]' ,
@@ -93,11 +95,11 @@ const CustomInitState = () => (
93
95
94
96
---
95
97
## Advanced Usage
96
- ### 🌀 sync tree state
97
- in order to perform more complex operations, we can sync and keep track of the current tree state outside.
98
+ ### 🔥 sync tree state
99
+ In order to perform more complex operations, we can sync and keep track of the current tree state outside.
98
100
101
+ This example shows how to download all selected files.
99
102
``` jsx
100
- // this example shows how to download all selected files
101
103
const SuperApp = () => {
102
104
const [treeState , setTreeState ] = useState (initState);
103
105
const onTreeStateChange = state => setTreeState (state);
@@ -116,8 +118,8 @@ const SuperApp = () => {
116
118
};
117
119
```
118
120
119
- ### 🌀 custom icons
120
- there are 9 icons and all of them are customizable.
121
+ ### 🔥 custom icons
122
+ There are 9 icons and all of them are customizable.
121
123
- FileIcon
122
124
- FolderIcon
123
125
- FolderOpenIcon
@@ -128,20 +130,28 @@ there are 9 icons and all of them are customizable.
128
130
- CaretDownIcon
129
131
- OKIcon
130
132
133
+ This example shows how to customize the FileIcon (same interface for all other icons).
131
134
``` jsx
132
- // this example shows how to customize the FileIcon
133
- // all other icons have same interface
134
135
import { FaBitcoin } from ' react-icons/fa' ;
135
136
136
137
const BitcoinApp = () => {
137
138
const FileIcon = ({ onClick: defaultOnClick, nodeData }) => {
138
- const { path , name , ... restData } = nodeData;
139
-
139
+ const {
140
+ path ,
141
+ name ,
142
+ checked ,
143
+ isOpen ,
144
+ ... restData
145
+ } = nodeData;
146
+
147
+ // custom event handler
140
148
const handleClick = () => {
141
- doSthBad ({ path, name });
149
+ doSthBad ({ path, name, checked, isOpen, ... restData });
150
+
142
151
defaultOnClick ();
143
152
};
144
153
154
+ // custom Style
145
155
return < FaBitcoin onClick= { handleClick } / > ;
146
156
};
147
157
@@ -157,24 +167,23 @@ const BitcoinApp = () => {
157
167
};
158
168
```
159
169
160
- ### 🌀 disable icons
161
- this usage is a subset of custom icons. For example, to hide ` FileIcon ` we can simply pass in a dummy custom icon
170
+ ### 🔥 disable icons
171
+ This usage is a subset of custom icons. For example, to hide ` FileIcon ` we can simply pass in a dummy custom icon, so nothing will be rendered.
162
172
``` tsx
163
173
const FileIcon = (... args ) => null ;
164
174
```
165
175
166
- ### 🌀 custom ` onClick ` for node names
176
+ ### 🔥 custom ` onClick ` for node names
177
+ This example shows how to download the file when click on the node name.
167
178
``` tsx
168
- // this example shows how to download the file when click on the name
169
-
170
179
const dataWithUrl = {
171
180
name: ' secret crypto file' ,
172
181
url: ' polkadot.network' , // wew can provide any custom data to the FolderTree!
173
182
// ...
174
183
};
175
184
176
185
const onNameClick = (defaultOnClick , nodeData ) => {
177
- // defaultOnClick(); // don't need to call the default behavior
186
+ defaultOnClick ();
178
187
179
188
const {
180
189
// internal data
@@ -206,7 +215,7 @@ const Downloader = () => (
206
215
| iconComponents | custom icon components | object | ant design icons (default) |
207
216
| indentPixels | ident pixels of 1x level treenode | number | 30 (default) |
208
217
| showCheckbox | show check box? | bool | true (default) | false |
209
- | onNameClick | call back when click treenode text | function | open treenode inline toolbox (default) |
218
+ | onNameClick | callback when click treenode name | function | open treenode inline toolbox (default) |
210
219
211
220
---
212
221
## Bugs? Questions? Contributions?
0 commit comments