mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-03-16 00:11:07 +08:00
Adding multiple input demo, per request
This commit is contained in:
parent
f8ebb30d76
commit
d407413cce
@ -1,5 +1,5 @@
|
|||||||
import Keyboard from '../lib';
|
import Keyboard from '../lib';
|
||||||
import './App.css';
|
import './css/App.css';
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
constructor(){
|
constructor(){
|
||||||
@ -18,6 +18,15 @@ class App {
|
|||||||
|
|
||||||
this.keyboard.setInput("Hello World!");
|
this.keyboard.setInput("Hello World!");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adding preview (demo only)
|
||||||
|
*/
|
||||||
|
document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', `
|
||||||
|
<div class="simple-keyboard-preview">
|
||||||
|
<textarea class="input" readonly>Hello World!</textarea>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
|
||||||
console.log(this.keyboard);
|
console.log(this.keyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
77
src/demo/MultipleInputsDemo.js
Normal file
77
src/demo/MultipleInputsDemo.js
Normal file
@ -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', `
|
||||||
|
<div>
|
||||||
|
<label>Input 1</label>
|
||||||
|
<input class="input" id="input1" value=""/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>Input 2</label>
|
||||||
|
<input class="input" id="input2" value=""/>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
40
src/demo/css/MultipleInputsDemo.css
Normal file
40
src/demo/css/MultipleInputsDemo.css
Normal file
@ -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;
|
||||||
|
}
|
@ -4,12 +4,3 @@ import App from './App';
|
|||||||
* Initializing demo
|
* Initializing demo
|
||||||
*/
|
*/
|
||||||
new App();
|
new App();
|
||||||
|
|
||||||
/**
|
|
||||||
* Adding preview (demo only)
|
|
||||||
*/
|
|
||||||
document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', `
|
|
||||||
<div class="simple-keyboard-preview">
|
|
||||||
<textarea class="input" readonly>Hello World!</textarea>
|
|
||||||
</div>
|
|
||||||
`);
|
|
Loading…
x
Reference in New Issue
Block a user