2018-02-07 19:06:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-08-01 19:55:49 +02:00
|
|
|
import InlineSVG from 'react-inlinesvg';
|
2018-02-23 17:31:41 +01:00
|
|
|
import { Helmet } from 'react-helmet';
|
2017-08-09 19:34:59 +02:00
|
|
|
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
|
2016-08-05 03:43:13 +02:00
|
|
|
// import { bindActionCreators } from 'redux';
|
|
|
|
// import { connect } from 'react-redux';
|
|
|
|
// import * as PreferencesActions from '../actions/preferences';
|
2016-06-24 00:29:55 +02:00
|
|
|
|
|
|
|
const plusUrl = require('../../../images/plus.svg');
|
|
|
|
const minusUrl = require('../../../images/minus.svg');
|
2016-09-01 05:07:43 +02:00
|
|
|
const beepUrl = require('../../../sounds/audioAlert.mp3');
|
2016-06-24 00:29:55 +02:00
|
|
|
|
2016-08-04 05:45:49 +02:00
|
|
|
class Preferences extends React.Component {
|
2016-08-09 22:15:28 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.handleUpdateAutosave = this.handleUpdateAutosave.bind(this);
|
2019-03-26 20:37:44 +01:00
|
|
|
this.handleUpdateLinewrap = this.handleUpdateLinewrap.bind(this);
|
2016-11-08 19:11:07 +01:00
|
|
|
this.handleLintWarning = this.handleLintWarning.bind(this);
|
2019-06-18 22:54:16 +02:00
|
|
|
this.onFontInputChange = this.onFontInputChange.bind(this);
|
|
|
|
this.onFontInputSubmit = this.onFontInputSubmit.bind(this);
|
|
|
|
this.increaseFontSize = this.increaseFontSize.bind(this);
|
|
|
|
this.decreaseFontSize = this.decreaseFontSize.bind(this);
|
|
|
|
this.setFontSize = this.setFontSize.bind(this);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
fontSize: props.fontSize
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onFontInputChange(event) {
|
2019-08-13 18:27:31 +02:00
|
|
|
const INTEGER_REGEX = /^[0-9\b]+$/;
|
|
|
|
if (event.target.value === '' || INTEGER_REGEX.test(event.target.value)) {
|
|
|
|
this.setState({
|
|
|
|
fontSize: event.target.value
|
|
|
|
});
|
|
|
|
}
|
2016-08-09 22:15:28 +02:00
|
|
|
}
|
|
|
|
|
2019-06-18 22:54:16 +02:00
|
|
|
onFontInputSubmit(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
let value = parseInt(this.state.fontSize, 10);
|
2018-05-09 04:10:52 +02:00
|
|
|
if (Number.isNaN(value)) {
|
2016-11-08 19:11:07 +01:00
|
|
|
value = 16;
|
|
|
|
}
|
2018-11-02 20:55:06 +01:00
|
|
|
if (value > 36) {
|
|
|
|
value = 36;
|
|
|
|
}
|
|
|
|
if (value < 8) {
|
|
|
|
value = 8;
|
|
|
|
}
|
2019-06-18 22:54:16 +02:00
|
|
|
this.setFontSize(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
setFontSize(value) {
|
|
|
|
this.setState({ fontSize: value });
|
2016-11-08 19:11:07 +01:00
|
|
|
this.props.setFontSize(value);
|
2016-08-04 05:45:49 +02:00
|
|
|
}
|
2016-07-06 17:27:39 +02:00
|
|
|
|
2019-06-18 22:54:16 +02:00
|
|
|
decreaseFontSize() {
|
|
|
|
const newValue = this.state.fontSize - 2;
|
|
|
|
this.setFontSize(newValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
increaseFontSize() {
|
|
|
|
const newValue = this.state.fontSize + 2;
|
|
|
|
this.setFontSize(newValue);
|
|
|
|
}
|
|
|
|
|
2016-08-09 22:15:28 +02:00
|
|
|
handleUpdateAutosave(event) {
|
|
|
|
const value = event.target.value === 'true';
|
|
|
|
this.props.setAutosave(value);
|
|
|
|
}
|
|
|
|
|
2019-03-26 20:37:44 +01:00
|
|
|
handleUpdateLinewrap(event) {
|
|
|
|
const value = event.target.value === 'true';
|
|
|
|
this.props.setLinewrap(value);
|
|
|
|
}
|
|
|
|
|
2016-08-11 20:09:59 +02:00
|
|
|
handleLintWarning(event) {
|
|
|
|
const value = event.target.value === 'true';
|
|
|
|
this.props.setLintWarning(value);
|
|
|
|
}
|
|
|
|
|
2016-08-04 05:45:49 +02:00
|
|
|
render() {
|
2016-09-01 05:07:43 +02:00
|
|
|
const beep = new Audio(beepUrl);
|
2016-08-29 20:39:23 +02:00
|
|
|
|
2016-08-04 05:45:49 +02:00
|
|
|
return (
|
2018-05-09 04:10:52 +02:00
|
|
|
<section className="preferences" title="preference-menu">
|
2018-02-23 17:31:41 +01:00
|
|
|
<Helmet>
|
|
|
|
<title>p5.js Web Editor | Preferences</title>
|
|
|
|
</Helmet>
|
2017-08-09 19:34:59 +02:00
|
|
|
<Tabs>
|
|
|
|
<TabList>
|
|
|
|
<div className="preference__subheadings">
|
2017-08-16 20:23:13 +02:00
|
|
|
<Tab><h4 className="preference__subheading">General Settings</h4></Tab>
|
|
|
|
<Tab><h4 className="preference__subheading">Accessibility</h4></Tab>
|
2017-08-09 19:34:59 +02:00
|
|
|
</div>
|
|
|
|
</TabList>
|
|
|
|
<TabPanel>
|
|
|
|
<div className="preference">
|
|
|
|
<h4 className="preference__title">Theme</h4>
|
|
|
|
<div className="preference__options">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
onChange={() => this.props.setTheme('light')}
|
|
|
|
aria-label="light theme on"
|
|
|
|
name="light theme"
|
|
|
|
id="light-theme-on"
|
|
|
|
className="preference__radio-button"
|
|
|
|
value="light"
|
|
|
|
checked={this.props.theme === 'light'}
|
|
|
|
/>
|
|
|
|
<label htmlFor="light-theme-on" className="preference__option">Light</label>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
onChange={() => this.props.setTheme('dark')}
|
|
|
|
aria-label="dark theme on"
|
|
|
|
name="dark theme"
|
|
|
|
id="dark-theme-on"
|
|
|
|
className="preference__radio-button"
|
|
|
|
value="dark"
|
|
|
|
checked={this.props.theme === 'dark'}
|
|
|
|
/>
|
|
|
|
<label htmlFor="dark-theme-on" className="preference__option">Dark</label>
|
2017-11-14 21:27:00 +01:00
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
onChange={() => this.props.setTheme('contrast')}
|
|
|
|
aria-label="high contrast theme on"
|
|
|
|
name="high contrast theme"
|
|
|
|
id="high-contrast-theme-on"
|
|
|
|
className="preference__radio-button"
|
|
|
|
value="contrast"
|
|
|
|
checked={this.props.theme === 'contrast'}
|
|
|
|
/>
|
|
|
|
<label htmlFor="high-contrast-theme-on" className="preference__option">High Contrast</label>
|
2017-08-09 19:34:59 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="preference">
|
|
|
|
<h4 className="preference__title">Text size</h4>
|
|
|
|
<button
|
|
|
|
className="preference__minus-button"
|
2019-06-18 22:54:16 +02:00
|
|
|
onClick={this.decreaseFontSize}
|
2017-08-09 19:34:59 +02:00
|
|
|
aria-label="decrease font size"
|
2019-06-18 22:54:16 +02:00
|
|
|
disabled={this.state.fontSize <= 8}
|
2017-08-09 19:34:59 +02:00
|
|
|
>
|
|
|
|
<InlineSVG src={minusUrl} alt="Decrease Font Size" />
|
|
|
|
<h6 className="preference__label">Decrease</h6>
|
|
|
|
</button>
|
2019-06-18 22:54:16 +02:00
|
|
|
<form onSubmit={this.onFontInputSubmit}>
|
|
|
|
<input
|
|
|
|
className="preference__value"
|
|
|
|
aria-live="polite"
|
|
|
|
aria-atomic="true"
|
|
|
|
value={this.state.fontSize}
|
|
|
|
onChange={this.onFontInputChange}
|
2019-08-13 18:27:31 +02:00
|
|
|
type="text"
|
2019-06-18 22:54:16 +02:00
|
|
|
ref={(element) => { this.fontSizeInput = element; }}
|
2019-08-13 18:27:31 +02:00
|
|
|
onClick={() => { this.fontSizeInput.select(); }}
|
2019-06-18 22:54:16 +02:00
|
|
|
/>
|
|
|
|
</form>
|
2017-08-09 19:34:59 +02:00
|
|
|
<button
|
|
|
|
className="preference__plus-button"
|
2019-06-18 22:54:16 +02:00
|
|
|
onClick={this.increaseFontSize}
|
2017-08-09 19:34:59 +02:00
|
|
|
aria-label="increase font size"
|
2019-06-18 22:54:16 +02:00
|
|
|
disabled={this.state.fontSize >= 36}
|
2017-08-09 19:34:59 +02:00
|
|
|
>
|
|
|
|
<InlineSVG src={plusUrl} alt="Increase Font Size" />
|
|
|
|
<h6 className="preference__label">Increase</h6>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div className="preference">
|
|
|
|
<h4 className="preference__title">Autosave</h4>
|
|
|
|
<div className="preference__options">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
onChange={() => this.props.setAutosave(true)}
|
|
|
|
aria-label="autosave on"
|
|
|
|
name="autosave"
|
|
|
|
id="autosave-on"
|
|
|
|
className="preference__radio-button"
|
|
|
|
value="On"
|
|
|
|
checked={this.props.autosave}
|
|
|
|
/>
|
|
|
|
<label htmlFor="autosave-on" className="preference__option">On</label>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
onChange={() => this.props.setAutosave(false)}
|
|
|
|
aria-label="autosave off"
|
|
|
|
name="autosave"
|
|
|
|
id="autosave-off"
|
|
|
|
className="preference__radio-button"
|
|
|
|
value="Off"
|
|
|
|
checked={!this.props.autosave}
|
|
|
|
/>
|
|
|
|
<label htmlFor="autosave-off" className="preference__option">Off</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-03-26 20:37:44 +01:00
|
|
|
<div className="preference">
|
|
|
|
<h4 className="preference__title">Word Wrap</h4>
|
|
|
|
<div className="preference__options">
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
onChange={() => this.props.setLinewrap(true)}
|
|
|
|
aria-label="linewrap on"
|
|
|
|
name="linewrap"
|
|
|
|
id="linewrap-on"
|
|
|
|
className="preference__radio-button"
|
|
|
|
value="On"
|
|
|
|
checked={this.props.linewrap}
|
|
|
|
/>
|
|
|
|
<label htmlFor="linewrap-on" className="preference__option">On</label>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
onChange={() => this.props.setLinewrap(false)}
|
|
|
|
aria-label="linewrap off"
|
|
|
|
name="linewrap"
|
|
|
|
id="linewrap-off"
|
|
|
|
className="preference__radio-button"
|
|
|
|
value="Off"
|
|
|
|
checked={!this.props.linewrap}
|
|
|
|
/>
|
|
|
|
<label htmlFor="linewrap-off" className="preference__option">Off</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-08-09 19:34:59 +02:00
|
|
|
</TabPanel>
|
|
|
|
<TabPanel>
|
|
|
|
<div className="preference">
|
2017-11-14 22:27:42 +01:00
|
|
|
<h4 className="preference__title">Lint warning sound</h4>
|
2017-08-09 19:34:59 +02:00
|
|
|
<div className="preference__options">
|
|
|
|
<input
|
2017-08-17 14:51:00 +02:00
|
|
|
type="radio"
|
2017-11-14 22:27:42 +01:00
|
|
|
onChange={() => this.props.setLintWarning(true)}
|
|
|
|
aria-label="lint warning on"
|
|
|
|
name="lint warning"
|
|
|
|
id="lint-warning-on"
|
2017-08-17 14:51:00 +02:00
|
|
|
className="preference__radio-button"
|
2017-08-09 19:34:59 +02:00
|
|
|
value="On"
|
2017-11-14 22:27:42 +01:00
|
|
|
checked={this.props.lintWarning}
|
2017-08-09 19:34:59 +02:00
|
|
|
/>
|
2017-11-14 22:27:42 +01:00
|
|
|
<label htmlFor="lint-warning-on" className="preference__option">On</label>
|
2017-08-09 19:34:59 +02:00
|
|
|
<input
|
2017-08-17 14:51:00 +02:00
|
|
|
type="radio"
|
2017-11-14 22:27:42 +01:00
|
|
|
onChange={() => this.props.setLintWarning(false)}
|
|
|
|
aria-label="lint warning off"
|
|
|
|
name="lint warning"
|
|
|
|
id="lint-warning-off"
|
2017-08-17 14:51:00 +02:00
|
|
|
className="preference__radio-button"
|
2017-11-14 22:27:42 +01:00
|
|
|
value="Off"
|
|
|
|
checked={!this.props.lintWarning}
|
2017-08-09 19:34:59 +02:00
|
|
|
/>
|
2017-11-14 22:27:42 +01:00
|
|
|
<label htmlFor="lint-warning-off" className="preference__option">Off</label>
|
2017-08-17 14:51:00 +02:00
|
|
|
<button
|
|
|
|
className="preference__preview-button"
|
|
|
|
onClick={() => beep.play()}
|
|
|
|
aria-label="preview sound"
|
|
|
|
>
|
|
|
|
Preview sound
|
|
|
|
</button>
|
2017-08-09 19:34:59 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="preference">
|
2017-11-14 22:27:42 +01:00
|
|
|
<h4 className="preference__title">Accessible text-based canvas</h4>
|
|
|
|
<h6 className="preference__subtitle">Used with screen reader</h6>
|
|
|
|
|
2017-08-09 19:34:59 +02:00
|
|
|
<div className="preference__options">
|
|
|
|
<input
|
2017-11-14 22:27:42 +01:00
|
|
|
type="checkbox"
|
|
|
|
onChange={(event) => {
|
|
|
|
this.props.setTextOutput(event.target.checked);
|
|
|
|
}}
|
|
|
|
aria-label="text output on"
|
|
|
|
name="text output"
|
|
|
|
id="text-output-on"
|
2017-08-09 19:34:59 +02:00
|
|
|
value="On"
|
2017-11-14 22:27:42 +01:00
|
|
|
checked={(this.props.textOutput)}
|
2017-08-09 19:34:59 +02:00
|
|
|
/>
|
2017-11-14 22:27:42 +01:00
|
|
|
<label htmlFor="text-output-on" className="preference__option preference__canvas">Plain-text</label>
|
2017-08-09 19:34:59 +02:00
|
|
|
<input
|
2017-11-14 22:27:42 +01:00
|
|
|
type="checkbox"
|
|
|
|
onChange={(event) => {
|
|
|
|
this.props.setGridOutput(event.target.checked);
|
|
|
|
}}
|
|
|
|
aria-label="table output on"
|
|
|
|
name="table output"
|
|
|
|
id="table-output-on"
|
|
|
|
value="On"
|
|
|
|
checked={(this.props.gridOutput)}
|
2017-08-09 19:34:59 +02:00
|
|
|
/>
|
2017-11-14 22:27:42 +01:00
|
|
|
<label htmlFor="table-output-on" className="preference__option preference__canvas">Table-text</label>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
onChange={(event) => {
|
|
|
|
this.props.setSoundOutput(event.target.checked);
|
|
|
|
}}
|
|
|
|
aria-label="sound output on"
|
|
|
|
name="sound output"
|
|
|
|
id="sound-output-on"
|
|
|
|
value="On"
|
|
|
|
checked={(this.props.soundOutput)}
|
|
|
|
/>
|
|
|
|
<label htmlFor="sound-output-on" className="preference__option preference__canvas">Sound</label>
|
2017-08-09 19:34:59 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|
2016-08-04 05:45:49 +02:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
2016-06-24 00:29:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-27 21:57:36 +02:00
|
|
|
Preferences.propTypes = {
|
|
|
|
fontSize: PropTypes.number.isRequired,
|
2016-08-09 22:15:28 +02:00
|
|
|
setFontSize: PropTypes.func.isRequired,
|
|
|
|
autosave: PropTypes.bool.isRequired,
|
2019-03-26 20:37:44 +01:00
|
|
|
linewrap: PropTypes.bool.isRequired,
|
2016-08-11 20:09:59 +02:00
|
|
|
setAutosave: PropTypes.func.isRequired,
|
2019-03-26 20:37:44 +01:00
|
|
|
setLinewrap: PropTypes.func.isRequired,
|
2017-05-31 21:23:30 +02:00
|
|
|
textOutput: PropTypes.bool.isRequired,
|
|
|
|
gridOutput: PropTypes.bool.isRequired,
|
2017-11-14 22:27:42 +01:00
|
|
|
soundOutput: PropTypes.bool.isRequired,
|
2016-08-12 21:50:33 +02:00
|
|
|
setTextOutput: PropTypes.func.isRequired,
|
2017-05-31 21:23:30 +02:00
|
|
|
setGridOutput: PropTypes.func.isRequired,
|
2017-11-14 22:27:42 +01:00
|
|
|
setSoundOutput: PropTypes.func.isRequired,
|
2016-08-11 20:09:59 +02:00
|
|
|
lintWarning: PropTypes.bool.isRequired,
|
2016-09-13 20:15:46 +02:00
|
|
|
setLintWarning: PropTypes.func.isRequired,
|
|
|
|
theme: PropTypes.string.isRequired,
|
2018-05-09 04:10:52 +02:00
|
|
|
setTheme: PropTypes.func.isRequired,
|
2017-09-22 15:36:25 +02:00
|
|
|
};
|
|
|
|
|
2016-08-05 03:43:13 +02:00
|
|
|
export default Preferences;
|