Skip to content

Commit dba591e

Browse files
committed
Create example to test out a large number of nodes
References #14.
1 parent b5c7e37 commit dba591e

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

examples/src/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ <h2>Pessimistic Toggle Example</h2>
3232
<p>Try clicking a partially-checked node. Instead of select all children, the pessimistic model will uncheck them.</p>
3333
<div id="pessimistic-toggle-example"></div>
3434

35+
<h2>Large Data Example</h2>
36+
<div id="large-data-example"></div>
37+
3538
<footer class="site-footer">
3639
<span class="site-footer-owner">
3740
<a href="https://github.com/jakezatecky/react-checkbox-tree">React Checkbox Tree</a> is maintained by <a href="https://github.com/jakezatecky">jakezatecky</a>.

examples/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import ReactDOM from 'react-dom';
44
import BasicExample from './js/BasicExample';
55
import CustomIconsExample from './js/CustomIconsExample';
66
import PessimisticToggleExample from './js/PessimisticToggleExample';
7+
import LargeDataExample from './js/LargeDataExample';
78

89
ReactDOM.render(<BasicExample />, document.getElementById('basic-example'));
910
ReactDOM.render(<CustomIconsExample />, document.getElementById('custom-icons-example'));
1011
ReactDOM.render(<PessimisticToggleExample />, document.getElementById('pessimistic-toggle-example'));
12+
ReactDOM.render(<LargeDataExample />, document.getElementById('large-data-example'));

examples/src/js/LargeDataExample.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React from 'react';
2+
import CheckboxTree from 'react-checkbox-tree';
3+
4+
const parents = [];
5+
6+
for (let i = 0; i < 100; i += 1) {
7+
const children = [];
8+
9+
for (let j = 0; j < 200; j += 1) {
10+
children.push({
11+
value: `node-0-${i}-${j}`,
12+
label: `Node 0-${i}-${j}`,
13+
});
14+
}
15+
16+
parents.push({
17+
value: `node-0-${i}`,
18+
label: `Node 0-${i}`,
19+
children,
20+
});
21+
}
22+
23+
const nodes = [{
24+
value: 'node-0',
25+
label: 'Node 0',
26+
children: parents,
27+
}];
28+
29+
class LargeDataExample extends React.Component {
30+
constructor() {
31+
super();
32+
33+
this.state = {
34+
checked: [],
35+
expanded: [],
36+
};
37+
38+
this.onCheck = this.onCheck.bind(this);
39+
this.onExpand = this.onExpand.bind(this);
40+
}
41+
42+
onCheck(checked) {
43+
this.setState({ checked });
44+
}
45+
46+
onExpand(expanded) {
47+
this.setState({ expanded });
48+
}
49+
50+
render() {
51+
const { checked, expanded } = this.state;
52+
53+
return (
54+
<CheckboxTree
55+
checked={checked}
56+
expanded={expanded}
57+
nodes={nodes}
58+
onCheck={this.onCheck}
59+
onExpand={this.onExpand}
60+
/>
61+
);
62+
}
63+
}
64+
65+
export default LargeDataExample;

0 commit comments

Comments
 (0)