@@ -12,7 +12,7 @@ import { NotificationConfig, NzConfigService } from 'ng-zorro-antd/core/config';
1212import { toCssPixel } from 'ng-zorro-antd/core/util' ;
1313import { NzMNContainerComponent } from 'ng-zorro-antd/message' ;
1414
15- import { NzNotificationData , NzNotificationDataOptions } from './typings' ;
15+ import { NzNotificationData , NzNotificationDataOptions , NzNotificationPlacement } from './typings' ;
1616
1717const NZ_CONFIG_MODULE_NAME = 'notification' ;
1818
@@ -43,7 +43,7 @@ const NZ_NOTIFICATION_DEFAULT_CONFIG: Required<NotificationConfig> = {
4343 <nz-notification
4444 *ngFor="let instance of topLeftInstances"
4545 [instance]="instance"
46- [placement]="config.nzPlacement "
46+ [placement]="'topLeft' "
4747 (destroyed)="remove($event.id, $event.userAction)"
4848 ></nz-notification>
4949 </div>
@@ -56,7 +56,7 @@ const NZ_NOTIFICATION_DEFAULT_CONFIG: Required<NotificationConfig> = {
5656 <nz-notification
5757 *ngFor="let instance of topRightInstances"
5858 [instance]="instance"
59- [placement]="config.nzPlacement "
59+ [placement]="'topRight' "
6060 (destroyed)="remove($event.id, $event.userAction)"
6161 ></nz-notification>
6262 </div>
@@ -69,7 +69,7 @@ const NZ_NOTIFICATION_DEFAULT_CONFIG: Required<NotificationConfig> = {
6969 <nz-notification
7070 *ngFor="let instance of bottomLeftInstances"
7171 [instance]="instance"
72- [placement]="config.nzPlacement "
72+ [placement]="'bottomLeft' "
7373 (destroyed)="remove($event.id, $event.userAction)"
7474 ></nz-notification>
7575 </div>
@@ -82,7 +82,35 @@ const NZ_NOTIFICATION_DEFAULT_CONFIG: Required<NotificationConfig> = {
8282 <nz-notification
8383 *ngFor="let instance of bottomRightInstances"
8484 [instance]="instance"
85- [placement]="config.nzPlacement"
85+ [placement]="'bottomRight'"
86+ (destroyed)="remove($event.id, $event.userAction)"
87+ ></nz-notification>
88+ </div>
89+ <div
90+ class="ant-notification ant-notification-top"
91+ [class.ant-notification-rtl]="dir === 'rtl'"
92+ [style.top]="top"
93+ [style.left]="'50%'"
94+ [style.transform]="'translateX(-50%)'"
95+ >
96+ <nz-notification
97+ *ngFor="let instance of topInstances"
98+ [instance]="instance"
99+ [placement]="'top'"
100+ (destroyed)="remove($event.id, $event.userAction)"
101+ ></nz-notification>
102+ </div>
103+ <div
104+ class="ant-notification ant-notification-bottom"
105+ [class.ant-notification-rtl]="dir === 'rtl'"
106+ [style.bottom]="bottom"
107+ [style.left]="'50%'"
108+ [style.transform]="'translateX(-50%)'"
109+ >
110+ <nz-notification
111+ *ngFor="let instance of bottomInstances"
112+ [instance]="instance"
113+ [placement]="'bottom'"
86114 (destroyed)="remove($event.id, $event.userAction)"
87115 ></nz-notification>
88116 </div>
@@ -98,6 +126,8 @@ export class NzNotificationContainerComponent extends NzMNContainerComponent {
98126 topRightInstances : Array < Required < NzNotificationData > > = [ ] ;
99127 bottomLeftInstances : Array < Required < NzNotificationData > > = [ ] ;
100128 bottomRightInstances : Array < Required < NzNotificationData > > = [ ] ;
129+ topInstances : Array < Required < NzNotificationData > > = [ ] ;
130+ bottomInstances : Array < Required < NzNotificationData > > = [ ] ;
101131
102132 constructor ( cdr : ChangeDetectorRef , nzConfigService : NzConfigService ) {
103133 super ( cdr , nzConfigService ) ;
@@ -168,10 +198,45 @@ export class NzNotificationContainerComponent extends NzMNContainerComponent {
168198 }
169199
170200 protected override readyInstances ( ) : void {
171- this . topLeftInstances = this . instances . filter ( m => m . options . nzPlacement === 'topLeft' ) ;
172- this . topRightInstances = this . instances . filter ( m => m . options . nzPlacement === 'topRight' || ! m . options . nzPlacement ) ;
173- this . bottomLeftInstances = this . instances . filter ( m => m . options . nzPlacement === 'bottomLeft' ) ;
174- this . bottomRightInstances = this . instances . filter ( m => m . options . nzPlacement === 'bottomRight' ) ;
201+ const instancesMap : Record < NzNotificationPlacement , Array < Required < NzNotificationData > > > = {
202+ topLeft : [ ] ,
203+ topRight : [ ] ,
204+ bottomLeft : [ ] ,
205+ bottomRight : [ ] ,
206+ top : [ ] ,
207+ bottom : [ ]
208+ } ;
209+ this . instances . forEach ( m => {
210+ const placement = m . options . nzPlacement ;
211+ switch ( placement ) {
212+ case 'topLeft' :
213+ instancesMap . topLeft . push ( m ) ;
214+ break ;
215+ case 'topRight' :
216+ instancesMap . topRight . push ( m ) ;
217+ break ;
218+ case 'bottomLeft' :
219+ instancesMap . bottomLeft . push ( m ) ;
220+ break ;
221+ case 'bottomRight' :
222+ instancesMap . bottomRight . push ( m ) ;
223+ break ;
224+ case 'top' :
225+ instancesMap . top . push ( m ) ;
226+ break ;
227+ case 'bottom' :
228+ instancesMap . bottom . push ( m ) ;
229+ break ;
230+ default :
231+ instancesMap . topRight . push ( m ) ;
232+ }
233+ } ) ;
234+ this . topLeftInstances = instancesMap . topLeft ;
235+ this . topRightInstances = instancesMap . topRight ;
236+ this . bottomLeftInstances = instancesMap . bottomLeft ;
237+ this . bottomRightInstances = instancesMap . bottomRight ;
238+ this . topInstances = instancesMap . top ;
239+ this . bottomInstances = instancesMap . bottom ;
175240
176241 this . cdr . detectChanges ( ) ;
177242 }
0 commit comments