Skip to content

Commit caa2e42

Browse files
authored
docs: Better documentation site (#67)
* docs: Basic working cut * chore: Updating after merge commit * chore: Lint upgrades * chore: Prepping it up * chore: Fix lint issues * docs: Add missing TOC entry
1 parent 2e0d514 commit caa2e42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3072
-22857
lines changed

.eslintrc.json

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
{
22
"parser": "babel-eslint",
3-
"parserOptions": {
4-
"ecmaFeatures": {
5-
"jsx": true,
6-
"modules": true
7-
}
8-
},
9-
"extends": ["standard", "plugin:react/recommended"],
10-
"plugins": ["react"],
3+
"extends": ["standard", "react-app"],
114
"rules": {
12-
"max-len": ["error", { "code": 120 }]
5+
"react/jsx-filename-extension": [
6+
1,
7+
{
8+
"extensions": [".js", ".jsx"]
9+
}
10+
],
11+
"import/no-extraneous-dependencies": [
12+
2,
13+
{
14+
"devDependencies": true
15+
}
16+
],
17+
"import/prefer-default-export": 0,
18+
"no-underscore-dangle": 0,
19+
"no-plusplus": 0,
20+
"no-shadow": 0,
21+
"no-param-reassign": 0,
22+
"react/require-default-props": 0,
23+
"semi": [2, "never"],
24+
"quotes": ["error", "single", { "avoidEscape": true }],
25+
"jsx-a11y/href-no-hash": 0
26+
},
27+
"globals": {
28+
"document": true
1329
}
1430
}

README.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
[![build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url] [![semantic-release][semantic-release]][semantic-release-url] [![Commitizen friendly][commitizen]][commitizen-url] [![Greenkeeper badge][greenkeeper]][greenkeeper-url]
88

9-
109
[npm-image]: http://img.shields.io/npm/v/react-dropdown-tree-select.svg?style=flat-square
1110
[npm-url]: http://npmjs.org/package/react-dropdown-tree-select
1211
[travis-image]: https://img.shields.io/travis/dowjones/react-dropdown-tree-select.svg?style=flat-square
@@ -23,7 +22,6 @@
2322
[gzip-image]: http://img.badgesize.io/https://unpkg.com/react-dropdown-tree-select/dist/react-dropdown-tree-select.js?compression=gzip&style=flat-square
2423
[gzip-url]: https://unpkg.com/react-dropdown-tree-select/dist/react-dropdown-tree-select.js
2524

26-
2725
## React Dropdown Tree Select
2826

2927
A lightweight and fast control to render a select component that can display hierarchical tree data. In addition, the control shows the selection in pills and allows user to search the options for quick filtering and selection.
@@ -55,6 +53,7 @@ A lightweight and fast control to render a select component that can display hie
5553
* [Virtualized rendering](#virtualized-rendering)
5654
* [Reducing costly DOM manipulations](#reducing-costly-dom-manipulations)
5755
* [FAQ](#faq)
56+
* [Doing more with HOCs](/docs/HOC.md)
5857
* [Development](#development)
5958
* [License](#license)
6059

@@ -97,36 +96,36 @@ In order to avoid version conflicts in your project, you must specify and instal
9796
## Usage
9897

9998
```jsx
100-
import React from "react";
101-
import ReactDOM from "react-dom";
102-
import DropdownTreeSelect from "react-dropdown-tree-select";
99+
import React from 'react'
100+
import ReactDOM from 'react-dom'
101+
import DropdownTreeSelect from 'react-dropdown-tree-select'
103102

104103
const tree = {
105-
label: "search me",
106-
value: "searchme",
104+
label: 'search me',
105+
value: 'searchme',
107106
children: [
108107
{
109-
label: "search me too",
110-
value: "searchmetoo",
108+
label: 'search me too',
109+
value: 'searchmetoo',
111110
children: [
112111
{
113-
label: "No one can get me",
114-
value: "anonymous"
112+
label: 'No one can get me',
113+
value: 'anonymous'
115114
}
116115
]
117116
}
118117
]
119-
};
118+
}
120119

121120
const onChange = (currentNode, selectedNodes) => {
122-
console.log("onChange::", currentNode, selectedNodes);
123-
};
121+
console.log('onChange::', currentNode, selectedNodes)
122+
}
124123
const onAction = ({ action, node }) => {
125-
console.log(`onAction:: [${action}]`, node);
126-
};
124+
console.log(`onAction:: [${action}]`, node)
125+
}
127126
const onNodeToggle = currentNode => {
128-
console.log("onNodeToggle::", currentNode);
129-
};
127+
console.log('onNodeToggle::', currentNode)
128+
}
130129

131130
ReactDOM.render(
132131
<DropdownTreeSelect
@@ -136,7 +135,7 @@ ReactDOM.render(
136135
onNodeToggle={onNodeToggle}
137136
/>,
138137
document.body
139-
); // in real world, you'd want to render to an element, instead of body.
138+
) // in real world, you'd want to render to an element, instead of body.
140139
```
141140

142141
## Props
@@ -164,7 +163,7 @@ function onChange(currentNode, selectedNodes) {
164163
// selectedNodes: [{ label, value, children, expanded, checked, className, ...extraProps }]
165164
}
166165

167-
return <DropdownTreeSelect data={data} onChange={onChange} />;
166+
return <DropdownTreeSelect data={data} onChange={onChange} />
168167
```
169168

170169
### onNodeToggle
@@ -180,7 +179,7 @@ function onNodeToggle(currentNode) {
180179
// currentNode: { label, value, children, expanded, checked, className, ...extraProps }
181180
}
182181

183-
return <DropdownTreeSelect data={data} onNodeToggle={onNodeToggle} />;
182+
return <DropdownTreeSelect data={data} onNodeToggle={onNodeToggle} />
184183
```
185184

186185
### data
@@ -254,16 +253,16 @@ module: {
254253
{
255254
test: /\.css$/,
256255
use: ExtractTextPlugin.extract({
257-
fallback: "style-loader",
256+
fallback: 'style-loader',
258257
use: [
259258
{
260-
loader: "css-loader"
259+
loader: 'css-loader'
261260
}
262261
]
263262
}),
264263
include: /node_modules[/\\]react-dropdown-tree-select/
265264
}
266-
];
265+
]
267266
}
268267
```
269268

docs/HOC.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Doing more with HOCs
2+
3+
This documentation is about expanding react-dropdown-tree-select using Higher Order Components/Functions.
4+
5+
## Table of Contents
6+
7+
* [What are HOCs](#what-are-hocs)
8+
* [Why use a HOC](#why-use-a-hoc)
9+
* [Examples](#examples)
10+
* [External Select All, Unselect All buttons](#external-select-all--unselect-all-buttons)
11+
* [Internal Select All Checkbox](#internal-select-all-checkbox)
12+
* [Prevent re-render on parent prop/state changes](#prevent-re-render-on-parent-prop-state-changes)
13+
* [Tree Node Paths](#tree-node-paths)
14+
15+
## What are HOCs
16+
17+
HOCs (or Higher Order Components/Functions) are either a React Component (or a function that returns a React Component) that are used to enhance the functionality of an existing component.
18+
19+
You can use HOCs to manipulate the props and state, abstract rendering logic or enable code reuse.
20+
21+
## Why use a HOC
22+
23+
Or in other words, why is this functionality not baked in to the component? It's a fair question. There are many reasons but probably the biggest reason is - to _Keep It Simple_!
24+
25+
The control tries to provide a minimal, core set of features while making it easy to expand upon the core features using composition, or HOCs. This lets the component to have a very small footprint and allows you to customize/tweak or build upon as per your requirements.
26+
27+
## Examples
28+
29+
These are some of the examples of expanding the core component with HOCs. They are all provided as Code Sandboxes so feel free to play with them.
30+
31+
If you'd like to add to these examples, create an issue with a brief description (of what the HOC does) along with a CodeSandbox link.
32+
33+
### External Select All, Unselect All buttons
34+
35+
This is an example of selecting/unselecting all nodes programmatically, outside of the control.
36+
37+
![External Select/Unselect All buttons screenshot](https://user-images.githubusercontent.com/781818/37561174-6120362a-2a1e-11e8-914d-48636ed6e7d3.png)
38+
39+
[![Edit n348v2qox0](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/n348v2qox0)
40+
41+
### Internal Select All Checkbox
42+
43+
This example shows how to add a special Select All checkbox within the dropdown itself.
44+
45+
![Internal Select All Checkbox screenshot](https://user-images.githubusercontent.com/781818/37561139-7066396e-2a1d-11e8-99d0-02c24acbef3a.png)
46+
47+
[![Edit rjwqq86p1n](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/rjwqq86p1n)
48+
49+
### Prevent re-render on parent prop/state changes
50+
51+
Once initialized, the component (react-dropdown-tree-select) manages its own internal state. However, if this component is part of another component, then due to React's nature, anytime the parent is re-rendered, this component will re-render. While React's Virtual DOM diffing will cancel out any ultimate DOM modifications, it'll still go through all of its initialization process. This can be a waste of computation if the tree data hasn't changed.
52+
53+
To prevent that, this HOC simply adds a deep equality check in its `shouldComponentUpdate`.
54+
55+
This is not baked in the component since:
56+
57+
* Deep equality check can be expensive if the tree is large
58+
* Not everyone may need this check
59+
60+
[![Edit Prevent re-render on parent render with React Dropdown Tree Select](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/v05klkn56l)
61+
62+
### Tree Node Paths
63+
64+
The `onChange`/`onNodeToggle` events bubbles up few useful properties such as `_depth`, `_id`, `_parent` (and `_children` for non-leaf nodes). Using these, you can recurse up/down to grab a node in the tree.
65+
66+
In addition, you can use the object path notation to grab the node without recursion. This HOC demonstrates a technique to do that.
67+
68+
![Tree Node Paths screenshot](https://user-images.githubusercontent.com/781818/37561835-7729112e-2a2f-11e8-8f5b-c04f227e49b2.png)
69+
70+
[![Edit Tree node paths with React Dropdown Tree Select](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/l765q6lmrq)

0 commit comments

Comments
 (0)