forked from NG-ZORRO/ng-zorro-antd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkbox.ts
66 lines (60 loc) · 1.92 KB
/
checkbox.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Input,
NgZone,
OnInit,
Output
} from '@angular/core';
import { fromEvent } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { NzDestroyService } from 'ng-zorro-antd/core/services';
import { BooleanInput } from 'ng-zorro-antd/core/types';
import { InputBoolean } from 'ng-zorro-antd/core/util';
@Component({
selector: 'nz-tree-node-checkbox:not([builtin])',
template: ` <span class="ant-tree-checkbox-inner"></span> `,
changeDetection: ChangeDetectionStrategy.OnPush,
preserveWhitespaces: false,
host: {
class: 'ant-tree-checkbox',
'[class.ant-tree-checkbox-checked]': `nzChecked`,
'[class.ant-tree-checkbox-indeterminate]': `nzIndeterminate`,
'[class.ant-tree-checkbox-disabled]': `nzDisabled`
},
providers: [NzDestroyService]
})
export class NzTreeNodeCheckboxComponent implements OnInit {
static ngAcceptInputType_nzDisabled: BooleanInput;
@Input() nzChecked?: boolean;
@Input() nzIndeterminate?: boolean;
@Input() @InputBoolean() nzDisabled?: boolean;
@Output() readonly nzClick = new EventEmitter<MouseEvent>();
constructor(
private ngZone: NgZone,
private ref: ChangeDetectorRef,
private host: ElementRef<HTMLElement>,
private destroy$: NzDestroyService
) {}
ngOnInit(): void {
this.ngZone.runOutsideAngular(() =>
fromEvent<MouseEvent>(this.host.nativeElement, 'click')
.pipe(takeUntil(this.destroy$))
.subscribe((event: MouseEvent) => {
if (!this.nzDisabled && this.nzClick.observers.length) {
this.ngZone.run(() => {
this.nzClick.emit(event);
this.ref.markForCheck();
});
}
})
);
}
}