]>
Commit | Line | Data |
---|---|---|
f8b530e0 RK |
1 | import { Component, forwardRef, Input } from '@angular/core' |
2 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' | |
3 | import { Notifier } from '@app/core' | |
dc1296a9 | 4 | |
f8b530e0 RK |
5 | |
6 | @Component({ | |
a70bf3bd C |
7 | selector: 'my-input-text', |
8 | templateUrl: './input-text.component.html', | |
9 | styleUrls: [ './input-text.component.scss' ], | |
f8b530e0 RK |
10 | providers: [ |
11 | { | |
12 | provide: NG_VALUE_ACCESSOR, | |
a70bf3bd | 13 | useExisting: forwardRef(() => InputTextComponent), |
f8b530e0 RK |
14 | multi: true |
15 | } | |
16 | ] | |
17 | }) | |
a70bf3bd | 18 | export class InputTextComponent implements ControlValueAccessor { |
1916c966 | 19 | @Input() inputId = Math.random().toString(11).slice(2, 8) // id cannot be left empty or undefined |
f8b530e0 RK |
20 | @Input() value = '' |
21 | @Input() autocomplete = 'off' | |
22 | @Input() placeholder = '' | |
23cd3129 | 23 | @Input() tabindex = 0 |
f8b530e0 RK |
24 | @Input() withToggle = true |
25 | @Input() withCopy = false | |
26 | @Input() readonly = false | |
27 | @Input() show = false | |
28 | ||
29 | constructor (private notifier: Notifier) { } | |
30 | ||
31 | get inputType () { | |
32 | return this.show | |
33 | ? 'text' | |
34 | : 'password' | |
35 | } | |
36 | ||
37 | get toggleTitle () { | |
38 | return this.show | |
39 | ? $localize`Hide` | |
40 | : $localize`Show` | |
41 | } | |
42 | ||
43 | toggle () { | |
44 | this.show = !this.show | |
45 | } | |
46 | ||
47 | activateCopiedMessage () { | |
48 | this.notifier.success($localize`Copied`) | |
49 | } | |
50 | ||
51 | propagateChange = (_: any) => { /* empty */ } | |
52 | ||
53 | writeValue (value: string) { | |
54 | this.value = value | |
55 | } | |
56 | ||
57 | registerOnChange (fn: (_: any) => void) { | |
58 | this.propagateChange = fn | |
59 | } | |
60 | ||
61 | registerOnTouched () { | |
62 | // Unused | |
63 | } | |
64 | ||
65 | update () { | |
66 | this.propagateChange(this.value) | |
67 | } | |
68 | } |