diff --git a/index.html b/index.html
index e3279f5..41aad9b 100755
--- a/index.html
+++ b/index.html
@@ -13,33 +13,6 @@
Keep Talking and Nobody Explodes
-
-
Keypads
diff --git a/ktane.js b/ktane.js
index 75273f9..ad9987b 100755
--- a/ktane.js
+++ b/ktane.js
@@ -39,35 +39,6 @@ $('section').each(function () {
id && $('#navList').append($('').append($a));
});
-(function () {
- /**
- * Button
- */
- var $section = $('#sectionButton'),
- $instruction = $section.find('.instruction'),
- instruction;
-
- $section.find('input').on('click', function () {
- var colour = $('input[name="buttonColour"]:checked').val(),
- text = $('input[name="buttonText"]:checked').val();
-
- if (text === 'Detonate') {
- instruction = 'If 2+ \ud83d\udd0b, press and release.
Otherwise, hold button.'
- } else if (colour === 'white') {
- instruction = 'If CAR, hold button.
Otherwise, if 3+ \ud83d\udd0b and FRK, press and release.
Otherwise, hold button.'
- } else if (colour === 'blue' && text === 'Abort'
- || colour === 'yellow') {
- instruction = 'Hold button.';
- } else if (colour === 'red' && text === 'Hold') {
- instruction = 'Press and release.';
- } else {
- instruction = 'If 3+ \ud83d\udd0b and FRK, press and release the button.
Otherwise, hold button.';
- }
-
- $instruction.html(instruction);
- }).triggerHandler('click');
-})();
-
(function () {
/**
* Keypads
diff --git a/src/App.css b/src/App.css
index 47d3fa6..756bac5 100755
--- a/src/App.css
+++ b/src/App.css
@@ -112,17 +112,6 @@ nav {
padding: 0.1em 0.5em;
}
-#sectionButton {
- line-height: 150%;
-}
-#sectionButton div {
- margin-bottom: 1em;
-}
-#sectionButton .buttonWhite {
- border-style: solid;
- border-width: 1px;
-}
-
#sectionKeypads ul {
display: inline-block;
list-style-type: none;
diff --git a/src/App.js b/src/App.js
index d3e7183..d34ae6d 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,5 +1,6 @@
import React from 'react';
import './App.css';
+import ButtonModule from "./components/ButtonModule";
import WiresModule from "./components/WiresModule";
function App() {
@@ -9,7 +10,8 @@ function App() {
Keep Talking and Nobody Explodes
-
+
+
);
}
diff --git a/src/components/ButtonModule.js b/src/components/ButtonModule.js
new file mode 100644
index 0000000..71188bc
--- /dev/null
+++ b/src/components/ButtonModule.js
@@ -0,0 +1,112 @@
+import ButtonModuleColourInput from "./ButtonModuleColourInput";
+import ButtonModuleTextInput from "./ButtonModuleTextInput";
+import KtaneModule from "./KtaneModule";
+import React from "react";
+import "../css/ButtonModule.css";
+
+export default class ButtonModule extends KtaneModule {
+ constructor(props) {
+ super(props);
+
+ this.colourBlue = "blue";
+ this.colourWhite = "white";
+ this.colourYellow = "yellow";
+ this.colourRed = "red";
+ this.allColours = [this.colourBlue, this.colourWhite, this.colourYellow, this.colourRed];
+
+ this.textAbort = "Abort";
+ this.textDetonate = "Detonate";
+ this.textHold = "Hold";
+ this.textPress = "Press";
+ this.allText = [this.textAbort, this.textDetonate, this.textHold, this.textPress];
+
+ this.setColour = this.setColour.bind(this);
+ this.setText = this.setText.bind(this);
+ }
+
+ getInstruction() {
+ if (this.state.text === this.textDetonate) {
+ return <>If 2+ 🔋, press and release.
Otherwise, hold button.>;
+ } else if (this.state.colour === this.colourWhite) {
+ return <>
+ If CAR, hold button.
+ Otherwise, if 3+ 🔋 and FRK, press and release.
+ Otherwise, hold button.
+ >;
+ } else if ((this.state.colour === this.colourBlue && this.state.text === this.textAbort) || this.state.colour === this.colourYellow) {
+ return "Hold button.";
+ } else if (this.state.colour === this.colourRed && this.state.text === this.textHold) {
+ return "Press and release.";
+ } else {
+ return <>
+ If 3+ 🔋 and FRK, press and release the button.
+
Otherwise, hold button.
+ >;
+ }
+ }
+
+ getTitle() {
+ return "Button";
+ }
+
+ mainRender() {
+ return (
+ <>
+
+ Colour:
+ {
+ this.allColours.map(colour => (
+
+ ))
+ }
+
+
+
+ Text:
+ {
+ this.allText.map(text => (
+
+ ))
+ }
+
+
+ {this.getInstruction()}
+
+
+ If holding button, release when the timer contains the digit that corresponds to the strip colour:
+
+ - Blue: 4
+ - Yellow: 5
+ - Other: 1
+
+
+ >
+ )
+ }
+
+ resetState() {
+ // @TODO Put string literals into constants
+ this.state = {
+ colour: "blue",
+ text: "Abort"
+ };
+ }
+
+ setColour(event) {
+ this.setState({colour: event.target.value});
+ }
+
+ setText(event) {
+ this.setState({text: event.target.value});
+ }
+}
diff --git a/src/components/ButtonModuleColourInput.js b/src/components/ButtonModuleColourInput.js
new file mode 100644
index 0000000..fc67eda
--- /dev/null
+++ b/src/components/ButtonModuleColourInput.js
@@ -0,0 +1,31 @@
+import PropTypes from 'prop-types';
+import React, {Component} from "react";
+
+export default class ButtonModuleColourInput extends Component {
+ render() {
+ return (
+
+ )
+ }
+
+ shouldComponentUpdate(nextProps) {
+ return this.props.stateColour !== nextProps.stateColour;
+ }
+}
+
+ButtonModuleColourInput.propTypes = {
+ colour: PropTypes.string,
+ onChange: PropTypes.func,
+ stateColour: PropTypes.string
+};
diff --git a/src/components/ButtonModuleTextInput.js b/src/components/ButtonModuleTextInput.js
new file mode 100644
index 0000000..eafb7a7
--- /dev/null
+++ b/src/components/ButtonModuleTextInput.js
@@ -0,0 +1,28 @@
+import PropTypes from 'prop-types';
+import React, {Component} from "react";
+
+export default class ButtonModuleTextInput extends Component {
+ render() {
+ return (
+
+ )
+ }
+
+ shouldComponentUpdate(nextProps) {
+ return this.props.stateText !== nextProps.stateText;
+ }
+}
+
+ButtonModuleTextInput.propTypes = {
+ onChange: PropTypes.func,
+ stateText: PropTypes.string,
+ text: PropTypes.string
+};
diff --git a/src/css/ButtonModule.css b/src/css/ButtonModule.css
new file mode 100644
index 0000000..a3900de
--- /dev/null
+++ b/src/css/ButtonModule.css
@@ -0,0 +1,10 @@
+#sectionButton {
+ line-height: 150%;
+}
+#sectionButton div {
+ margin-bottom: 1em;
+}
+#sectionButton .buttonWhite {
+ border-style: solid;
+ border-width: 1px;
+}