-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathapp.js
74 lines (67 loc) · 1.58 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import '../lib/react-ui-tree.css';
import './theme.css';
import './app.css';
import cx from 'classnames';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Tree from '../lib/react-ui-tree.js';
import tree from './tree';
import packageJSON from '../package.json';
class App extends Component {
state = {
active: null,
tree: tree
};
renderNode = node => {
return (
<span
className={cx('node', {
'is-active': node === this.state.active
})}
onClick={this.onClickNode.bind(null, node)}
>
{node.module}
</span>
);
};
onClickNode = node => {
this.setState({
active: node
});
};
render() {
return (
<div className="app">
<div className="tree">
<Tree
paddingLeft={20}
tree={this.state.tree}
onChange={this.handleChange}
isNodeCollapsed={this.isNodeCollapsed}
renderNode={this.renderNode}
/>
</div>
<div className="inspector">
<h1>
{packageJSON.name} {packageJSON.version}
</h1>
<button onClick={this.updateTree}>update tree</button>
<pre>{JSON.stringify(this.state.tree, null, ' ')}</pre>
</div>
</div>
);
}
handleChange = tree => {
this.setState({
tree: tree
});
};
updateTree = () => {
const { tree } = this.state;
tree.children.push({ module: 'test' });
this.setState({
tree: tree
});
};
}
ReactDOM.render(<App />, document.getElementById('app'));