Skip to content

Commit c423344

Browse files
authored
chore: update tree util docs (#356)
1 parent 91b214b commit c423344

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

README.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,33 @@
1111
[![Build Status](https://travis-ci.org/frontend-collective/react-sortable-tree.svg?branch=master)](https://travis-ci.org/frontend-collective/react-sortable-tree)
1212
[![Coverage Status](https://coveralls.io/repos/github/frontend-collective/react-sortable-tree/badge.svg?branch=master)](https://coveralls.io/github/frontend-collective/react-sortable-tree?branch=master)
1313

14-
> A React component for Drag-and-drop sortable representation of hierarchical data. Checkout the [demo](https://react-sortable-tree.surge.sh/) for a demonstration of some basic features. Checkout the [storybook](https://react-sortable-tree.surge.sh/storybook/index.html) for advanced usage. Play with the code on [CodeSandbox.io](https://codesandbox.io/s/wkxvy3z15w).
14+
> A React component for Drag-and-drop sortable representation of hierarchical data. Checkout the [demo](https://react-sortable-tree.surge.sh/) for a demonstration of some basic features. Checkout the [storybook](https://frontend-collective.github.io/react-sortable-tree/) for advanced usage. Play with the code on [CodeSandbox.io](https://codesandbox.io/s/wkxvy3z15w).
1515
1616
<div align="center">
1717
<img src="https://cloud.githubusercontent.com/assets/4413963/19334888/2be8261c-913a-11e6-9508-4b347ae114b4.gif"/>
1818
</div>
1919

20+
## Table of Contents
21+
22+
- [Getting Started](#getting-started)
23+
- [Usage](#usage)
24+
- [Props](#props)
25+
- [Data Helpers](#data-helper-functions)
26+
- [Themes](#themes)
27+
- [Browser Compatibility](#browser-compatibility)
28+
- [Troubleshooting](#troubleshooting)
29+
- [Contributing](#contributing)
30+
2031
## Getting started
2132

2233
Install `react-sortable-tree` using npm.
2334

2435
```sh
36+
# NPM
2537
npm install react-sortable-tree --save
38+
39+
# YARN
40+
yarn add react-sortable-tree
2641
```
2742

2843
ES6 and CommonJS builds are available with each distribution.
@@ -38,11 +53,12 @@ import SortableTree from 'react-sortable-tree';
3853
// Or you can import the tree without the dnd context as a named export. eg
3954
import { SortableTreeWithoutDndContext as SortableTree } from 'react-sortable-tree';
4055

41-
// Importing from esm (default)
42-
import SortableTree from 'react-sortable-tree/dist/index.esm.js';
43-
44-
// Importing from cjs
56+
// Importing from cjs (default)
4557
import SortableTree from 'react-sortable-tree/dist/index.cjs.js';
58+
import SortableTree from 'react-sortable-tree';
59+
60+
// Importing from esm
61+
import SortableTree from 'react-sortable-tree/dist/index.esm.js';
4662
```
4763

4864
## Usage
@@ -74,7 +90,7 @@ export default class Tree extends Component {
7490
}
7591
```
7692

77-
## Options
93+
## Props
7894

7995
| Prop | Type | <div style="width: 400px;">Description</div> |
8096
| :----------------------------- | :------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -114,18 +130,23 @@ Need a hand turning your flat data into nested tree data?
114130
Want to perform add/remove operations on the tree data without creating your own recursive function?
115131
Check out the helper functions exported from [`tree-data-utils.js`](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js).
116132

117-
Notable among the available functions:
118-
119-
- **`getTreeFromFlatData`**: Convert flat data (like that from a database) into nested tree data
120-
- **`getFlatDataFromTree`**: Convert tree data back to flat data
121-
- **`addNodeUnderParent`**: Add a node under the parent node at the given path
122-
- **`removeNode`**: For a given path, get the node at that path and the treeData with that node removed.
123-
- **`changeNodeAtPath`**: Modify the node object at the given path
124-
- **`map`**: Perform a change on every node in the tree
125-
- **`walk`**: Visit every node in the tree in order
126-
127-
Documentation for each method is only available in the code at this time. You can also refer to the tests for simple usage examples.
128-
If your hobbies happen to include writing documentation, by all means submit a pull request. It would really help out.
133+
- [**`getTreeFromFlatData`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L972): Convert flat data (like that from a database) into nested tree data.
134+
- [**`getFlatDataFromTree`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L939): Convert tree data back to flat data.
135+
- [**`addNodeUnderParent`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L612): Add a node under the parent node at the given path.
136+
- [**`removeNode`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L533): For a given path, get the node at that path, treeIndex, and the treeData with that node removed.
137+
- [**`removeNodeAtPath`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L505): For a given path, remove the node and return the treeData.
138+
- [**`changeNodeAtPath`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L409): Modify the node object at the given path.
139+
- [**`map`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L359): Perform a change on every node in the tree.
140+
- [**`walk`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L326): Visit every node in the tree in order.
141+
- [**`getDescendantCount`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L60): Count how many descendants this node has.
142+
- [**`getVisibleNodeCount`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L248): Count how many visible descendants this node has.
143+
- [**`getVisibleNodeInfoAtIndex`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L286): Get the <targetIndex>th visible node in the tree data.
144+
- [**`toggleExpandedForAll`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L389): Expand or close every node in the tree.
145+
- [**`getNodeAtPath`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L572): Get the node at the input path.
146+
- [**`insertNode`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L878): Insert the input node at the specified depth and minimumTreeIndex.
147+
- [**`find`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L1070): Find nodes matching a search query in the tree.
148+
- [**`isDescendant`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L1020): Check if a node is a descendant of another node.
149+
- [**`getDepth`**](https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js#L1038): Get the longest path in the tree.
129150

130151
## Themes
131152

@@ -172,7 +193,7 @@ import { SortableTreeWithoutDndContext as SortableTree } from 'react-sortable-tr
172193

173194
## Contributing
174195

175-
Please read the [Code of Conduct](CODE_OF_CONDUCT.md).
196+
Please read the [Code of Conduct](CODE_OF_CONDUCT.md). I actively welcome pull requests :)
176197

177198
After cloning the repository and running `npm install` inside, you can use the following commands to develop and build the project.
178199

0 commit comments

Comments
 (0)