11# 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
88![ folder-tree-demo] ( /assets/folder-tree-demo.gif )
99
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/ )
1112
1213---
1314## Basic Usage
@@ -47,6 +48,7 @@ tree state is an object that looks like:
4748 url (optional): ' url of this node for example' ,
4849}
4950```
51+ This example shows how to render a tree with custom initial state
5052``` tsx
5153const treeState = {
5254 name: ' root [half checked and opened]' ,
@@ -93,11 +95,11 @@ const CustomInitState = () => (
9395
9496---
9597## 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.
98100
101+ This example shows how to download all selected files.
99102``` jsx
100- // this example shows how to download all selected files
101103const SuperApp = () => {
102104 const [treeState , setTreeState ] = useState (initState);
103105 const onTreeStateChange = state => setTreeState (state);
@@ -116,8 +118,8 @@ const SuperApp = () => {
116118};
117119```
118120
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.
121123- FileIcon
122124- FolderIcon
123125- FolderOpenIcon
@@ -128,20 +130,28 @@ there are 9 icons and all of them are customizable.
128130- CaretDownIcon
129131- OKIcon
130132
133+ This example shows how to customize the FileIcon (same interface for all other icons).
131134``` jsx
132- // this example shows how to customize the FileIcon
133- // all other icons have same interface
134135import { FaBitcoin } from ' react-icons/fa' ;
135136
136137const BitcoinApp = () => {
137138 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
140148 const handleClick = () => {
141- doSthBad ({ path, name });
149+ doSthBad ({ path, name, checked, isOpen, ... restData });
150+
142151 defaultOnClick ();
143152 };
144153
154+ // custom Style
145155 return < FaBitcoin onClick= { handleClick } / > ;
146156 };
147157
@@ -157,24 +167,23 @@ const BitcoinApp = () => {
157167};
158168```
159169
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.
162172``` tsx
163173const FileIcon = (... args ) => null ;
164174```
165175
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.
167178``` tsx
168- // this example shows how to download the file when click on the name
169-
170179const dataWithUrl = {
171180 name: ' secret crypto file' ,
172181 url: ' polkadot.network' , // wew can provide any custom data to the FolderTree!
173182 // ...
174183};
175184
176185const onNameClick = (defaultOnClick , nodeData ) => {
177- // defaultOnClick(); // don't need to call the default behavior
186+ defaultOnClick ();
178187
179188 const {
180189 // internal data
@@ -206,7 +215,7 @@ const Downloader = () => (
206215| iconComponents | custom icon components | object | ant design icons (default) |
207216| indentPixels | ident pixels of 1x level treenode | number | 30 (default) |
208217| 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) |
210219
211220---
212221## Bugs? Questions? Contributions?
0 commit comments