Demo update

This commit is contained in:
Francisco Hodge 2019-11-07 11:26:19 -05:00
parent 0c481cb29a
commit 70b99b44c6
3 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,75 @@
import Keyboard from "../lib";
import "./css/MultipleKeyboardsDestroyDemo.css";
const setDOM = () => {
document.querySelector("#root").innerHTML = `
<input class="input" placeholder="Tap on the virtual keyboard to start" />
<div class="simple-keyboard"></div>
<input class="input2" placeholder="Tap on the virtual keyboard to start" />
<div class="keyboard2"></div>
`;
};
class Demo {
constructor() {
setDOM();
/**
* Demo Start
*/
this.keyboard = new Keyboard({
onChange: input => this.onChange(input),
onKeyPress: button => this.onKeyPress(button),
debug: true
});
this.keyboard2 = new Keyboard(".keyboard2", {
theme: "simple-keyboard hg-theme-default",
onChange: input => this.onChange(input, "input2"),
onKeyPress: button => this.onKeyPress(button, "keyboard2"),
debug: true
});
console.log(this.keyboard);
setTimeout(this.keyboard.destroy, 10000);
/**
* Update simple-keyboard when input is changed directly
*/
document.querySelector(".input").addEventListener("input", event => {
this.keyboard.setInput(event.target.value);
});
document.querySelector(".input2").addEventListener("input", event => {
this.keyboard2.setInput(event.target.value);
});
}
onChange(input, inputClass) {
document.querySelector(`.${inputClass || "input"}`).value = input;
console.log("Input changed", input);
}
onKeyPress(button, keyboardInstanceKey) {
console.log("Button pressed", button);
/**
* If you want to handle the shift and caps lock buttons
*/
if (button === "{shift}" || button === "{lock}")
this.handleShift(keyboardInstanceKey);
}
handleShift(keyboardInstanceKey) {
let keyboard = this[keyboardInstanceKey || "keyboard"];
let currentLayout = keyboard.options.layoutName;
let shiftToggle = currentLayout === "default" ? "shift" : "default";
keyboard.setOptions({
layoutName: shiftToggle
});
}
}
export default Demo;

View File

@ -0,0 +1,12 @@
input {
width: 100%;
height: 100px;
padding: 20px;
font-size: 20px;
border: none;
box-sizing: border-box;
}
.simple-keyboard {
max-width: 850px;
}

View File

@ -6,6 +6,7 @@ import "./css/index.css";
import BasicDemo from "./BasicDemo";
//import FullKeyboardDemo from "./FullKeyboardDemo";
//import ButtonThemeDemo from "./ButtonThemeDemo";
//import MultipleKeyboardsDemo from "./MultipleKeyboardsDestroyDemo";
/**
* Selected demo