-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
modal-confirm-container.component.ts
147 lines (138 loc) · 5.19 KB
/
modal-confirm-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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* 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 { FocusTrapFactory } from '@angular/cdk/a11y';
import { OverlayRef } from '@angular/cdk/overlay';
import { CdkPortalOutlet } from '@angular/cdk/portal';
import { DOCUMENT } from '@angular/common';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Inject,
NgZone,
OnInit,
Optional,
Output,
Renderer2,
ViewChild
} from '@angular/core';
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
import { takeUntil } from 'rxjs/operators';
import { NzConfigService } from 'ng-zorro-antd/core/config';
import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzI18nService, NzModalI18nInterface } from 'ng-zorro-antd/i18n';
import { nzModalAnimations } from './modal-animations';
import { BaseModalContainerComponent } from './modal-container';
import { ModalOptions } from './modal-types';
@Component({
selector: 'nz-modal-confirm-container',
exportAs: 'nzModalConfirmContainer',
template: `
<div
#modalElement
role="document"
class="ant-modal"
[ngClass]="config.nzClassName!"
[ngStyle]="config.nzStyle!"
[style.width]="config?.nzWidth! | nzToCssUnit"
>
<div class="ant-modal-content">
<button *ngIf="config.nzClosable" nz-modal-close (click)="onCloseClick()"></button>
<div class="ant-modal-body" [ngStyle]="config.nzBodyStyle!">
<div class="ant-modal-confirm-body-wrapper">
<div class="ant-modal-confirm-body">
<i nz-icon [nzType]="config.nzIconType!"></i>
<span class="ant-modal-confirm-title">
<ng-container *nzStringTemplateOutlet="config.nzTitle">
<span [innerHTML]="config.nzTitle"></span>
</ng-container>
</span>
<div class="ant-modal-confirm-content">
<ng-template cdkPortalOutlet></ng-template>
<div *ngIf="isStringContent" [innerHTML]="config.nzContent"></div>
</div>
</div>
<div class="ant-modal-confirm-btns">
<button
*ngIf="config.nzCancelText !== null"
[attr.cdkFocusInitial]="config.nzAutofocus === 'cancel' || null"
nz-button
(click)="onCancel()"
[nzLoading]="!!config.nzCancelLoading"
[disabled]="config.nzCancelDisabled"
>
{{ config.nzCancelText || locale.cancelText }}
</button>
<button
*ngIf="config.nzOkText !== null"
[attr.cdkFocusInitial]="config.nzAutofocus === 'ok' || null"
nz-button
[nzType]="config.nzOkType!"
(click)="onOk()"
[nzLoading]="!!config.nzOkLoading"
[disabled]="config.nzOkDisabled"
[nzDanger]="config.nzOkDanger"
>
{{ config.nzOkText || locale.okText }}
</button>
</div>
</div>
</div>
</div>
</div>
`,
animations: [nzModalAnimations.modalContainer],
// Using OnPush for modal caused footer can not to detect changes. we can fix it when 8.x.
changeDetection: ChangeDetectionStrategy.Default,
host: {
tabindex: '-1',
role: 'dialog',
'[class]': 'config.nzWrapClassName ? "ant-modal-wrap " + config.nzWrapClassName : "ant-modal-wrap"',
'[class.ant-modal-wrap-rtl]': `dir === 'rtl'`,
'[class.ant-modal-centered]': 'config.nzCentered',
'[style.zIndex]': 'config.nzZIndex',
'[@.disabled]': 'config.nzNoAnimation',
'[@modalContainer]': 'state',
'(@modalContainer.start)': 'onAnimationStart($event)',
'(@modalContainer.done)': 'onAnimationDone($event)',
'(click)': 'onContainerClick($event)'
}
})
export class NzModalConfirmContainerComponent extends BaseModalContainerComponent implements OnInit {
@ViewChild(CdkPortalOutlet, { static: true }) portalOutlet!: CdkPortalOutlet;
@ViewChild('modalElement', { static: true }) modalElementRef!: ElementRef<HTMLDivElement>;
@Output() readonly cancelTriggered = new EventEmitter<void>();
@Output() readonly okTriggered = new EventEmitter<void>();
locale!: NzModalI18nInterface;
constructor(
ngZone: NgZone,
private i18n: NzI18nService,
host: ElementRef<HTMLElement>,
focusTrapFactory: FocusTrapFactory,
cdr: ChangeDetectorRef,
render: Renderer2,
overlayRef: OverlayRef,
nzConfigService: NzConfigService,
public config: ModalOptions,
@Optional() @Inject(DOCUMENT) document: NzSafeAny,
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationType: string
) {
super(ngZone, host, focusTrapFactory, cdr, render, overlayRef, nzConfigService, config, document, animationType);
this.i18n.localeChange.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.locale = this.i18n.getLocaleData('Modal');
});
}
ngOnInit(): void {
this.setupMouseListeners(this.modalElementRef);
}
onCancel(): void {
this.cancelTriggered.emit();
}
onOk(): void {
this.okTriggered.emit();
}
}