import { Component, AfterViewInit, ViewEncapsulation, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core'; import Keyboard from 'simple-keyboard'; @Component({ selector: 'rh-alphabet-keyboard', encapsulation: ViewEncapsulation.None, templateUrl: './alphabet-keyboard.component.html', styleUrls: ['./alphabet-keyboard.component.less'] }) export class RhAlphabetKeyboardComponent implements OnChanges, AfterViewInit { // private visible = true; // @Input() // get rhVisible() { // return this.visible; // } // set rhVisible(value: boolean) { // this.visible = value; // this.rhVisibleChange.emit(value); // } @Output() rhClose = new EventEmitter(); @Input() rhValue = ''; @Output() rhValueChange = new EventEmitter(); // value = ''; keyboard!: Keyboard; constructor() { // } ngOnChanges(changes: SimpleChanges): void { const { rhValue } = changes; if (!rhValue?.currentValue) { this.keyboard.clearInput(); } } ngAfterViewInit() { this.keyboard = new Keyboard({ onChange: (input) => this.onChange(input), onKeyPress: (button) => this.onKeyPress(button) }); } // onInputChange = (event: RhSafeAny) => { // this.keyboard?.setInput(event.target.value); // // this.inputChagne.emit(event.target.value); // }; closeKeyboard() { this.rhClose.emit(); } private onChange = (input: string) => { this.rhValue = input; this.rhValueChange.emit(input); // console.log('input changed', input); }; private onKeyPress = (button: string) => { // console.log('button pressed', button); if (button === '{shift}' || button === '{lock}') { this.handleShift(); } }; private handleShift() { const currentLayout = this.keyboard?.options.layoutName; const shiftToggle = currentLayout === 'default' ? 'shift' : 'default'; this.keyboard?.setOptions({ layoutName: shiftToggle }); } }