Compare commits

..
62 Commits
Author SHA1 Message Date
Francisco Hodge ad17363173 Fix README typo 2018-08-21 20:14:42 -04:00
Francisco Hodge 1fe93ba6dd Readme update 2018-08-14 17:00:51 -04:00
Francisco Hodge 7e968e07b8 Readme update 2018-08-14 16:45:54 -04:00
Francisco Hodge 6c5026da34 Updating readme 2018-08-13 21:43:12 -04:00
Francisco Hodge 38f178cc18 Readme update 2018-08-13 21:26:34 -04:00
Francisco Hodge 8e3b0e18c0 Reset className on clear() 2018-08-13 14:48:21 -04:00
Francisco Hodge c32a8a9568 maintenance: npm audit fix performed 2018-08-13 13:39:50 -04:00
Francisco Hodge 705b5acf53 npm bin update 2018-08-07 10:31:14 -04:00
Francisco Hodge d4886c1f6f npm update 2018-08-07 09:08:36 -04:00
Francisco Hodge 6ba68a21e6 npm version bump 2018-08-03 14:47:36 -04:00
Francisco Hodge 958019199a Removing peer dependencies 2018-08-03 14:46:53 -04:00
Francisco Hodge 65bf9362bd Dist update 2018-07-31 12:02:22 -04:00
Francisco Hodge f4a5d946d6 npm version update 2018-07-31 12:00:02 -04:00
Francisco Hodge 12fcae865e Changed key "delete" to "backspace" as per suggestion 2018-07-31 11:58:19 -04:00
Francisco Hodge 5b84982812 npm version bump 2018-07-19 10:13:27 -04:00
Francisco Hodge be6d1b0f93 Update badges 2018-07-19 10:13:09 -04:00
Francisco Hodge 0f5dad0527 Switching to JSDelivr for CDN use case 2018-07-13 17:23:28 -04:00
Francisco Hodge 94c14df816 Disable tap to zoom on IOS10+ 2018-07-13 17:08:35 -04:00
Francisco Hodge 4206e02ca2 Readme update 2018-07-05 17:24:26 -04:00
Francisco Hodge 3b1e9c131a Updated README links 2018-07-05 17:20:58 -04:00
Francisco Hodge e7b604f6b1 Added multiple inputs live demo 2018-07-03 19:10:47 -04:00
Francisco Hodge 66ae70f29a update example links 2018-06-29 22:29:40 -04:00
Francisco Hodge 470bdc8e74 readme links update 2018-06-29 22:26:35 -04:00
Francisco Hodge 0533b4c2c2 npm bump 2018-06-29 21:43:44 -04:00
Francisco Hodge 5a7fef7643 Updated README with buttonTheme example 2018-06-29 21:43:22 -04:00
Francisco Hodge d88912cd23 Build update 2018-06-29 20:43:07 -04:00
Francisco Hodge e138f1fd6f Support multiple classes for themeButtons 2018-06-29 20:41:14 -04:00
Francisco Hodge 0581247fbe Build update 2018-06-29 20:17:44 -04:00
Francisco Hodge d8d8d460c2 Updated dependencies, bump npm version 2018-06-29 20:17:04 -04:00
Francisco Hodge 8b8d90f248 Slightly updating demo css 2018-06-29 20:10:19 -04:00
Francisco Hodge 42e47ef8f9 Adding clearer colors for Keyboard 2018-06-29 20:04:31 -04:00
Francisco Hodge 1e16bde389 Single button styling support (buttonTheme) 2018-06-29 20:01:29 -04:00
Francisco Hodge 201542b189 Minor typo fix 2018-06-29 19:59:03 -04:00
Francisco Hodge 41b23cca89 README update 2018-06-08 10:59:11 -04:00
Francisco Hodge b2df5cf09e npm version bump 2018-06-08 10:40:30 -04:00
Francisco Hodge 10bbcdd89c Updating README cdn usage example 2018-06-08 10:39:20 -04:00
Francisco Hodge 3b75d11b9c Update build 2018-06-08 10:28:50 -04:00
Francisco Hodge 71136a0d5e Webpack config adjustment 2018-06-08 10:15:21 -04:00
Francisco Hodge 1aafdeee0a npm bump 2018-06-08 09:57:53 -04:00
Francisco Hodge 41c87430ff npm bump 2018-05-30 23:16:41 -04:00
Francisco Hodge ff2476a331 README typo fix 2018-05-30 23:15:01 -04:00
Francisco Hodge 894483e6a7 Adding editable CodeSandbox examples 2018-05-30 22:28:51 -04:00
Francisco Hodge cbef48eb3c npm version bump 2018-05-02 13:01:16 -04:00
Francisco Hodge 2769002ff6 Adding further comments on multiple input example 2018-05-02 12:41:29 -04:00
Francisco Hodge 04088f63c1 Fix image path 2018-04-30 15:33:15 -04:00
Francisco Hodge 69ed611788 Bump npm version 2018-04-30 12:47:31 -04:00
Francisco Hodge dbed641621 Updating documentation 2018-04-30 12:47:18 -04:00
Francisco Hodge d1e6630247 README cleanup 2018-04-30 11:11:31 -04:00
Francisco Hodge d8e8b6076a Updating dist 2018-04-30 11:07:21 -04:00
Francisco Hodge 7c292d04bf Adding inputName, setOptions, Use-cases documentation 2018-04-30 11:05:55 -04:00
Francisco Hodge f91e50a1b2 Bump npm version 2018-04-30 10:37:44 -04:00
Francisco Hodge c7eb4ba4d3 Adding newLineOnEnter in demo 2018-04-30 10:37:09 -04:00
Francisco Hodge d407413cce Adding multiple input demo, per request 2018-04-30 10:36:05 -04:00
Francisco Hodge f8ebb30d76 Adding Multiple Input support 2018-04-30 10:35:51 -04:00
Francisco Hodge 276a478eb6 Fix typo 2018-04-24 10:10:20 -04:00
Francisco Hodge c239e21625 Updated examples 2018-04-24 10:06:23 -04:00
Francisco Hodge d42036ec3e bump npm version 2018-04-24 09:39:00 -04:00
Francisco Hodge cbd1506f53 Improved readme examples 2018-04-24 09:38:14 -04:00
Francisco Hodge d477c35cce Adding build to git for user convenience 2018-04-24 09:18:55 -04:00
Francisco Hodge 4362e486a5 readme fix 2018-04-23 06:35:37 -04:00
Francisco Hodge 2502bcc910 bump npm version 2018-04-21 18:04:44 -04:00
Francisco Hodge df42db3b95 ES6 initial setup 2018-04-20 16:34:02 -04:00
24 changed files with 4080 additions and 3107 deletions
-1
View File
@@ -4,7 +4,6 @@
/node_modules
# production
/build
/demo
# testing
+251 -64
View File
@@ -1,57 +1,102 @@
# simple-keyboard
[![npm version](https://badge.fury.io/js/simple-keyboard.svg)](https://www.npmjs.com/package/simple-keyboard)
[![](https://data.jsdelivr.com/v1/package/npm/simple-keyboard/badge)](https://www.jsdelivr.com/package/npm/simple-keyboard)
[![npm](https://img.shields.io/npm/v/simple-keyboard.svg)](https://www.npmjs.com/package/simple-keyboard)
[![Dependencies](https://img.shields.io/david/hodgef/simple-keyboard.svg)](https://www.npmjs.com/package/simple-keyboard)
[![Dev Dependencies](https://img.shields.io/david/dev/hodgef/simple-keyboard.svg)](https://www.npmjs.com/package/simple-keyboard)
[![npm downloads](https://img.shields.io/npm/dm/simple-keyboard.svg)](https://www.npmjs.com/package/simple-keyboard)
<a href="https://franciscohodge.com/simple-keyboard/demo" title="View Demo"><img src="https://franciscohodge.com/project-pages/simple-keyboard/images/simple-keyboard-banner2.png" align="center" width="100%"></a>
[![NPM](https://nodei.co/npm/simple-keyboard.png)](https://npmjs.com/package/simple-keyboard)
> An easily customisable and responsive on-screen virtual keyboard for React.js projects.
<img src="src/demo/images/keyboard.PNG" align="center" width="100%">
> The easily customisable and responsive on-screen virtual keyboard for Javascript projects.
## Installation
### npm
`npm install simple-keyboard --save`
## Usage
### zip file (self-hosted)
[Click here to download the latest release (zip format).](https://github.com/hodgef/simple-keyboard/zipball/master)
> Want to use a CDN instead of self-host? Scroll down to the "Usage with CDN" instructions below.
## Usage with npm
### js
````js
import React, {Component} from 'react';
import Keyboard from 'simple-keyboard';
import 'simple-keyboard/build/css/index.css';
class App extends Component {
let keyboard = new Keyboard({
onChange: input => onChange(input),
onKeyPress: button => onKeyPress(button)
});
onChange = (input) => {
console.log("Input changed", input);
}
onKeyPress = (button) => {
console.log("Button pressed", button);
}
render(){
return (
<Keyboard
onChange={input =>
this.onChange(input)}
onKeyPress={button =>
this.onKeyPress(button)}
/>
);
}
function onChange(input){
document.querySelector(".input").value = input;
console.log("Input changed", input);
}
export default App;
function onKeyPress(button){
console.log("Button pressed", button);
}
````
### html
````html
<input class="input" />
<div class="simple-keyboard"></div>
````
[![Edit krzkx19rr](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/krzkx19rr)
> Need a more extensive example? [Click here](https://github.com/hodgef/simple-keyboard/blob/master/src/demo/App.js).
## Usage with CDN
### html
````html
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/simple-keyboard@latest/build/css/index.css">
</head>
<body>
<input class="input" placeholder="Tap on the virtual keyboard to start" />
<div class="simple-keyboard"></div>
<script src="https://cdn.jsdelivr.net/npm/simple-keyboard@latest/build/index.min.js"></script>
<script src="src/index.js"></script>
</body>
</html>
````
### js (index.js)
````js
let Keyboard = window.SimpleKeyboard.default;
let myKeyboard = new Keyboard({
onChange: input => onChange(input),
onKeyPress: button => onKeyPress(button)
});
function onChange(input) {
document.querySelector(".input").value = input;
console.log("Input changed", input);
}
function onKeyPress(button) {
console.log("Button pressed", button);
}
````
[![Edit 6n0wzxjmjk](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/6n0wzxjmjk)
## Options
You can customize the Keyboard by passing options (props) to it.
You can customize the Keyboard by passing options to it.
Here are the available options (the code examples are the defaults):
### layout
@@ -59,7 +104,7 @@ Here are the available options (the code examples are the defaults):
> Modify the keyboard layout
```js
layout={{
layout: {
'default': [
'` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
'{tab} q w e r t y u i o p [ ] \\',
@@ -74,24 +119,26 @@ layout={{
'{shift} Z X C V B N M < > ? {shift}',
'.com @ {space}'
]
}}
}
```
> Looking for keyboard layouts in other languages? **Check out [simple-keyboard-layouts](https://github.com/hodgef/simple-keyboard-layouts) !**
### layoutName
> Specifies which layout should be used.
```js
layoutName={"default"}
layoutName: "default"
```
### display
> Replaces variable buttons (such as `{bksp}`) with a human-friendly name (e.g.: "delete").
> Replaces variable buttons (such as `{bksp}`) with a human-friendly name (e.g.: "backspace").
```js
display={{
'{bksp}': 'delete',
display: {
'{bksp}': 'backspace',
'{enter}': '< enter',
'{shift}': 'shift',
'{s}': 'shift',
@@ -100,23 +147,44 @@ display={{
'{accept}': 'Submit',
'{space}': ' ',
'{//}': ' '
}}
}
```
### theme
> A prop to add your own css classes. You can add multiple classes separated by a space.
> A prop to add your own css classes _to the keyboard wrapper_. You can add multiple classes separated by a space.
```js
theme={"hg-theme-default"}
theme: "hg-theme-default"
```
### buttonTheme
> A prop to add your own css classes _to one or several buttons_. You can add multiple classes separated by a space.
```js
buttonTheme: [
{
class: "myCustomClass",
buttons: "Q W E R T Y q w e r t y"
},
{
class: "anotherCustomClass",
buttons: "Q q"
},
...
]
```
[![Edit simple-keyboard customization demo - npm](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/vj8jvz2q4l?module=%2Fsrc%2Findex.js)
### debug
> Runs a console.log every time a key is pressed. Displays the buttons pressed and the current input.
```js
debug={false}
debug: false
```
### newLineOnEnter
@@ -124,22 +192,54 @@ debug={false}
> Specifies whether clicking the "ENTER" button will input a newline (`\n`) or not.
```js
newLineOnEnter={true}
newLineOnEnter: false
```
### inputName
> Allows you to use a single simple-keyboard instance for several inputs.
```js
inputName: "default"
```
### onKeyPress
> Executes the callback function on key press. Returns button layout name (i.e.: "{shift}").
```js
onKeyPress: (button) => console.log(button)
```
### onChange
> Executes the callback function on input change. Returns the current input's string.
```js
onChange: (input) => console.log(input)
```
### onChangeAll
> Executes the callback function on input change. Returns the input object with all defined inputs. This is useful if you're handling several inputs with simple-keyboard, as specified in the "*[Using several inputs](#using-several-inputs)*" guide.
```js
onChangeAll: (inputs) => console.log(inputs)
```
## Methods
simple-keybord has a few methods you can use to further control it's behavior.
To access these functions, you need a `ref` of the simple-keyboard component, like so:
simple-keyboard has a few methods you can use to further control it's behavior.
To access these functions, you need the instance the simple-keyboard component, like so:
```js
<Keyboard
ref={r => this.keyboard = r}
[...]
var keyboard = new Keyboard({
...
});
/>
// Then, on componentDidMount ..
this.keyboard.methodName(params);
// Then, use as follows...
keyboard.methodName(params);
```
### clearInput
@@ -147,7 +247,12 @@ this.keyboard.methodName(params);
> Clear the keyboard's input.
```js
this.keyboard.clearInput();
// For default input (i.e. if you have only one)
keyboard.clearInput();
// For specific input
// Must have been previously set using the "inputName" prop.
keyboard.clearInput("inputName");
```
### getInput
@@ -155,39 +260,121 @@ this.keyboard.clearInput();
> Get the keyboard's input (You can also get it from the _onChange_ prop).
```js
let input = this.keyboard.getInput();
// For default input (i.e. if you have only one)
let input = keyboard.getInput();
// For specific input
// Must have been previously set using the "inputName" prop.
let input = keyboard.getInput("inputName");
```
### setInput
> Set the keyboard's input. Useful if you want the keybord to initialize with a default value, for example.
> Set the keyboard's input. Useful if you want to track input changes made outside simple-keyboard.
```js
this.keyboard.setInput("Hello World!");
// For default input (i.e. if you have only one)
keyboard.setInput("Hello World!");
// For specific input
// Must have been previously set using the "inputName" prop.
keyboard.setInput("Hello World!", "inputName");
```
It returns a promise, so if you want to run something after it's applied, call it as so:
### setOptions
> Set new option or modify existing ones after initialization. The changes are applied immediately.
```js
let inputSetPromise = this.keyboard.setInput("Hello World!");
inputSetPromise.then((result) => {
console.log("Input set");
keyboard.setOptions({
theme: "my-custom-theme"
});
```
## Use-cases
### Using several inputs
Set the *[inputName](#inputname)* option for each input you want to handle with simple-keyboard.
For example:
```html
<input class="input" id="input1" value=""/>
<input class="input" id="input2" value=""/>
```
```js
// Here we'll store the input id that simple-keyboard will be using.
var selectedInput;
// Initialize simple-keyboard as usual
var keyboard = new Keyboard({
onChange: input => onChange(input)
});
// Add an event listener for the inputs to be tracked
document.querySelectorAll('.input')
.forEach(input => input.addEventListener('focus', onInputFocus));
/**
* When an input is focused, it will be marked as selected (selectedInput)
* This is so we can replace it's value on the onChange function
*
* Also, we will set the inputName option to a unique string identifying the input (id)
* simple-keyboard save the input in this key and report changes through onChange
*/
onInputFocus = event => {
// Setting input as selected
selectedInput = `#${event.target.id}`;
// Set the inputName option on the fly !
keyboard.setOptions({
inputName: event.target.id
});
}
// When the current input is changed, this is called
onChange = input => {
// If the input is not defined, grabbing the first ".input".
let currentInput = selectedInput || '.input';
// Updating the selected input's value
document.querySelector(currentInput).value = input;
}
```
> [See full example](https://github.com/hodgef/simple-keyboard/blob/master/src/demo/MultipleInputsDemo.js).
[![Edit simple-keyboard multiple inputs demo - npm](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/43nm6v4xyx?module=%2Fsrc%2Findex.js)
### Having keys in a different language configuration
There's a number of key layouts available. To apply them, check out [simple-keyboard-layouts](https://github.com/hodgef/simple-keyboard-layouts).
<a href="https://github.com/hodgef/simple-keyboard-layouts" title="simple-keyboard-layouts repository"><img src="https://franciscohodge.com/project-pages/simple-keyboard/images/simple-keyboard-banner3layouts.png" align="center"></a>
If you'd like to contribute your own layouts, please submit your pull request at the simple-keyboard-layouts repository.
## Demo
<img src="src/demo/images/demo.gif" align="center" width="600">
[https://franciscohodge.com/simple-keyboard/demo](https://franciscohodge.com/simple-keyboard/demo)
To run demo on your own computer:
[![Edit krzkx19rr](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/krzkx19rr)
### To run demo on your own computer
* Clone this repository
* `npm install`
* `npm start`
* Visit [http://localhost:3000/](http://localhost:3000/)
## Note
### Other versions
This is a work in progress. Feel free to submit any issues you have at:
* ReactJS - [react-simple-keyboard](https://github.com/hodgef/react-simple-keyboard)
## Contributing
PR's and issues are welcome. Feel free to submit any issues you have at:
[https://github.com/hodgef/simple-keyboard/issues](https://github.com/hodgef/simple-keyboard/issues)
+10
View File
@@ -0,0 +1,10 @@
console.log('\x1b[36m%s\x1b[0m', `
______________________________________\n`);
console.log('\x1b[33m%s\x1b[0m', `Thank you for installing simple-keyboard !`);
console.log('\x1b[36m%s\x1b[0m', `
Please consider starring the repository so others can also find it.
https://github.com/hodgef/simple-keyboard/stargazers
______________________________________
`);
+2
View File
@@ -0,0 +1,2 @@
body,html{margin:0;padding:0}.simple-keyboard{font-family:HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;width:100%;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-box-sizing:border-box;box-sizing:border-box;overflow:hidden;-ms-touch-action:manipulation;touch-action:manipulation}.simple-keyboard .hg-row{display:-ms-flexbox;display:flex}.simple-keyboard .hg-row:not(:last-child){margin-bottom:5px}.simple-keyboard .hg-row .hg-button:not(:last-child){margin-right:5px}.simple-keyboard .hg-button{display:inline-block;-ms-flex-positive:1;flex-grow:1;cursor:pointer}.hg-standardBtn{max-width:100px}.simple-keyboard.hg-theme-default{background-color:rgba(0,0,0,.1);padding:5px;border-radius:5px}.simple-keyboard.hg-theme-default .hg-button{-webkit-box-shadow:0 0 3px -1px rgba(0,0,0,.3);box-shadow:0 0 3px -1px rgba(0,0,0,.3);height:40px;border-radius:5px;-webkit-box-sizing:border-box;box-sizing:border-box;padding:5px;background:#fff;border-bottom:1px solid #b5b5b5}.simple-keyboard.hg-theme-default .hg-button:active{background:#e4e4e4}.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button{width:33.3%;height:60px;-ms-flex-align:center;align-items:center;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center}
/*# sourceMappingURL=index.css.map*/
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["webpack:///./src/lib/components/Keyboard.css"],"names":[],"mappings":"AAAA,UACE,SACA,SAAW,CAGb,iBACE,6GACA,WACA,yBACG,sBACC,qBACI,iBACR,8BACQ,sBACR,gBACA,8BACI,yBAA2B,CAGjC,yBACE,oBACA,YAAc,CAGhB,0CACE,iBAAmB,CAGrB,qDACE,gBAAkB,CAGpB,4BACE,qBACA,oBACI,YACJ,cAAgB,CAGlB,gBACE,eAAiB,CAMnB,kCACE,gCACA,YACA,iBAAmB,CAGrB,6CACE,+CACQ,uCACR,YACA,kBACA,8BACQ,sBACR,YACA,gBACA,+BAAiC,CAGlC,oDACC,kBAAoB,CAGtB,+DACE,YACA,YACA,sBACI,mBACJ,oBACA,aACA,qBACI,sBAAwB","file":"css/index.css","sourcesContent":["body, html {\r\n margin: 0;\r\n padding: 0;\r\n}\r\n\r\n.simple-keyboard {\r\n font-family: \"HelveticaNeue-Light\", \"Helvetica Neue Light\", \"Helvetica Neue\", Helvetica, Arial, \"Lucida Grande\", sans-serif;\r\n width: 100%;\r\n -webkit-user-select: none;\r\n -moz-user-select: none;\r\n -ms-user-select: none;\r\n user-select: none;\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n overflow: hidden;\r\n -ms-touch-action: manipulation;\r\n touch-action: manipulation;\r\n}\r\n\r\n.simple-keyboard .hg-row {\r\n display: -ms-flexbox;\r\n display: flex;\r\n}\r\n\r\n.simple-keyboard .hg-row:not(:last-child) {\r\n margin-bottom: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-row .hg-button:not(:last-child) {\r\n margin-right: 5px;\r\n}\r\n\r\n.simple-keyboard .hg-button {\r\n display: inline-block;\r\n -ms-flex-positive: 1;\r\n flex-grow: 1;\r\n cursor: pointer;\r\n}\r\n\r\n.hg-standardBtn {\r\n max-width: 100px;\r\n}\r\n\r\n/**\r\n * hg-theme-default theme\r\n */\r\n.simple-keyboard.hg-theme-default {\r\n background-color: rgba(0,0,0,0.1);\r\n padding: 5px;\r\n border-radius: 5px;\r\n }\r\n\r\n.simple-keyboard.hg-theme-default .hg-button {\r\n -webkit-box-shadow: 0px 0px 3px -1px rgba(0,0,0,0.3);\r\n box-shadow: 0px 0px 3px -1px rgba(0,0,0,0.3);\r\n height: 40px;\r\n border-radius: 5px;\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n padding: 5px;\r\n background: white;\r\n border-bottom: 1px solid #b5b5b5;\r\n }\r\n\r\n .simple-keyboard.hg-theme-default .hg-button:active {\r\n background: #e4e4e4;\r\n }\r\n\r\n.simple-keyboard.hg-theme-default.hg-layout-numeric .hg-button {\r\n width: 33.3%;\r\n height: 60px;\r\n -ms-flex-align: center;\r\n align-items: center;\r\n display: -ms-flexbox;\r\n display: flex;\r\n -ms-flex-pack: center;\r\n justify-content: center;\r\n}\n\n\n// WEBPACK FOOTER //\n// ./src/lib/components/Keyboard.css"],"sourceRoot":""}
+2
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -60,7 +60,8 @@ module.exports = {
// CRL: Updated whole block with library specific info
path: paths.appDemoBuild,
filename: 'index.js',
libraryTarget: 'umd'
libraryTarget: 'umd',
library: 'SimpleKeyboard'
},
resolve: {
// This allows you to set a fallback for where Webpack should look for modules.
+2 -1
View File
@@ -57,7 +57,8 @@ module.exports = {
// CRL: Updated whole block with library specific info
path: paths.appBuild,
filename: 'index.js',
libraryTarget: 'umd'
libraryTarget: 'umd',
library: 'SimpleKeyboard'
},
resolve: {
// This allows you to set a fallback for where Webpack should look for modules.
+3444 -2726
View File
File diff suppressed because it is too large Load Diff
+13 -15
View File
@@ -1,13 +1,14 @@
{
"name": "simple-keyboard",
"version": "1.1.2",
"description": "React.js Virtual Keyboard",
"version": "2.3.22",
"description": "On-screen Virtual Keyboard",
"main": "build/index.js",
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"demo": "node scripts/demo.js",
"test": "node scripts/test.js --env=jsdom",
"postinstall": "node bin/postinstall",
"prepublish": "npm run build"
},
"repository": {
@@ -18,27 +19,28 @@
"bugs": {
"url": "https://github.com/hodgef/simple-keyboard/issues"
},
"homepage": "https://github.com/hodgef/simple-keyboard",
"homepage": "https://franciscohodge.com/simple-keyboard",
"keywords": [
"react",
"reactjs",
"javascript",
"es6",
"digital",
"keyboard",
"onscreen",
"virtual",
"component",
"simple",
"easy"
"virtual-keyboard",
"touchscreen",
"touch-screen"
],
"license": "MIT",
"dependencies": {},
"devDependencies": {
"autoprefixer": "7.1.6",
"babel-core": "6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "7.2.3",
"babel-jest": "20.0.3",
"babel-loader": "7.1.2",
"babel-preset-react-app": "^3.1.0",
"babel-preset-react-app": "^3.1.2",
"babel-runtime": "6.26.0",
"case-sensitive-paths-webpack-plugin": "2.1.1",
"chalk": "1.1.3",
@@ -61,6 +63,7 @@
"postcss-flexbugs-fixes": "3.2.0",
"postcss-loader": "2.0.8",
"promise": "8.0.1",
"prop-types": "^15.6.1",
"raf": "3.4.0",
"react": "^16.2.0",
"react-dev-utils": "^4.2.1",
@@ -71,12 +74,7 @@
"webpack": "3.8.1",
"webpack-dev-server": "2.9.4",
"webpack-manifest-plugin": "1.3.2",
"whatwg-fetch": "2.0.3",
"prop-types": "^15.6.1"
},
"peerDependencies": {
"react": ">=0.14",
"react-dom": ">=0.14"
"whatwg-fetch": "2.0.3"
},
"jest": {
"collectCoverageFrom": [
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

+17 -3
View File
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
@@ -19,13 +19,27 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>simple-keyboard</title>
<style>
/**
* Disabling double-tap to zoom in iOS 10+
* as it interferes with simple-keyboard
*/
body,
html {
touch-action: manipulation;
}
</style>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<div id="root">
<div class="simple-keyboard"></div>
</div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
+41 -75
View File
@@ -1,93 +1,59 @@
import React, {Component} from 'react';
import Keyboard from '../lib';
import './App.css';
import './css/App.css';
class App extends Component {
state = {
input: '',
layoutName: "default"
class App {
constructor(){
document.addEventListener('DOMContentLoaded', this.onDOMLoaded);
this.layoutName = "default";
}
componentDidMount(){
this.keyboard.setInput("Hello World!")
.then(input => {
this.setState({input: input});
});
}
onChange = (input) => {
this.setState({
input: input
}, () => {
console.log("Input changed", input);
onDOMLoaded = () => {
this.keyboard = new Keyboard({
debug: true,
layoutName: this.layoutName,
onChange: input => this.onChange(input),
onKeyPress: button => this.onKeyPress(button),
newLineOnEnter: true
});
}
onKeyPress = (button) => {
console.log("Button pressed", button);
this.keyboard.setInput("Hello World!");
/**
* Shift functionality
* Adding preview (demo only)
*/
if(button === "{lock}" || button === "{shift}")
this.handleShiftButton();
document.querySelector('.simple-keyboard').insertAdjacentHTML('beforebegin', `
<div class="simple-keyboard-preview">
<textarea class="input" readonly>Hello World!</textarea>
</div>
`);
console.log(this.keyboard);
}
handleShiftButton = () => {
let layoutName = this.state.layoutName;
let shiftToggle = layoutName === "default" ? "shift" : "default";
this.setState({
let layoutName = this.layoutName;
let shiftToggle = this.layoutName = layoutName === "default" ? "shift" : "default";
this.keyboard.setOptions({
layoutName: shiftToggle
});
}
render(){
return (
<div className={"demoPage"}>
<div className={"screenContainer"}>
<textarea className={"inputContainer"} value={this.state.input} />
</div>
<Keyboard
ref={r => this.keyboard = r}
onChange={input => this.onChange(input)}
onKeyPress={button => this.onKeyPress(button)}
layoutName={this.state.layoutName}
layout={{
'default': [
'` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
'{tab} q w e r t y u i o p [ ] \\',
'{lock} a s d f g h j k l ; \' {enter}',
'{shift} z x c v b n m , . / {shift}',
'.com @ {space}'
],
'shift': [
'~ ! @ # $ % ^ & * ( ) _ + {bksp}',
'{tab} Q W E R T Y U I O P { } |',
'{lock} A S D F G H J K L : " {enter}',
'{shift} Z X C V B N M < > ? {shift}',
'.com @ {space}'
]
}}
theme={"hg-layout-default hg-theme-default"}
debug={true}
display={{
'{bksp}': 'delete',
'{enter}': '< enter',
'{shift}': 'shift',
'{s}': 'shift',
'{tab}': 'tab',
'{lock}': 'caps',
'{accept}': 'Submit',
'{space}': ' ',
'{//}': ' '
}}
/>
</div>
);
onChange = input => {
document.querySelector('.input').value = input;
}
onKeyPress = button => {
console.log("Button pressed", button);
/**
* Shift functionality
*/
if(button === "{lock}" || button === "{shift}")
this.handleShiftButton();
}
}
export default App;
+77
View 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;
+6 -5
View File
@@ -1,13 +1,13 @@
.demoPage {
#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;
}
.demoPage .screenContainer {
#root .simple-keyboard-preview {
background: rgba(0,0,0,0.8);
border: 20px solid;
border: 20px solid rgba(0,0,0,0.1);
height: 300px;
border-top-right-radius: 5px;
border-top-left-radius: 5px;
@@ -15,14 +15,15 @@
box-sizing: border-box;
}
.demoPage .inputContainer {
color: white;
#root .input {
color: rgba(255,255,255,0.9);
background: transparent;
border: none;
outline: none;
font-family: monospace;
width: 100%;
height: 100%;
font-size: 18px;
}
.simple-keyboard.hg-layout-custom {
+40
View 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;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

+4 -5
View File
@@ -1,7 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
/**
* Initializing demo
*/
new App();
-108
View File
@@ -1,108 +0,0 @@
// In production, we register a service worker to serve assets from local cache.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on the "N+1" visit to a page, since previously
// cached resources are updated in the background.
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
// This link also includes instructions on opting out of this behavior.
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
export default function register() {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Lets check if a service worker still exists or not.
checkValidServiceWorker(swUrl);
} else {
// Is not local host. Just register service worker
registerValidSW(swUrl);
}
});
}
}
function registerValidSW(swUrl) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the old content will have been purged and
// the fresh content will have been added to the cache.
// It's the perfect time to display a "New content is
// available; please refresh." message in your web app.
console.log('New content is available; please refresh.');
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
if (
response.status === 404 ||
response.headers.get('content-type').indexOf('javascript') === -1
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
}
}
+4 -4
View File
@@ -9,6 +9,7 @@ body, html {
user-select: none;
box-sizing: border-box;
overflow: hidden;
touch-action: manipulation;
}
.simple-keyboard .hg-row {
@@ -29,7 +30,7 @@ body, html {
cursor: pointer;
}
.simple-keyboard.hg-layout-default .hg-button.hg-standardBtn {
.hg-standardBtn {
max-width: 100px;
}
@@ -37,7 +38,7 @@ body, html {
* hg-theme-default theme
*/
.simple-keyboard.hg-theme-default {
background-color: rgba(0,0,0,0.2);
background-color: rgba(0,0,0,0.1);
padding: 5px;
border-radius: 5px;
}
@@ -45,12 +46,11 @@ body, html {
.simple-keyboard.hg-theme-default .hg-button {
box-shadow: 0px 0px 3px -1px rgba(0,0,0,0.3);
height: 40px;
border: 1px solid rgba(0,0,0,0.25);
border-radius: 5px;
box-sizing: border-box;
padding: 5px;
background: white;
border-bottom: 1px solid gray;
border-bottom: 1px solid #b5b5b5;
}
.simple-keyboard.hg-theme-default .hg-button:active {
+159 -95
View File
@@ -1,53 +1,40 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import './Keyboard.css';
// Services
import KeyboardLayout from '../services/KeyboardLayout';
import Utilities from '../services/Utilities';
class App extends Component {
state = {
input: ''
}
class SimpleKeyboard {
constructor(...params){
let keyboardDOMQuery = typeof params[0] === "string" ? params[0] : '.simple-keyboard';
let options = typeof params[0] === "object" ? params[0] : params[1];
componentWillReceiveProps = (nextProps) => {
if(
this.props !== nextProps
){
this.setState({
layoutName: nextProps.layoutName,
layout: nextProps.layout,
themeClass: nextProps.theme
});
}
}
if(!options)
options = {};
clearInput = () => {
this.setState({
input: ''
});
}
/**
* Processing options
*/
this.keyboardDOM = document.querySelector(keyboardDOMQuery);
this.options = options;
this.options.layoutName = this.options.layoutName || "default";
this.options.theme = this.options.theme || "hg-theme-default";
this.options.inputName = this.options.inputName || "default";
this.input = {};
this.input[this.options.inputName] = '';
this.keyboardDOMClass = keyboardDOMQuery.split('.').join("");
getInput = () => {
return this.state.input;
}
setInput = input => {
return new Promise(resolve => {
this.setState({
input: input
}, () => {
resolve(input);
});
})
.catch(reason => {
console.warn(reason);
});
/**
* Rendering keyboard
*/
if(this.keyboardDOM)
this.render();
else
console.error(`"${keyboardDOMQuery}" was not found in the DOM.`);
}
handleButtonClicked = (button) => {
let debug = this.props.debug;
let debug = this.options.debug;
/**
* Ignoring placeholder buttons
@@ -58,32 +45,32 @@ class App extends Component {
/**
* Calling onKeyPress
*/
if(typeof this.props.onKeyPress === "function")
this.props.onKeyPress(button);
if(typeof this.options.onKeyPress === "function")
this.options.onKeyPress(button);
/**
* Updating input
*/
let options = {
newLineOnEnter: this.props.newLineOnEnter !== false || true
newLineOnEnter: (this.options.newLineOnEnter === true)
}
let updatedInput = Utilities.getUpdatedInput(button, this.state.input, options);
if(!this.input[this.options.inputName])
this.input[this.options.inputName] = '';
if(this.state.input !== updatedInput){
this.setState({
input: updatedInput
}, () => {
if(debug){
console.log('Input changed:', this.state.input);
}
/**
* Calling onChange
*/
if(typeof this.props.onChange === "function")
this.props.onChange(this.state.input);
});
let updatedInput = Utilities.getUpdatedInput(button, this.input[this.options.inputName], options);
if(this.input[this.options.inputName] !== updatedInput){
this.input[this.options.inputName] = updatedInput;
if(debug)
console.log('Input changed:', this.input);
/**
* Calling onChange
*/
if(typeof this.options.onChange === "function")
this.options.onChange(this.input[this.options.inputName]);
}
if(debug){
@@ -91,48 +78,125 @@ class App extends Component {
}
}
render() {
let layoutName = this.props.layoutName || "default";
let layout = this.props.layout || KeyboardLayout.getLayout(layoutName);
let themeClass = this.props.theme || "hg-theme-default";
let layoutClass = this.props.layout ? "hg-layout-custom" : `hg-layout-${layoutName}`;
clearInput = (inputName) => {
inputName = inputName || this.options.inputName;
this.input[this.options.inputName] = '';
}
return (
<div className={`simple-keyboard ${themeClass} ${layoutClass}`}>
{layout[layoutName].map((row, index) => {
let rowArray = row.split(' ');
getInput = (inputName) => {
inputName = inputName || this.options.inputName;
return this.input[this.options.inputName];
}
return (
<div key={`hg-row-${index}`} className="hg-row">
{rowArray.map((button, index) => {
let fctBtnClass = Utilities.getButtonClass(button);
let buttonDisplayName = Utilities.getButtonDisplayName(button, this.props.display);
setInput = (input, inputName) => {
inputName = inputName || this.options.inputName;
this.input[inputName] = input;
}
return (
<div
key={`hg-button-${index}`}
className={`hg-button ${fctBtnClass}`}
onClick={() => this.handleButtonClicked(button)}
><span>{buttonDisplayName}</span></div>
);
})}
</div>
);
})}
</div>
);
setOptions = option => {
option = option || {};
this.options = Object.assign(this.options, option);
this.render();
}
clear = () => {
this.keyboardDOM.innerHTML = '';
this.keyboardDOM.className = this.keyboardDOMClass;
}
render = () => {
/**
* Clear keyboard
*/
this.clear();
let layoutClass = this.options.layout ? "hg-layout-custom" : `hg-layout-${this.options.layoutName}`;
let layout = this.options.layout || KeyboardLayout.getLayout(this.options.layoutName);
/**
* Account for buttonTheme, if set
*/
let buttonThemesParsed = {};
if(Array.isArray(this.options.buttonTheme)){
this.options.buttonTheme.forEach(themeObj => {
if(themeObj.buttons && themeObj.class){
let themeButtons = themeObj.buttons.split(' ');
if(Array.isArray(themeButtons)){
themeButtons.forEach(themeButton => {
let themeParsed = buttonThemesParsed[themeButton];
// If the button has already been added
if(themeParsed)
buttonThemesParsed[themeButton] = `${themeParsed} ${themeObj.class}`;
else
buttonThemesParsed[themeButton] = themeObj.class;
});
}
} else {
console.warn(`buttonTheme row is missing the "buttons" or the "class". Please check the documentation.`)
}
});
}
/**
* Adding themeClass, layoutClass to keyboardDOM
*/
this.keyboardDOM.className += ` ${this.options.theme} ${layoutClass}`;
/**
* Iterating through each row
*/
layout[this.options.layoutName].forEach((row) => {
let rowArray = row.split(' ');
/**
* Creating empty row
*/
var rowDOM = document.createElement('div');
rowDOM.className += "hg-row";
/**
* Iterating through each button in row
*/
rowArray.forEach((button) => {
let fctBtnClass = Utilities.getButtonClass(button);
let buttonThemeClass = buttonThemesParsed[button];
let buttonDisplayName = Utilities.getButtonDisplayName(button, this.options.display);
/**
* Creating button
*/
var buttonDOM = document.createElement('div');
buttonDOM.className += `hg-button ${fctBtnClass}${buttonThemeClass ? " "+buttonThemeClass : ""}`;
buttonDOM.onclick = () => this.handleButtonClicked(button);
/**
* Adding button label to button
*/
var buttonSpanDOM = document.createElement('span');
buttonSpanDOM.innerHTML = buttonDisplayName;
buttonDOM.appendChild(buttonSpanDOM);
/**
* Appending button to row
*/
rowDOM.appendChild(buttonDOM);
/**
* Calling onInit
*/
if(typeof this.options.onInit === "function")
this.options.onInit();
});
/**
* Appending row to keyboard
*/
this.keyboardDOM.appendChild(rowDOM);
});
}
}
App.propTypes = {
layoutName: PropTypes.string,
layout: PropTypes.object,
theme: PropTypes.string,
display: PropTypes.object,
onChange: PropTypes.func,
onKeyPress: PropTypes.func,
debug: PropTypes.bool
};
export default App;
export default SimpleKeyboard;
+2 -2
View File
@@ -1,2 +1,2 @@
import Keyboard from './components/Keyboard';
export default Keyboard;
import SimpleKeyboard from './components/Keyboard';
export default SimpleKeyboard;
+2 -2
View File
@@ -53,7 +53,7 @@ class Utilities {
static getDefaultDiplay(){
return {
'{bksp}': 'delete',
'{bksp}': 'backspace',
'{enter}': '< enter',
'{shift}': 'shift',
'{s}': 'shift',
@@ -82,7 +82,7 @@ class Utilities {
output = output + "\t";
else if(button === "{enter}" && newLineOnEnter)
output = output + "\n";
else if(!button.includes("{") && !button.includes("{"))
else if(!button.includes("{") && !button.includes("}"))
output = output + button;
return output;