2016-06-27 19:08:25 +00:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-08-17 20:09:20 +00:00
|
|
|
import { Link } from 'react-router';
|
2016-07-22 16:42:38 +00:00
|
|
|
const InlineSVG = require('react-inlinesvg');
|
2016-06-23 22:29:55 +00:00
|
|
|
const playUrl = require('../../../images/play.svg');
|
|
|
|
const logoUrl = require('../../../images/p5js-logo.svg');
|
|
|
|
const stopUrl = require('../../../images/stop.svg');
|
|
|
|
const preferencesUrl = require('../../../images/preferences.svg');
|
2016-07-22 16:42:38 +00:00
|
|
|
import classNames from 'classnames';
|
2016-06-23 22:29:55 +00:00
|
|
|
|
2016-08-15 16:42:13 +00:00
|
|
|
class Toolbar extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.handleKeyPress = this.handleKeyPress.bind(this);
|
|
|
|
this.handleProjectNameChange = this.handleProjectNameChange.bind(this);
|
|
|
|
}
|
2016-06-23 22:29:55 +00:00
|
|
|
|
2016-08-15 16:42:13 +00:00
|
|
|
handleKeyPress(event) {
|
|
|
|
if (event.key === 'Enter') {
|
|
|
|
this.props.hideEditProjectName();
|
|
|
|
}
|
|
|
|
}
|
2016-07-31 02:46:48 +00:00
|
|
|
|
2016-08-15 16:42:13 +00:00
|
|
|
handleProjectNameChange(event) {
|
|
|
|
this.props.setProjectName(event.target.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
validateProjectName() {
|
|
|
|
if (this.props.project.name === '') {
|
|
|
|
this.props.setProjectName(this.originalProjectName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let playButtonClass = classNames({
|
|
|
|
'toolbar__play-button': true,
|
|
|
|
'toolbar__play-button--selected': this.props.isPlaying
|
|
|
|
});
|
|
|
|
let stopButtonClass = classNames({
|
|
|
|
'toolbar__stop-button': true,
|
|
|
|
'toolbar__stop-button--selected': !this.props.isPlaying
|
|
|
|
});
|
|
|
|
let preferencesButtonClass = classNames({
|
|
|
|
'toolbar__preferences-button': true,
|
|
|
|
'toolbar__preferences-button--selected': this.props.preferencesIsVisible
|
|
|
|
});
|
|
|
|
let nameContainerClass = classNames({
|
|
|
|
'toolbar__project-name-container': true,
|
|
|
|
'toolbar__project-name-container--editing': this.props.project.isEditingName
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="toolbar">
|
|
|
|
<img className="toolbar__logo" src={logoUrl} alt="p5js Logo" />
|
2016-08-16 01:09:47 +00:00
|
|
|
<button
|
|
|
|
className="toolbar__play-sketch-button"
|
|
|
|
onClick={() => { this.props.startTextOutput(); this.props.startSketch(); }}
|
2016-08-25 21:59:02 +00:00
|
|
|
aria-label="play sketch"
|
2016-08-16 01:09:47 +00:00
|
|
|
>
|
2016-08-25 21:59:02 +00:00
|
|
|
<InlineSVG src={playUrl} alt="Play Sketch" />
|
|
|
|
</button>
|
|
|
|
<button className={playButtonClass} onClick={this.props.startSketch} aria-label="play only visual sketch">
|
|
|
|
<InlineSVG src={playUrl} alt="Play only visual Sketch" />
|
2016-08-16 01:09:47 +00:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
className={stopButtonClass}
|
|
|
|
onClick={() => { this.props.stopTextOutput(); this.props.stopSketch(); }}
|
|
|
|
aria-label="stop sketch"
|
|
|
|
>
|
2016-08-15 16:42:13 +00:00
|
|
|
<InlineSVG src={stopUrl} alt="Stop Sketch" />
|
|
|
|
</button>
|
|
|
|
<div className={nameContainerClass}>
|
|
|
|
<a
|
|
|
|
className="toolbar__project-name"
|
|
|
|
onClick={() => {
|
|
|
|
this.originalProjectName = this.props.project.name;
|
|
|
|
this.props.showEditProjectName();
|
|
|
|
setTimeout(() => this.refs.projectNameInput.focus(), 0);
|
|
|
|
}}
|
|
|
|
>{this.props.project.name}</a>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
className="toolbar__project-name-input"
|
|
|
|
value={this.props.project.name}
|
|
|
|
onChange={this.handleProjectNameChange}
|
|
|
|
ref="projectNameInput"
|
|
|
|
onBlur={() => {
|
|
|
|
this.validateProjectName();
|
|
|
|
this.props.hideEditProjectName();
|
|
|
|
}}
|
|
|
|
onKeyPress={this.handleKeyPress}
|
|
|
|
/>
|
|
|
|
{(() => { // eslint-disable-line
|
|
|
|
if (this.props.owner) {
|
|
|
|
return (
|
2016-08-17 20:09:20 +00:00
|
|
|
<p className="toolbar__project-owner">
|
|
|
|
by <Link to={`/${this.props.owner.username}/sketches`}>{this.props.owner.username}</Link>
|
|
|
|
</p>
|
2016-08-15 16:42:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
})()}
|
|
|
|
</div>
|
|
|
|
<button
|
|
|
|
className={preferencesButtonClass}
|
|
|
|
onClick={this.props.openPreferences}
|
2016-08-25 21:59:02 +00:00
|
|
|
aria-label="preferences"
|
2016-06-27 19:08:25 +00:00
|
|
|
>
|
2016-08-25 21:59:02 +00:00
|
|
|
<InlineSVG src={preferencesUrl} alt="Preferences" />
|
2016-08-15 16:42:13 +00:00
|
|
|
</button>
|
2016-06-23 22:29:55 +00:00
|
|
|
</div>
|
2016-08-15 16:42:13 +00:00
|
|
|
);
|
|
|
|
}
|
2016-06-23 22:29:55 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 19:08:25 +00:00
|
|
|
Toolbar.propTypes = {
|
|
|
|
isPlaying: PropTypes.bool.isRequired,
|
2016-08-01 17:55:49 +00:00
|
|
|
preferencesIsVisible: PropTypes.bool.isRequired,
|
2016-06-27 19:08:25 +00:00
|
|
|
startSketch: PropTypes.func.isRequired,
|
|
|
|
stopSketch: PropTypes.func.isRequired,
|
2016-08-12 20:37:38 +00:00
|
|
|
startTextOutput: PropTypes.func.isRequired,
|
|
|
|
stopTextOutput: PropTypes.func.isRequired,
|
2016-06-27 19:08:25 +00:00
|
|
|
setProjectName: PropTypes.func.isRequired,
|
2016-07-15 15:54:47 +00:00
|
|
|
openPreferences: PropTypes.func.isRequired,
|
2016-07-15 17:11:50 +00:00
|
|
|
owner: PropTypes.shape({
|
|
|
|
username: PropTypes.string
|
2016-08-15 16:42:13 +00:00
|
|
|
}),
|
|
|
|
project: PropTypes.shape({
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
isEditingName: PropTypes.bool
|
|
|
|
}).isRequired,
|
|
|
|
showEditProjectName: PropTypes.func.isRequired,
|
|
|
|
hideEditProjectName: PropTypes.func.isRequired
|
2016-06-27 19:08:25 +00:00
|
|
|
};
|
|
|
|
|
2016-06-23 22:29:55 +00:00
|
|
|
export default Toolbar;
|