Skip to content

Commit d455fb6

Browse files
committed
[Component] Add component for keyboard
1 parent d661f3e commit d455fb6

File tree

7 files changed

+101
-0
lines changed

7 files changed

+101
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"ngx-clipboard": "^14.0.1",
5050
"ngx-perfect-scrollbar": "^10.1.1",
5151
"rxjs": "~6.6.0",
52+
"simple-keyboard": "^3.3.22",
5253
"tslib": "^2.1.0",
5354
"zone.js": "~0.11.4"
5455
},

src/renderer/app/layout/layout.routing.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ const LAYOUT_ROUTES: Routes = [
5252
{
5353
path: 'progressbar',
5454
loadChildren: () => import('../pages/component/progressbar/progressbar.module').then(m => m.ProgressbarComponentModule)
55+
},
56+
{
57+
path: 'keyboard',
58+
loadChildren: () => import('../pages/component/keyboard/keyboard.module').then(m => m.KeyboardModule)
5559
}
5660
]
5761
},

src/renderer/app/layout/navigation/navigation.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
<li routerLinkActive="navigation__active">
3535
<a [routerLink]="['/component/progressbar']"><i class="fa fa-pagelines"></i> Progressbar</a>
3636
</li>
37+
<li routerLinkActive="navigation__active">
38+
<a [routerLink]="['/component/keyboard']"><i class="fa fa-keyboard-o"></i> Keyboard</a>
39+
</li>
3740
</ul>
3841
</li>
3942
<li routerLinkActive="navigation__sub--active" class="navigation__sub">
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<section class="content--row">
2+
<header class="content__title">
3+
<h1>Keyboard</h1>
4+
<small>This template is built using <code>simple-keyboard</code> and provides some usage examples</small>
5+
</header>
6+
<div class="card-demo">
7+
<div class="card">
8+
<div class="card-body">
9+
<h4 class="card-title">Keyboard</h4>
10+
<div class="form-group">
11+
<input type="text" class="form-control form-control-lg" (input)="onInputChange($event)" value="{{value}}"
12+
placeholder="Tap on the virtual keyboard to start">
13+
<i class="form-group__bar"></i>
14+
</div>
15+
<div class="simple-keyboard"></div>
16+
</div>
17+
</div>
18+
</div>
19+
</section>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
2+
import Keyboard from 'simple-keyboard';
3+
4+
@Component({
5+
selector: 'app-root',
6+
encapsulation: ViewEncapsulation.None,
7+
templateUrl: './keyboard.component.html',
8+
styleUrls: [
9+
'../../../../../../node_modules/simple-keyboard/build/css/index.css'
10+
]
11+
})
12+
export class KeyboardComponent implements OnInit {
13+
value = '';
14+
keyboard: Keyboard;
15+
16+
constructor() {
17+
}
18+
19+
ngOnInit(): void {
20+
}
21+
22+
// eslint-disable-next-line @angular-eslint/use-lifecycle-interface
23+
ngAfterViewInit() {
24+
this.keyboard = new Keyboard({
25+
onChange: input => this.onChange(input),
26+
onKeyPress: button => this.onKeyPress(button)
27+
});
28+
}
29+
30+
onChange = (input: string) => {
31+
this.value = input;
32+
};
33+
onKeyPress = (button: string) => {
34+
if (button === '{shift}' || button === '{lock}') {
35+
this.handleShift();
36+
}
37+
};
38+
onInputChange = (event: any) => {
39+
this.keyboard.setInput(event.target.value);
40+
};
41+
handleShift = () => {
42+
const currentLayout = this.keyboard.options.layoutName;
43+
const shiftToggle = currentLayout === 'default' ? 'shift' : 'default';
44+
this.keyboard.setOptions({
45+
layoutName: shiftToggle
46+
});
47+
};
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { NgModule } from '@angular/core';
2+
import { KeyboardComponent } from '@renderer/app/pages/component/keyboard/keyboard.component';
3+
import { CommonModule } from '@angular/common';
4+
import { RouterModule } from '@angular/router';
5+
6+
const KEYBOARD_ROUTES = [
7+
{path: '', component: KeyboardComponent}
8+
];
9+
10+
@NgModule({
11+
declarations: [
12+
KeyboardComponent
13+
],
14+
imports: [
15+
CommonModule,
16+
RouterModule.forChild(KEYBOARD_ROUTES)
17+
],
18+
providers: []
19+
})
20+
export class KeyboardModule {
21+
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8942,6 +8942,11 @@ signal-exit@^3.0.0, signal-exit@^3.0.2, signal-exit@^3.0.3:
89428942
resolved "https://registry.npm.taobao.org/signal-exit/download/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"
89438943
integrity sha1-oUEMLt2PB3sItOJTyOrPyvBXRhw=
89448944

8945+
simple-keyboard@^3.3.22:
8946+
version "3.3.22"
8947+
resolved "https://registry.yarnpkg.com/simple-keyboard/-/simple-keyboard-3.3.22.tgz#33aab849cc15779b9ea174d7a75a178471929d89"
8948+
integrity sha512-dXuqORS0XbmkzAIB9lRhyDq3lbq3FManY6RgBKteC6sCirvNLT5TgMSX0v4eDLxBaBRbE/J5nV1ixQgFpzuNsw==
8949+
89458950
slash@^3.0.0:
89468951
version "3.0.0"
89478952
resolved "https://registry.npm.taobao.org/slash/download/slash-3.0.0.tgz?cache=0&sync_timestamp=1618384496016&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fslash%2Fdownload%2Fslash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"

0 commit comments

Comments
 (0)