2016-07-06 21:09:05 +02:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-07-08 20:57:22 +02:00
|
|
|
import classNames from 'classnames';
|
2016-07-14 18:47:54 +02:00
|
|
|
import InlineSVG from 'react-inlinesvg';
|
2017-02-22 20:29:35 +01:00
|
|
|
import ConnectedFileNode from './FileNode';
|
|
|
|
|
2016-08-25 23:32:27 +02:00
|
|
|
const folderUrl = require('../../../images/folder.svg');
|
|
|
|
const downArrowUrl = require('../../../images/down-arrow.svg');
|
2016-07-06 21:09:05 +02:00
|
|
|
|
2016-08-03 21:11:59 +02:00
|
|
|
class Sidebar extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.resetSelectedFile = this.resetSelectedFile.bind(this);
|
2017-01-09 22:11:01 +01:00
|
|
|
this.toggleProjectOptions = this.toggleProjectOptions.bind(this);
|
2016-08-03 21:11:59 +02:00
|
|
|
}
|
2016-07-14 18:47:54 +02:00
|
|
|
|
2016-08-03 21:11:59 +02:00
|
|
|
resetSelectedFile() {
|
2016-08-23 19:52:31 +02:00
|
|
|
this.props.setSelectedFile(this.props.files[1].id);
|
2016-08-03 21:11:59 +02:00
|
|
|
}
|
|
|
|
|
2017-01-09 22:11:01 +01:00
|
|
|
toggleProjectOptions(e) {
|
|
|
|
e.preventDefault();
|
2017-01-09 18:47:32 +01:00
|
|
|
if (this.props.projectOptionsVisible) {
|
|
|
|
this.props.closeProjectOptions();
|
|
|
|
} else {
|
2017-02-22 20:29:35 +01:00
|
|
|
this.sidebarOptions.focus();
|
2017-01-09 18:47:32 +01:00
|
|
|
this.props.openProjectOptions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-03 21:11:59 +02:00
|
|
|
render() {
|
|
|
|
const sidebarClass = classNames({
|
2017-02-22 20:29:35 +01:00
|
|
|
'sidebar': true,
|
2016-08-30 05:23:10 +02:00
|
|
|
'sidebar--contracted': !this.props.isExpanded,
|
|
|
|
'sidebar--project-options': this.props.projectOptionsVisible
|
2016-08-03 21:11:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<nav className={sidebarClass} title="file-navigation" role="navigation">
|
2017-01-09 22:11:01 +01:00
|
|
|
<div className="sidebar__header" onContextMenu={this.toggleProjectOptions}>
|
2016-08-25 23:32:27 +02:00
|
|
|
<h3 className="sidebar__title">
|
|
|
|
<span className="sidebar__folder-icon">
|
|
|
|
<InlineSVG src={folderUrl} />
|
|
|
|
</span>
|
|
|
|
<span>project-folder</span>
|
|
|
|
</h3>
|
2016-08-03 21:11:59 +02:00
|
|
|
<div className="sidebar__icons">
|
|
|
|
<button
|
2016-08-30 05:23:10 +02:00
|
|
|
aria-label="add file or folder"
|
2016-08-03 21:11:59 +02:00
|
|
|
className="sidebar__add"
|
2016-10-19 19:03:19 +02:00
|
|
|
tabIndex="0"
|
2017-02-22 20:29:35 +01:00
|
|
|
ref={(element) => { this.sidebarOptions = element; }}
|
2017-01-09 22:11:01 +01:00
|
|
|
onClick={this.toggleProjectOptions}
|
2016-08-30 05:23:10 +02:00
|
|
|
onBlur={() => setTimeout(this.props.closeProjectOptions, 200)}
|
2016-08-03 21:11:59 +02:00
|
|
|
>
|
2016-08-25 23:32:27 +02:00
|
|
|
<InlineSVG src={downArrowUrl} />
|
2016-08-03 21:11:59 +02:00
|
|
|
</button>
|
2016-08-30 05:23:10 +02:00
|
|
|
<ul className="sidebar__project-options">
|
|
|
|
<li>
|
2017-02-22 20:29:35 +01:00
|
|
|
<button aria-label="add folder" onClick={this.props.newFolder} >
|
2016-12-20 06:21:04 +01:00
|
|
|
Add folder
|
2017-02-22 20:29:35 +01:00
|
|
|
</button>
|
2016-08-30 05:23:10 +02:00
|
|
|
</li>
|
|
|
|
<li>
|
2017-02-22 20:29:35 +01:00
|
|
|
<button aria-label="add file" onClick={this.props.newFile} >
|
2016-12-20 06:21:04 +01:00
|
|
|
Add file
|
2017-02-22 20:29:35 +01:00
|
|
|
</button>
|
2016-08-30 05:23:10 +02:00
|
|
|
</li>
|
|
|
|
</ul>
|
2016-08-03 21:11:59 +02:00
|
|
|
</div>
|
2016-07-14 18:47:54 +02:00
|
|
|
</div>
|
2016-08-24 19:09:48 +02:00
|
|
|
<ConnectedFileNode id={this.props.files.filter(file => file.name === 'root')[0].id} />
|
2016-08-03 21:11:59 +02:00
|
|
|
</nav>
|
|
|
|
);
|
|
|
|
}
|
2016-07-06 21:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Sidebar.propTypes = {
|
2017-02-22 20:29:35 +01:00
|
|
|
files: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
id: PropTypes.string.isRequired
|
|
|
|
})).isRequired,
|
2016-08-03 21:11:59 +02:00
|
|
|
setSelectedFile: PropTypes.func.isRequired,
|
|
|
|
isExpanded: PropTypes.bool.isRequired,
|
2016-08-30 05:23:10 +02:00
|
|
|
projectOptionsVisible: PropTypes.bool.isRequired,
|
2016-08-03 21:11:59 +02:00
|
|
|
newFile: PropTypes.func.isRequired,
|
2016-08-30 05:23:10 +02:00
|
|
|
openProjectOptions: PropTypes.func.isRequired,
|
|
|
|
closeProjectOptions: PropTypes.func.isRequired,
|
|
|
|
newFolder: PropTypes.func.isRequired
|
2016-07-06 21:09:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Sidebar;
|