diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-04 15:58:55 +0100 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2020-12-04 16:01:53 +0100 |
commit | f8b530e0a523a0d9ff469ef716838374c395a360 (patch) | |
tree | a55d49365e539582dd5000a2c73b9351df93a52d /client/src/app/shared/shared-forms | |
parent | aa5ee5017a83b280352f8dbcfed2d4741709a4fd (diff) | |
download | PeerTube-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')
9 files changed, 95 insertions, 35 deletions
diff --git a/client/src/app/shared/shared-forms/dynamic-form-field.component.html b/client/src/app/shared/shared-forms/dynamic-form-field.component.html index 6a3c31637..658d8ce5b 100644 --- a/client/src/app/shared/shared-forms/dynamic-form-field.component.html +++ b/client/src/app/shared/shared-forms/dynamic-form-field.component.html | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | <input *ngIf="setting.type === 'input'" type="text" [id]="setting.name" [formControlName]="setting.name" /> | 6 | <input *ngIf="setting.type === 'input'" type="text" [id]="setting.name" [formControlName]="setting.name" /> |
7 | 7 | ||
8 | <input *ngIf="setting.type === 'input-password'" type="password" [id]="setting.name" [formControlName]="setting.name" /> | 8 | <my-input-toggle-hidden *ngIf="setting.type === 'input-password'" [formControlName]="setting.name" [id]="setting.name"></my-input-toggle-hidden> |
9 | 9 | ||
10 | <textarea *ngIf="setting.type === 'input-textarea'" type="text" [id]="setting.name" [formControlName]="setting.name"></textarea> | 10 | <textarea *ngIf="setting.type === 'input-textarea'" type="text" [id]="setting.name" [formControlName]="setting.name"></textarea> |
11 | 11 | ||
diff --git a/client/src/app/shared/shared-forms/index.ts b/client/src/app/shared/shared-forms/index.ts index 66b426191..1d859b991 100644 --- a/client/src/app/shared/shared-forms/index.ts +++ b/client/src/app/shared/shared-forms/index.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | export * from './form-validator.service' | 1 | export * from './form-validator.service' |
2 | export * from './form-reactive' | 2 | export * from './form-reactive' |
3 | export * from './select' | 3 | export * from './select' |
4 | export * from './input-readonly-copy.component' | 4 | export * from './input-toggle-hidden.component' |
5 | export * from './input-switch.component' | 5 | export * from './input-switch.component' |
6 | export * from './markdown-textarea.component' | 6 | export * from './markdown-textarea.component' |
7 | export * from './peertube-checkbox.component' | 7 | export * from './peertube-checkbox.component' |
diff --git a/client/src/app/shared/shared-forms/input-readonly-copy.component.html b/client/src/app/shared/shared-forms/input-readonly-copy.component.html deleted file mode 100644 index 7a75bd70b..000000000 --- a/client/src/app/shared/shared-forms/input-readonly-copy.component.html +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | <div class="input-group input-group-sm"> | ||
2 | <input [id]="id" #urlInput (click)="urlInput.select()" type="text" class="form-control readonly" readonly [value]="value" /> | ||
3 | |||
4 | <div class="input-group-append"> | ||
5 | <button [cdkCopyToClipboard]="urlInput.value" (click)="activateCopiedMessage()" type="button" class="btn btn-outline-secondary"> | ||
6 | <span class="glyphicon glyphicon-copy"></span> | ||
7 | </button> | ||
8 | </div> | ||
9 | </div> | ||
diff --git a/client/src/app/shared/shared-forms/input-readonly-copy.component.scss b/client/src/app/shared/shared-forms/input-readonly-copy.component.scss deleted file mode 100644 index 8dc4f113c..000000000 --- a/client/src/app/shared/shared-forms/input-readonly-copy.component.scss +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | input.readonly { | ||
2 | font-size: 15px; | ||
3 | } | ||
diff --git a/client/src/app/shared/shared-forms/input-readonly-copy.component.ts b/client/src/app/shared/shared-forms/input-readonly-copy.component.ts deleted file mode 100644 index b04d69d05..000000000 --- a/client/src/app/shared/shared-forms/input-readonly-copy.component.ts +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | import { Component, Input } from '@angular/core' | ||
2 | import { Notifier } from '@app/core' | ||
3 | |||
4 | @Component({ | ||
5 | selector: 'my-input-readonly-copy', | ||
6 | templateUrl: './input-readonly-copy.component.html', | ||
7 | styleUrls: [ './input-readonly-copy.component.scss' ] | ||
8 | }) | ||
9 | export class InputReadonlyCopyComponent { | ||
10 | @Input() id: string | ||
11 | @Input() value = '' | ||
12 | |||
13 | constructor (private notifier: Notifier) { } | ||
14 | |||
15 | activateCopiedMessage () { | ||
16 | this.notifier.success($localize`Copied`) | ||
17 | } | ||
18 | } | ||
diff --git a/client/src/app/shared/shared-forms/input-toggle-hidden.component.html b/client/src/app/shared/shared-forms/input-toggle-hidden.component.html new file mode 100644 index 000000000..f59dc6215 --- /dev/null +++ b/client/src/app/shared/shared-forms/input-toggle-hidden.component.html | |||
@@ -0,0 +1,13 @@ | |||
1 | <div class="input-group input-group-sm"> | ||
2 | <input [id]="id" [autocomplete]="autocomplete" [value]="value" [placeholder]="placeholder" [(ngModel)]="value" (ngModelChange)="update()" [ngClass]="{ 'readonly': readonly }" [readonly]="readonly" | ||
3 | #input (click)="input.select()" (input)="update()" (change)="update()" [type]="inputType" class="form-control" /> | ||
4 | |||
5 | <div *ngIf="withToggle || withCopy" class="input-group-append"> | ||
6 | <button *ngIf="withToggle" (click)="toggle()" type="button" class="btn btn-outline-secondary" [title]="toggleTitle"> | ||
7 | <span class="glyphicon glyphicon-eye-{{ show ? 'open' : 'close' }}"></span> | ||
8 | </button> | ||
9 | <button *ngIf="withCopy" [cdkCopyToClipboard]="input.value" (click)="activateCopiedMessage()" type="button" class="btn btn-outline-secondary" i18n-title title="Copy"> | ||
10 | <span class="glyphicon glyphicon-copy"></span> | ||
11 | </button> | ||
12 | </div> | ||
13 | </div> | ||
diff --git a/client/src/app/shared/shared-forms/input-toggle-hidden.component.scss b/client/src/app/shared/shared-forms/input-toggle-hidden.component.scss new file mode 100644 index 000000000..e20f69b86 --- /dev/null +++ b/client/src/app/shared/shared-forms/input-toggle-hidden.component.scss | |||
@@ -0,0 +1,11 @@ | |||
1 | @import '_variables'; | ||
2 | @import '_mixins'; | ||
3 | |||
4 | input { | ||
5 | @include peertube-input-text(auto); | ||
6 | |||
7 | // set again properties of peertube-input-text that are overriden by .input-group | ||
8 | font-size: 15px !important; | ||
9 | padding-left: 15px !important; | ||
10 | padding-right: 15px !important; | ||
11 | } | ||
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 @@ | |||
1 | import { Component, forwardRef, Input } from '@angular/core' | ||
2 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' | ||
3 | import { 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 | }) | ||
17 | export 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 | } | ||
diff --git a/client/src/app/shared/shared-forms/shared-form.module.ts b/client/src/app/shared/shared-forms/shared-form.module.ts index 060abc995..22e8dd05a 100644 --- a/client/src/app/shared/shared-forms/shared-form.module.ts +++ b/client/src/app/shared/shared-forms/shared-form.module.ts | |||
@@ -7,7 +7,7 @@ import { SharedGlobalIconModule } from '../shared-icons' | |||
7 | import { SharedMainModule } from '../shared-main/shared-main.module' | 7 | import { SharedMainModule } from '../shared-main/shared-main.module' |
8 | import { DynamicFormFieldComponent } from './dynamic-form-field.component' | 8 | import { DynamicFormFieldComponent } from './dynamic-form-field.component' |
9 | import { FormValidatorService } from './form-validator.service' | 9 | import { FormValidatorService } from './form-validator.service' |
10 | import { InputReadonlyCopyComponent } from './input-readonly-copy.component' | 10 | import { InputToggleHiddenComponent } from './input-toggle-hidden.component' |
11 | import { InputSwitchComponent } from './input-switch.component' | 11 | import { InputSwitchComponent } from './input-switch.component' |
12 | import { MarkdownTextareaComponent } from './markdown-textarea.component' | 12 | import { MarkdownTextareaComponent } from './markdown-textarea.component' |
13 | import { PeertubeCheckboxComponent } from './peertube-checkbox.component' | 13 | import { PeertubeCheckboxComponent } from './peertube-checkbox.component' |
@@ -30,7 +30,7 @@ import { TimestampInputComponent } from './timestamp-input.component' | |||
30 | ], | 30 | ], |
31 | 31 | ||
32 | declarations: [ | 32 | declarations: [ |
33 | InputReadonlyCopyComponent, | 33 | InputToggleHiddenComponent, |
34 | MarkdownTextareaComponent, | 34 | MarkdownTextareaComponent, |
35 | PeertubeCheckboxComponent, | 35 | PeertubeCheckboxComponent, |
36 | PreviewUploadComponent, | 36 | PreviewUploadComponent, |
@@ -55,7 +55,7 @@ import { TimestampInputComponent } from './timestamp-input.component' | |||
55 | InputMaskModule, | 55 | InputMaskModule, |
56 | NgSelectModule, | 56 | NgSelectModule, |
57 | 57 | ||
58 | InputReadonlyCopyComponent, | 58 | InputToggleHiddenComponent, |
59 | MarkdownTextareaComponent, | 59 | MarkdownTextareaComponent, |
60 | PeertubeCheckboxComponent, | 60 | PeertubeCheckboxComponent, |
61 | PreviewUploadComponent, | 61 | PreviewUploadComponent, |