]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-forms/input-text.component.ts
Replace all glyphicon icons
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-forms / input-text.component.ts
CommitLineData
f8b530e0
RK
1import { Component, forwardRef, Input } from '@angular/core'
2import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
3import { Notifier } from '@app/core'
93c728a2 4import { GlobalIconName } from '../shared-icons'
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 18export 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
93c728a2
C
51 getEyeIcon (): GlobalIconName {
52 if (this.show) return 'sensitive'
53
54 return 'unsensitive'
55 }
56
f8b530e0
RK
57 propagateChange = (_: any) => { /* empty */ }
58
59 writeValue (value: string) {
60 this.value = value
61 }
62
63 registerOnChange (fn: (_: any) => void) {
64 this.propagateChange = fn
65 }
66
67 registerOnTouched () {
68 // Unused
69 }
70
71 update () {
72 this.propagateChange(this.value)
73 }
74}