@@ -8,7 +8,7 @@ An tiny, accessible React Tree component with a sensible API that supports sorti
88
99### Demos
1010
11- - [ Simple demo] ( https://codesandbox.io/s/fervent-wave-u7psb?file=/src/App .tsx )
11+ - [ Simple demo] ( https://codesandbox.io/s/fervent-wave-u7psb?file=/src/file-browser/FileBrowser .tsx )
1212- Lazy children demo
1313- [ Journal example] ( https://github.com/mpkelly/Journal/blob/ab927cb481f60459d50a58012b89795aa33bfa47/packages/journal/src/features/collections-tree/CollectionsTree.tsx#L39 )
1414
@@ -26,10 +26,30 @@ An tiny, accessible React Tree component with a sensible API that supports sorti
2626- [x] Keyboard support, including navigating, selecting, copying/cutting and pasting
2727- [x] Implement W3C's [ Tree View accessibility specification] ( https://www.w3.org/TR/wai-aria-practices/#TreeView )
2828- [ ] Dropping at precise locations in target
29- - [ ] Performance testing and optimisation
3029
3130I wrote this for [ Journal] ( https://github.com/mpkelly/Journal ) , another side-project of mine, and didn't need to drop a precise locations but may add this in future.
3231
32+ ### Quick Start
33+
34+
35+
36+ ``` TypeScript
37+
38+ // Use `ScrollableTree` which wraps the `Tree` in a scroll container
39+ // but also fixes various scrolling/focusing quirks.
40+
41+ import {ScrollableTree as Tree } from " @mpkelly/react-tree" ;
42+
43+ < Tree
44+ nodes = {nodes }
45+ schema = {FileSystemSchema }
46+ renderElement = {renderElement }
47+ onChange = {handleChange }
48+ onPaste = {handlePaste }
49+ nameProperty = " name"
50+ / >
51+ ```
52+
3353### API
3454
3555#### Nodes
@@ -183,22 +203,7 @@ React Tree doesn't provide styling because it doesn't render anything visible by
183203
184204` ` `
185205
186- #### Mutating your state
187-
188- The ` onChange ` callback should look something like this:
189-
190- ` ` ` TypeScript
191- const handleChange = (
192- changed : FlatNode ,
193- property : keyof FlatNode ,
194- value : any
195- ) => {
196- const nextNode = {... node , [property ]:value };
197-
198- // call setState or whatever
199- handleNodeChange (nextNode );
200- };
201- ` ` `
206+ #### Deleting a node and all of its children
202207
203208React Tree also exports some utilities that can help you delete a ` FlatNode ` and its children. An example:
204209
@@ -225,4 +230,4 @@ if (result && result.node) {
225230
226231#### Tree
227232
228- View the full [Tree API](https://github.com/mpkelly/react-tree/blob/master/packages/react-tree/src/Tree.tsx). Note how most properties are optional.
233+ View the full [Tree API](https://github.com/mpkelly/react-tree/blob/master/packages/react-tree/src/Tree.tsx).
0 commit comments