Skip to content

Commit

Permalink
fix(module:notification): fix global config nzPlacement not working (#…
Browse files Browse the repository at this point in the history
…5140)

* fix(module:notification): fix global config nzPlacement not working

close #5135

* fix: fix tslint
  • Loading branch information
wendell authored Apr 26, 2020
1 parent ea9c7e9 commit 1ce1634
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 3 additions & 3 deletions components/notification/demo/placement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { NzNotificationPosition, NzNotificationService } from 'ng-zorro-antd/notification';
import { NzNotificationPlacement, NzNotificationService } from 'ng-zorro-antd/notification';

@Component({
selector: 'nz-demo-notification-placement',
Expand Down Expand Up @@ -27,11 +27,11 @@ import { NzNotificationPosition, NzNotificationService } from 'ng-zorro-antd/not
export class NzDemoNotificationPlacementComponent {
placement = 'topRight';

createBasicNotification(position: NzNotificationPosition): void {
createBasicNotification(position: NzNotificationPlacement): void {
this.notification.blank(
'Notification Title',
'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
{ nzPosition: position }
{ nzPlacement: position }
);
}

Expand Down
20 changes: 16 additions & 4 deletions components/notification/notification-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ViewEncapsulation } from '@angular/core';
import { NotificationConfig, NzConfigService } from 'ng-zorro-antd/core/config';
import { warnDeprecation } from 'ng-zorro-antd/core/logger';
import { toCssPixel } from 'ng-zorro-antd/core/util';

import { NzMNContainerComponent } from 'ng-zorro-antd/message';
Expand Down Expand Up @@ -138,11 +139,22 @@ export class NzNotificationContainerComponent extends NzMNContainerComponent {
}

protected readyInstances(): void {
this.topLeftInstances = this.instances.filter(m => m.options.nzPosition === 'topLeft');
this.topRightInstances = this.instances.filter(m => m.options.nzPosition === 'topRight' || !m.options.nzPosition);
this.bottomLeftInstances = this.instances.filter(m => m.options.nzPosition === 'bottomLeft');
this.bottomRightInstances = this.instances.filter(m => m.options.nzPosition === 'bottomRight');
this.topLeftInstances = this.instances.filter(m => m.options.nzPlacement === 'topLeft');
this.topRightInstances = this.instances.filter(m => m.options.nzPlacement === 'topRight' || !m.options.nzPlacement);
this.bottomLeftInstances = this.instances.filter(m => m.options.nzPlacement === 'bottomLeft');
this.bottomRightInstances = this.instances.filter(m => m.options.nzPlacement === 'bottomRight');

this.cdr.detectChanges();
}

protected mergeOptions(options?: NzNotificationDataOptions): NzNotificationDataOptions {
const { nzPosition } = options ?? {};

if (nzPosition) {
warnDeprecation('`nzPosition` of NzNotificationDataOptions is deprecated and would be removed in 10.0.0. Use `nzPlacement` instead.');
}

const { nzDuration, nzAnimate, nzPauseOnHover, nzPlacement } = this.config;
return { nzDuration, nzAnimate, nzPauseOnHover, nzPlacement: nzPlacement || nzPosition, ...options };
}
}
9 changes: 7 additions & 2 deletions components/notification/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ import { TemplateRef } from '@angular/core';
import { NgClassInterface, NgStyleInterface } from 'ng-zorro-antd/core/types';
import { Subject } from 'rxjs';

export type NzNotificationPosition = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
export type NzNotificationPlacement = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';

export interface NzNotificationDataOptions<T = {}> {
nzKey?: string;
nzStyle?: NgStyleInterface | string;
nzClass?: NgClassInterface | string;
nzCloseIcon?: TemplateRef<void> | string;
nzPosition?: NzNotificationPosition;
nzPlacement?: NzNotificationPlacement;
nzData?: T;
nzDuration?: number;
nzAnimate?: boolean;
nzPauseOnHover?: boolean;

/**
* @deprecated use nzPlacement instead, this would be removed in 10.0.0
*/
nzPosition?: NzNotificationPlacement;
}

export interface NzNotificationData {
Expand Down

0 comments on commit 1ce1634

Please sign in to comment.