embark/embark-ui/src/components/FileExplorer.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-08-30 12:13:37 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import {Treebeard, decorators} from 'react-treebeard';
const Header = ({style, node}) => {
const iconType = node.children ? 'folder' : 'file';
const iconClass = `fe fe-${iconType}`;
const iconStyle = {marginRight: '5px'};
return (
<div style={style.base}>
<div style={style.title}>
<i className={iconClass} style={iconStyle}/>
{node.name}
</div>
</div>
);
};
Header.propTypes = {
style: PropTypes.object,
node: PropTypes.object
};
decorators.Header = Header;
class FileExplorer extends React.Component {
constructor(props){
super(props);
this.state = {};
}
2018-08-30 12:13:37 +00:00
2018-08-30 12:13:37 +00:00
onToggle(node, toggled){
2018-08-30 12:13:37 +00:00
let oldNode = this.state.cursor;
if(oldNode) {
oldNode.active = false;
}
2018-08-30 12:13:37 +00:00
node.active = true;
if(node.children) {
node.toggled = toggled;
2018-08-30 12:13:37 +00:00
} else {
this.props.fetchFile(node);
2018-08-30 12:13:37 +00:00
}
this.setState({ cursor: node });
}
2018-08-30 12:13:37 +00:00
2018-08-30 12:13:37 +00:00
render(){
return (
<Treebeard
data={this.props.files}
decorators={decorators}
2018-08-30 12:13:37 +00:00
onToggle={this.onToggle.bind(this)}
2018-08-30 12:13:37 +00:00
/>
);
}
}
FileExplorer.propTypes = {
2018-08-30 12:13:37 +00:00
files: PropTypes.array,
fetchFile: PropTypes.func
2018-08-30 12:13:37 +00:00
};
export default FileExplorer;