mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-04-21 09:46:24 +08:00
Demo update
This commit is contained in:
parent
0c481cb29a
commit
70b99b44c6
75
src/demo/MultipleKeyboardsDestroyDemo.js
Normal file
75
src/demo/MultipleKeyboardsDestroyDemo.js
Normal 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;
|
12
src/demo/css/MultipleKeyboardsDestroyDemo.css
Normal file
12
src/demo/css/MultipleKeyboardsDestroyDemo.css
Normal 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;
|
||||||
|
}
|
@ -6,6 +6,7 @@ import "./css/index.css";
|
|||||||
import BasicDemo from "./BasicDemo";
|
import BasicDemo from "./BasicDemo";
|
||||||
//import FullKeyboardDemo from "./FullKeyboardDemo";
|
//import FullKeyboardDemo from "./FullKeyboardDemo";
|
||||||
//import ButtonThemeDemo from "./ButtonThemeDemo";
|
//import ButtonThemeDemo from "./ButtonThemeDemo";
|
||||||
|
//import MultipleKeyboardsDemo from "./MultipleKeyboardsDestroyDemo";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selected demo
|
* Selected demo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user