/
message-container.component.ts
64 lines (54 loc) · 1.97 KB
/
message-container.component.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
/**
* 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, ViewEncapsulation } from '@angular/core';
import { MessageConfig, NzConfigService } from 'ng-zorro-antd/core/config';
import { toCssPixel } from 'ng-zorro-antd/core/util';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { NzMNContainerComponent } from './base';
import { NzMessageData } from './typings';
const NZ_CONFIG_COMPONENT_NAME = 'message';
const NZ_MESSAGE_DEFAULT_CONFIG: Required<MessageConfig> = {
nzAnimate: true,
nzDuration: 3000,
nzMaxStack: 7,
nzPauseOnHover: true,
nzTop: 24
};
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
selector: 'nz-message-container',
exportAs: 'nzMessageContainer',
preserveWhitespaces: false,
template: `
<div class="ant-message" [style.top]="top">
<nz-message *ngFor="let instance of instances" [instance]="instance" (destroyed)="remove($event.id, $event.userAction)"></nz-message>
</div>
`
})
export class NzMessageContainerComponent extends NzMNContainerComponent {
readonly destroy$ = new Subject<void>();
instances: Array<Required<NzMessageData>> = [];
top?: string | null;
constructor(cdr: ChangeDetectorRef, nzConfigService: NzConfigService) {
super(cdr, nzConfigService);
}
protected subscribeConfigChange(): void {
this.nzConfigService
.getConfigChangeEventForComponent(NZ_CONFIG_COMPONENT_NAME)
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.updateConfig());
}
protected updateConfig(): void {
this.config = {
...NZ_MESSAGE_DEFAULT_CONFIG,
...this.config,
...this.nzConfigService.getConfigForComponent(NZ_CONFIG_COMPONENT_NAME)
};
this.top = toCssPixel(this.config.nzTop);
this.cdr.markForCheck();
}
}