1 import { Component, ElementRef, forwardRef, Input, ViewChild } from '@angular/core'
2 import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3 import { Notifier } from '@app/core'
6 selector: 'my-input-text',
7 templateUrl: './input-text.component.html',
8 styleUrls: [ './input-text.component.scss' ],
11 provide: NG_VALUE_ACCESSOR,
12 useExisting: forwardRef(() => InputTextComponent),
17 export class InputTextComponent implements ControlValueAccessor {
18 @ViewChild('input') inputElement: ElementRef
20 @Input() inputId = Math.random().toString(11).slice(2, 8) // id cannot be left empty or undefined
22 @Input() autocomplete = 'off'
23 @Input() placeholder = ''
25 @Input() withToggle = true
26 @Input() withCopy = false
27 @Input() readonly = false
29 @Input() formError: string
31 constructor (private notifier: Notifier) { }
46 this.show = !this.show
49 activateCopiedMessage () {
50 this.notifier.success($localize`Copied`)
53 propagateChange = (_: any) => { /* empty */ }
55 writeValue (value: string) {
59 registerOnChange (fn: (_: any) => void) {
60 this.propagateChange = fn
63 registerOnTouched () {
68 this.propagateChange(this.value)
72 const el: HTMLElement = this.inputElement.nativeElement
74 el.focus({ preventScroll: true })