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