aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-forms/input-text.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/shared-forms/input-text.component.ts')
-rw-r--r--client/src/app/shared/shared-forms/input-text.component.ts67
1 files changed, 67 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-forms/input-text.component.ts b/client/src/app/shared/shared-forms/input-text.component.ts
new file mode 100644
index 000000000..ed4637c17
--- /dev/null
+++ b/client/src/app/shared/shared-forms/input-text.component.ts
@@ -0,0 +1,67 @@
1import { Component, forwardRef, Input } from '@angular/core'
2import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3import { Notifier } from '@app/core'
4
5@Component({
6 selector: 'my-input-text',
7 templateUrl: './input-text.component.html',
8 styleUrls: [ './input-text.component.scss' ],
9 providers: [
10 {
11 provide: NG_VALUE_ACCESSOR,
12 useExisting: forwardRef(() => InputTextComponent),
13 multi: true
14 }
15 ]
16})
17export class InputTextComponent implements ControlValueAccessor {
18 @Input() inputId = Math.random().toString(11).slice(2, 8) // id cannot be left empty or undefined
19 @Input() value = ''
20 @Input() autocomplete = 'off'
21 @Input() placeholder = ''
22 @Input() tabindex = 0
23 @Input() withToggle = true
24 @Input() withCopy = false
25 @Input() readonly = false
26 @Input() show = false
27
28 constructor (private notifier: Notifier) { }
29
30 get inputType () {
31 return this.show
32 ? 'text'
33 : 'password'
34 }
35
36 get toggleTitle () {
37 return this.show
38 ? $localize`Hide`
39 : $localize`Show`
40 }
41
42 toggle () {
43 this.show = !this.show
44 }
45
46 activateCopiedMessage () {
47 this.notifier.success($localize`Copied`)
48 }
49
50 propagateChange = (_: any) => { /* empty */ }
51
52 writeValue (value: string) {
53 this.value = value
54 }
55
56 registerOnChange (fn: (_: any) => void) {
57 this.propagateChange = fn
58 }
59
60 registerOnTouched () {
61 // Unused
62 }
63
64 update () {
65 this.propagateChange(this.value)
66 }
67}