diff options
Diffstat (limited to 'client/src/app/shared/forms/peertube-checkbox.component.ts')
-rw-r--r-- | client/src/app/shared/forms/peertube-checkbox.component.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/client/src/app/shared/forms/peertube-checkbox.component.ts b/client/src/app/shared/forms/peertube-checkbox.component.ts new file mode 100644 index 000000000..c626c4c5d --- /dev/null +++ b/client/src/app/shared/forms/peertube-checkbox.component.ts | |||
@@ -0,0 +1,45 @@ | |||
1 | import { Component, forwardRef, Input } from '@angular/core' | ||
2 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' | ||
3 | |||
4 | @Component({ | ||
5 | selector: 'my-peertube-checkbox', | ||
6 | styleUrls: [ './peertube-checkbox.component.scss' ], | ||
7 | templateUrl: './peertube-checkbox.component.html', | ||
8 | providers: [ | ||
9 | { | ||
10 | provide: NG_VALUE_ACCESSOR, | ||
11 | useExisting: forwardRef(() => PeertubeCheckboxComponent), | ||
12 | multi: true | ||
13 | } | ||
14 | ] | ||
15 | }) | ||
16 | export class PeertubeCheckboxComponent implements ControlValueAccessor { | ||
17 | @Input() checked = false | ||
18 | @Input() inputName: string | ||
19 | @Input() labelText: string | ||
20 | @Input() helpHtml: string | ||
21 | |||
22 | isDisabled = false | ||
23 | |||
24 | propagateChange = (_: any) => { /* empty */ } | ||
25 | |||
26 | writeValue (checked: boolean) { | ||
27 | this.checked = checked | ||
28 | } | ||
29 | |||
30 | registerOnChange (fn: (_: any) => void) { | ||
31 | this.propagateChange = fn | ||
32 | } | ||
33 | |||
34 | registerOnTouched () { | ||
35 | // Unused | ||
36 | } | ||
37 | |||
38 | onModelChange () { | ||
39 | this.propagateChange(this.checked) | ||
40 | } | ||
41 | |||
42 | setDisabledState (isDisabled: boolean) { | ||
43 | this.isDisabled = isDisabled | ||
44 | } | ||
45 | } | ||