aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-forms/input-toggle-hidden.component.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-04 15:58:55 +0100
committerRigel Kent <sendmemail@rigelk.eu>2020-12-04 16:01:53 +0100
commitf8b530e0a523a0d9ff469ef716838374c395a360 (patch)
treea55d49365e539582dd5000a2c73b9351df93a52d /client/src/app/shared/shared-forms/input-toggle-hidden.component.ts
parentaa5ee5017a83b280352f8dbcfed2d4741709a4fd (diff)
downloadPeerTube-f8b530e0a523a0d9ff469ef716838374c395a360.tar.gz
PeerTube-f8b530e0a523a0d9ff469ef716838374c395a360.tar.zst
PeerTube-f8b530e0a523a0d9ff469ef716838374c395a360.zip
unify inputs requiring buttons like password inputs
Diffstat (limited to 'client/src/app/shared/shared-forms/input-toggle-hidden.component.ts')
-rw-r--r--client/src/app/shared/shared-forms/input-toggle-hidden.component.ts66
1 files changed, 66 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-forms/input-toggle-hidden.component.ts b/client/src/app/shared/shared-forms/input-toggle-hidden.component.ts
new file mode 100644
index 000000000..0e974426b
--- /dev/null
+++ b/client/src/app/shared/shared-forms/input-toggle-hidden.component.ts
@@ -0,0 +1,66 @@
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-toggle-hidden',
7 templateUrl: './input-toggle-hidden.component.html',
8 styleUrls: [ './input-toggle-hidden.component.scss' ],
9 providers: [
10 {
11 provide: NG_VALUE_ACCESSOR,
12 useExisting: forwardRef(() => InputToggleHiddenComponent),
13 multi: true
14 }
15 ]
16})
17export class InputToggleHiddenComponent implements ControlValueAccessor {
18 @Input() id = 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() withToggle = true
23 @Input() withCopy = false
24 @Input() readonly = false
25 @Input() show = false
26
27 constructor (private notifier: Notifier) { }
28
29 get inputType () {
30 return this.show
31 ? 'text'
32 : 'password'
33 }
34
35 get toggleTitle () {
36 return this.show
37 ? $localize`Hide`
38 : $localize`Show`
39 }
40
41 toggle () {
42 this.show = !this.show
43 }
44
45 activateCopiedMessage () {
46 this.notifier.success($localize`Copied`)
47 }
48
49 propagateChange = (_: any) => { /* empty */ }
50
51 writeValue (value: string) {
52 this.value = value
53 }
54
55 registerOnChange (fn: (_: any) => void) {
56 this.propagateChange = fn
57 }
58
59 registerOnTouched () {
60 // Unused
61 }
62
63 update () {
64 this.propagateChange(this.value)
65 }
66}