Created
October 20, 2015 08:35
-
-
Save d3ep4k/113010094925e6fd0aa1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TreeFolder = React.createClass({ | |
getInitialState: function() { | |
return { showFolderContents: this.props.showFolderContents, node: this.props.node}; | |
}, | |
onClick: function() { | |
this.setState({ showFolderContents: !this.state.showFolderContents }); | |
}, | |
updateData: function(data){ | |
this.setState({node:data}) | |
}, | |
contextMenu: function(e){ | |
this.props.contextMenuCallback(e) | |
}, | |
render: function(){ | |
var cnodes = this.state.node.nodeChildren | |
var name = this.state.node.name; | |
var icon = this.state.showFolderContents ? "fa-folder-open":"fa-folder" | |
console.log(this.props) | |
var callback = this.props.contextMenuCallback; | |
if(cnodes){ | |
return( | |
<div className="tree-folder"> | |
<div className="tree-folder-header" onClick={this.onClick} onContextMenu={this.contextMenu}> | |
<i className={'fa ' + icon + ' success'}></i> | |
<div className="tree-folder-name">{name}</div> | |
</div> | |
<div className="tree-folder-content"> | |
{ this.state.showFolderContents ? | |
this.state.node.nodeChildren.map(function(comp, i){return( | |
<TreeFolder key={i} node={comp} contextMenuCallback={callback}/> | |
)}) | |
:null | |
} | |
</div> | |
<div className="tree-loader hide"><div>Loading...</div></div> | |
</div> | |
) | |
}else{ | |
return ( | |
<div className="tree-item" onContextMenu={this.contextMenu}> | |
<i className="tree-dot"></i> | |
<div className="tree-item-name">{name}</div> | |
</div> | |
) | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment