|
1 | 1 | # React Sortable Tree
|
2 | 2 |
|
3 |
| -[](https://fritz-c.github.io/react-sortable-tree/) |
| 3 | +[](https://npmjs.org/package/react-sortable-tree) |
4 | 4 |
|
5 |
| -__Note: This is a work in progress; most of the features are not yet implemented.__ |
| 5 | +[](https://fritz-c.github.io/react-sortable-tree/) |
6 | 6 |
|
7 |
| -[DEMO](https://fritz-c.github.io/react-sortable-tree/) |
| 7 | +### [Demo](https://fritz-c.github.io/react-sortable-tree/) |
8 | 8 |
|
9 | 9 | ### Features
|
10 | 10 |
|
@@ -39,24 +39,33 @@ export default class Tree extends Component {
|
39 | 39 |
|
40 | 40 | Property | Type | Default | Required | Description
|
41 | 41 | :-------------------------|:--------------:|:-------------------:|:--------:|:----------------------------------------
|
42 |
| -treeData | object[] | | yes | Tree data in the following format: `[{title: 'main', subtitle: 'sub'}, { title: 'value2', expanded: true, children: [{ title: 'value3') }] }]`.<br>`title` is the primary label for the node<br>`subtitle` is a secondary label for the node `expanded` shows children of the node if true, or hides them if false. Defaults to false.<br>`children` is an array of child nodes belonging to the node. |
43 |
| -style | object | | {} | Style applied to the container wrapping the tree (style defaults to {height: '100%'}) |
44 |
| -className | string | | | Class name for the container wrapping the tree |
45 |
| -innerStyle | object | | {} | Style applied to the inner, scrollable container (for padding, etc.) |
46 |
| -rowHeight | number or func | `62` | | Used by react-virtualized Either a fixed row height (number) or a function that returns the height of a row given its index: `({ index: number }): number` |
47 |
| -reactVirtualizedListProps | object | | | Custom properties to hand to the [react-virtualized list](https://github.com/bvaughn/react-virtualized/blob/master/docs/List.md#prop-types) |
48 |
| -scaffoldBlockPxWidth | number | `44` | | The width of the blocks containing the lines representing the structure of the tree. |
49 |
| -maxDepth | number | | | Maximum depth nodes can be inserted at. Defaults to infinite. |
50 |
| -searchMethod | func | | | The method used to search nodes. Defaults to a function that uses the `searchQuery` string to search for nodes with matching `title` or `subtitle` values. NOTE: Changing `searchMethod` will not update the search, but changing the `searchQuery` will. |
51 |
| -searchQuery | any | | null | Used by the `searchMethod` to highlight and scroll to matched nodes. Should be a string for the default `searchMethod`, but can be anything when using a custom search. |
52 |
| -searchFocusOffset | number | | | Outline the <`searchFocusOffset`>th node and scroll to it. |
53 |
| -searchFinishCallback | func | | | Get the nodes that match the search criteria. Used for counting total matches, etc. |
54 |
| -generateNodeProps | func | | | Generate an object with additional props to be passed to the node renderer. Use this for adding buttons via the `buttons` key, or additional `style` / `className` settings. |
| 42 | +treeData | object[] | | yes | Tree data with the following keys: <div>`title` is the primary label for the node.</div><div>`subtitle` is a secondary label for the node.</div><div>`expanded` shows children of the node if true, or hides them if false. Defaults to false.</div><div>`children` is an array of child nodes belonging to the node.</div><div>__Example__: `[{title: 'main', subtitle: 'sub'}, { title: 'value2', expanded: true, children: [{ title: 'value3') }] }]` |
| 43 | +onChange | func | | yes | Called whenever tree data changed. Just like with React input elements, you have to update your own component's data to see the changes reflected.<div>`( treeData: object[] ): void`</div> |
| 44 | +style | object | `{}` | | Style applied to the container wrapping the tree (style defaults to {height: '100%'}) |
| 45 | +className | string | | | Class name for the container wrapping the tree |
| 46 | +innerStyle | object | `{}` | | Style applied to the inner, scrollable container (for padding, etc.) |
| 47 | +maxDepth | number | | | Maximum depth nodes can be inserted at. Defaults to infinite. |
| 48 | +searchMethod | func | | | The method used to search nodes. Defaults to a function that uses the `searchQuery` string to search for nodes with matching `title` or `subtitle` values. NOTE: Changing `searchMethod` will not update the search, but changing the `searchQuery` will.<div>`({ node: object, path: number[] or string[], treeIndex: number, searchQuery: any }): bool`</div> |
| 49 | +searchQuery | string or any | `null` | | Used by the `searchMethod` to highlight and scroll to matched nodes. Should be a string for the default `searchMethod`, but can be anything when using a custom search. |
| 50 | +searchFocusOffset | number | | | Outline the <`searchFocusOffset`>th node and scroll to it. |
| 51 | +searchFinishCallback | func | | | Get the nodes that match the search criteria. Used for counting total matches, etc.<div>`(matches: { node: object, path: number[] or string[], treeIndex: number }[]): void`</div> |
| 52 | +generateNodeProps | func | | | Generate an object with additional props to be passed to the node renderer. Use this for adding buttons via the `buttons` key, or additional `style` / `className` settings.<div>`({ node: object, path: number[] or string[], treeIndex: number, lowerSiblingCounts: number[], isSearchMatch: bool, isSearchFocus: bool }): object`</div> |
| 53 | +getNodeKey | func | defaultGetNodeKey | | Determine the unique key used to identify each node and generate the `path` array passed in callbacks. By default, returns the index in the tree (omitting hidden nodes).<div>`({ node: object, treeIndex: number }): string or number`</div> |
| 54 | +onMoveNode | func | | | Called after node move operation. <div>`({ treeData: object[], node: object }): void`</div> |
| 55 | +onVisibilityToggle | func | | | Called after children nodes collapsed or expanded. <div>`({ treeData: object[], node: object, expanded: bool }): void`</div> |
| 56 | +reactVirtualizedListProps | object | | | Custom properties to hand to the [react-virtualized list](https://github.com/bvaughn/react-virtualized/blob/master/docs/List.md#prop-types) |
| 57 | +rowHeight | number or func | `62` | | Used by react-virtualized. Either a fixed row height (number) or a function that returns the height of a row given its index: `({ index: number }): number` |
| 58 | +scaffoldBlockPxWidth | number | `44` | | The width of the blocks containing the lines representing the structure of the tree. |
55 | 59 | nodeContentRenderer | any | NodeRendererDefault | | Override the default component for rendering nodes (but keep the scaffolding generator) This is an advanced option for complete customization of the appearance. It is best to copy the component in `node-renderer-default.js` to use as a base, and customize as needed.
|
56 |
| -getNodeKey | func | defaultGetNodeKey | | Determine the unique key used to identify each node and generate the `path` array passed in callbacks. By default, returns the index in the tree (omitting hidden nodes). |
57 |
| -onChange | func | | yes | Called whenever tree data changed. Just like with React input elements, you have to update your own component's data to see the changes reflected. |
58 |
| -onMoveNode | func | | | Called after node move operation. |
59 |
| -onVisibilityToggle | func | | | Called after children nodes collapsed or expanded. |
| 60 | + |
| 61 | +## Browser Compatibility |
| 62 | + |
| 63 | +| Browser | Works? | |
| 64 | +|:-----|:-----| |
| 65 | +| Chrome | Yes | |
| 66 | +| Firefox | Yes, but [no auto-scroll on drag](https://github.com/fritz-c/react-sortable-tree/issues/3) | |
| 67 | +| Safari | Yes, but [no auto-scroll on drag](https://github.com/fritz-c/react-sortable-tree/issues/3) | |
| 68 | +| IE >= 9 | Yes, but [no auto-scroll on drag](https://github.com/fritz-c/react-sortable-tree/issues/3) | |
60 | 69 |
|
61 | 70 | ## Contributing
|
62 | 71 |
|
|
0 commit comments