-
Notifications
You must be signed in to change notification settings - Fork 0
/
treeview.jsx
86 lines (66 loc) · 1.82 KB
/
treeview.jsx
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
75
76
77
78
79
80
81
82
83
84
85
86
var PureRenderMixin = React.addons.PureRenderMixin;
TreeView = React.createClass({
mixins: [PureRenderMixin],
propTypes: {
selected: React.PropTypes.number,
children: React.PropTypes.array
// array of:
// {
// navView: ReactClass,
// mainView: ReactClass,
// object: Object
// }
//
},
getInitialState () {
return {
selected: this.props.selected || 0
};
},
// TODO - try to remove?
changeSelected ( key ) {
this.setState( { selected: key } );
},
renderNavigation() {
return _.map(this.props.children, ( child, i ) => {
var classes = React.addons.classSet({
navBtn: true,
[ child.class ]: true,
selected: this.state.selected === i
});
var boundClick = this.changeSelected.bind( this, i );
var CClass = child.nav;
return <div className={classes} onClick={ boundClick } key={i} >
<CClass {...child.object} />
</div>;
});
},
renderMainView () {
var contract = Contracts[this.state.selected];
let obj = this.props.children[this.state.selected];
let ViewClass = obj.main;
var mainClasses = React.addons.classSet({
mainView: true,
[ obj.class ]: true
});
return <div className={mainClasses}>
<ViewClass key={this.state.selected} {...obj.object} />
</div>;
},
render () {
var boundClick = this.changeSelected.bind( this, "web3" );
var boundClickNew = this.changeSelected.bind( this, "new" );
var navClasses = React.addons.classSet({
navigation: true,
[ this.props.class ]: true
});
return (
<div className="treeview">
<div className={navClasses}>
{ this.renderNavigation() }
</div>
{this.renderMainView()}
</div>
);
}
});