1 import { ChangeDetectorRef, Component, forwardRef, Input, OnChanges, SimpleChanges } from '@angular/core'
2 import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
5 selector: 'my-peertube-checkbox',
6 styleUrls: [ './peertube-checkbox.component.scss' ],
7 templateUrl: './peertube-checkbox.component.html',
10 provide: NG_VALUE_ACCESSOR,
11 useExisting: forwardRef(() => PeertubeCheckboxComponent),
16 export class PeertubeCheckboxComponent implements ControlValueAccessor {
17 @Input() checked = false
18 @Input() inputName: string
19 @Input() labelText: string
20 @Input() labelHtml: string
21 @Input() helpHtml: string
22 @Input() helpPlacement = 'top'
23 @Input() disabled = false
25 // FIXME: https://github.com/angular/angular/issues/10816#issuecomment-307567836
26 @Input() onPushWorkaround = false
28 constructor (private cdr: ChangeDetectorRef) { }
30 propagateChange = (_: any) => { /* empty */ }
32 writeValue (checked: boolean) {
33 this.checked = checked
35 if (this.onPushWorkaround) {
36 this.cdr.markForCheck()
40 registerOnChange (fn: (_: any) => void) {
41 this.propagateChange = fn
44 registerOnTouched () {
49 this.propagateChange(this.checked)
52 setDisabledState (isDisabled: boolean) {
53 this.disabled = isDisabled