diff --git a/src/demo/App.js b/src/demo/App.js index 8ef65f2b..3a83b6a0 100644 --- a/src/demo/App.js +++ b/src/demo/App.js @@ -1,5 +1,5 @@ import Keyboard from '../lib'; -import './App.css'; +import './css/App.css'; class App { constructor(){ @@ -17,6 +17,15 @@ class App { }); this.keyboard.setInput("Hello World!"); + + /** + * Adding preview (demo only) + */ + document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', ` +
+ +
+ `); console.log(this.keyboard); } diff --git a/src/demo/MultipleInputsDemo.js b/src/demo/MultipleInputsDemo.js new file mode 100644 index 00000000..95ff8ef5 --- /dev/null +++ b/src/demo/MultipleInputsDemo.js @@ -0,0 +1,77 @@ +import Keyboard from '../lib'; +import './css/MultipleInputsDemo.css'; + +class App { + constructor(){ + document.addEventListener('DOMContentLoaded', this.onDOMLoaded); + + this.layoutName = "default"; + } + + onDOMLoaded = () => { + this.keyboard = new Keyboard({ + debug: true, + layoutName: this.layoutName, + onChange: input => this.onChange(input), + onKeyPress: button => this.onKeyPress(button) + }); + + /** + * Adding preview (demo only) + * In production, this would be part of your HTML file + */ + document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', ` +
+ + +
+
+ + +
+ `); + + /** + * Changing active input onFocus + */ + document.querySelectorAll('.input') + .forEach(input => input.addEventListener('focus', this.onInputFocus)); + + console.log(this.keyboard); + } + + onInputFocus = event => { + this.selectedInput = `#${event.target.id}`; + + this.keyboard.setOptions({ + inputName: event.target.id + }); + } + + onChange = input => { + let currentInput = this.selectedInput || '.input'; + document.querySelector(currentInput).value = input; + } + + onKeyPress = button => { + console.log("Button pressed", button); + + /** + * Shift functionality + */ + if(button === "{lock}" || button === "{shift}") + this.handleShiftButton(); + } + + handleShiftButton = () => { + let layoutName = this.layoutName; + let shiftToggle = this.layoutName = layoutName === "default" ? "shift" : "default"; + + this.keyboard.setOptions({ + layoutName: shiftToggle + }); + } + +} + +export default App; \ No newline at end of file diff --git a/src/demo/App.css b/src/demo/css/App.css similarity index 100% rename from src/demo/App.css rename to src/demo/css/App.css diff --git a/src/demo/css/MultipleInputsDemo.css b/src/demo/css/MultipleInputsDemo.css new file mode 100644 index 00000000..d8ca0fdd --- /dev/null +++ b/src/demo/css/MultipleInputsDemo.css @@ -0,0 +1,40 @@ +#root { + font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; + max-width: 1000px; + margin: 0 auto; + padding-top: 20px; +} + +#root .screenContainer { + background: rgba(0,0,0,0.8); + border: 20px solid; + height: 300px; + border-top-right-radius: 5px; + border-top-left-radius: 5px; + padding: 10px; + box-sizing: border-box; +} + +#root .inputContainer { + color: white; + background: transparent; + border: none; + outline: none; + font-family: monospace; + width: 100%; + height: 100%; +} + +.simple-keyboard.hg-layout-custom { + border-top-left-radius: 0px; + border-top-right-radius: 0px; +} + +input { + padding: 10px; + margin: 10px 0; +} + +label { + display: block; +} \ No newline at end of file diff --git a/src/demo/index.js b/src/demo/index.js index 359f80d3..a35f9085 100644 --- a/src/demo/index.js +++ b/src/demo/index.js @@ -3,13 +3,4 @@ import App from './App'; /** * Initializing demo */ -new App(); - -/** - * Adding preview (demo only) - */ -document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', ` -
- -
-`); \ No newline at end of file +new App(); \ No newline at end of file