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';
|
2016-08-03 21:11:59 +02:00
|
|
|
import SidebarItem from './SidebarItem';
|
2016-07-14 18:47:54 +02:00
|
|
|
const rightArrowUrl = require('../../../images/right-arrow.svg');
|
|
|
|
const leftArrowUrl = require('../../../images/left-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);
|
|
|
|
}
|
2016-07-14 18:47:54 +02:00
|
|
|
|
2016-08-03 21:11:59 +02:00
|
|
|
resetSelectedFile() {
|
|
|
|
this.props.setSelectedFile(this.props.files[0].id);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const sidebarClass = classNames({
|
|
|
|
sidebar: true,
|
|
|
|
'sidebar--contracted': !this.props.isExpanded
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<nav className={sidebarClass} title="file-navigation" role="navigation">
|
|
|
|
<div className="sidebar__header">
|
|
|
|
<h3 className="sidebar__title">Sketch Files</h3>
|
|
|
|
<div className="sidebar__icons">
|
|
|
|
<button
|
|
|
|
aria-label="add file"
|
|
|
|
className="sidebar__add"
|
2016-08-04 01:03:01 +02:00
|
|
|
onClick={this.props.newFile}
|
2016-08-03 21:11:59 +02:00
|
|
|
>
|
|
|
|
+
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
aria-label="collapse file navigation"
|
|
|
|
className="sidebar__contract"
|
2016-08-04 01:03:01 +02:00
|
|
|
onClick={this.props.collapseSidebar}
|
2016-08-03 21:11:59 +02:00
|
|
|
>
|
|
|
|
<InlineSVG src={leftArrowUrl} />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
aria-label="expand file navigation"
|
|
|
|
className="sidebar__expand"
|
2016-08-04 01:03:01 +02:00
|
|
|
onClick={this.props.expandSidebar}
|
2016-08-03 21:11:59 +02:00
|
|
|
>
|
|
|
|
<InlineSVG src={rightArrowUrl} />
|
|
|
|
</button>
|
|
|
|
</div>
|
2016-07-14 18:47:54 +02:00
|
|
|
</div>
|
2016-08-10 22:20:15 +02:00
|
|
|
<ul className="sidebar__file-list" title="project files">
|
2016-08-03 21:11:59 +02:00
|
|
|
{this.props.files.map((file, fileIndex) =>
|
|
|
|
<SidebarItem
|
2016-07-12 21:11:45 +02:00
|
|
|
key={file.id}
|
2016-08-03 21:11:59 +02:00
|
|
|
file={file}
|
|
|
|
setSelectedFile={this.props.setSelectedFile}
|
|
|
|
fileIndex={fileIndex}
|
|
|
|
showFileOptions={this.props.showFileOptions}
|
|
|
|
hideFileOptions={this.props.hideFileOptions}
|
|
|
|
deleteFile={this.props.deleteFile}
|
|
|
|
resetSelectedFile={this.resetSelectedFile}
|
2016-08-03 23:10:03 +02:00
|
|
|
showEditFileName={this.props.showEditFileName}
|
|
|
|
hideEditFileName={this.props.hideEditFileName}
|
|
|
|
updateFileName={this.props.updateFileName}
|
2016-08-03 21:11:59 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
);
|
|
|
|
}
|
2016-07-06 21:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Sidebar.propTypes = {
|
2016-07-08 20:57:22 +02:00
|
|
|
files: PropTypes.array.isRequired,
|
2016-08-03 21:11:59 +02:00
|
|
|
setSelectedFile: PropTypes.func.isRequired,
|
|
|
|
isExpanded: PropTypes.bool.isRequired,
|
|
|
|
newFile: PropTypes.func.isRequired,
|
|
|
|
collapseSidebar: PropTypes.func.isRequired,
|
|
|
|
expandSidebar: PropTypes.func.isRequired,
|
|
|
|
showFileOptions: PropTypes.func.isRequired,
|
|
|
|
hideFileOptions: PropTypes.func.isRequired,
|
2016-08-03 23:10:03 +02:00
|
|
|
deleteFile: PropTypes.func.isRequired,
|
|
|
|
showEditFileName: PropTypes.func.isRequired,
|
|
|
|
hideEditFileName: PropTypes.func.isRequired,
|
|
|
|
updateFileName: PropTypes.func.isRequired
|
2016-07-06 21:09:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Sidebar;
|