Skip to content

Commit

Permalink
Refactor primefaces#13079
Browse files Browse the repository at this point in the history
  • Loading branch information
gucal committed May 23, 2023
1 parent 9a180b4 commit 3189207
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
12 changes: 11 additions & 1 deletion src/app/components/toast/toast.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TemplateRef } from '@angular/core';
import { Toast } from './toast';
import { Message } from '../api/message';
import { Toast } from './toast';
/**
* Breakpoints of toast element.
*/
Expand Down Expand Up @@ -36,3 +36,13 @@ export interface ToastCloseEvent {
*/
message: Message;
}
/**
* Custom close event.
* @see {@link ToastItem.onClose}
*/
export interface ToastItemCloseEvent extends ToastCloseEvent {
/**
* Index of the closed element.
*/
index: number;
}
18 changes: 9 additions & 9 deletions src/app/components/toast/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { TimesCircleIcon } from 'primeng/icons/timescircle';
import { RippleModule } from 'primeng/ripple';
import { ObjectUtils, UniqueComponentId, ZIndexUtils } from 'primeng/utils';
import { Subscription } from 'rxjs';
import { ToastBreakpoints, ToastCloseEvent } from './toast.interface';
import { ToastBreakpoints, ToastCloseEvent, ToastItemCloseEvent } from './toast.interface';

@Component({
selector: 'p-toastItem',
Expand Down Expand Up @@ -98,9 +98,9 @@ import { ToastBreakpoints, ToastCloseEvent } from './toast.interface';
}
})
export class ToastItem implements AfterViewInit, OnDestroy {
@Input({required: true}) message!: Message;
@Input() message: Message | null | undefined;

@Input({required: true}) index!: number;
@Input() index: number | null | undefined;

@Input() template: TemplateRef<any> | undefined;

Expand All @@ -112,7 +112,7 @@ export class ToastItem implements AfterViewInit, OnDestroy {

@Input() hideTransitionOptions: string | undefined;

@Output() onClose: EventEmitter<{message: Message, index: number}> = new EventEmitter();
@Output() onClose: EventEmitter<ToastItemCloseEvent> = new EventEmitter();

@ViewChild('container') containerViewChild: ElementRef | undefined;

Expand All @@ -129,8 +129,8 @@ export class ToastItem implements AfterViewInit, OnDestroy {
this.zone.runOutsideAngular(() => {
this.timeout = setTimeout(() => {
this.onClose.emit({
index: this.index,
message: this.message
index: <number>this.index,
message: <Message>this.message
});
}, this.message?.life || 3000);
});
Expand All @@ -156,8 +156,8 @@ export class ToastItem implements AfterViewInit, OnDestroy {
this.clearTimeout();

this.onClose.emit({
index: this.index,
message: this.message
index: <number>this.index,
message: <Message>this.message
});

event.preventDefault();
Expand Down Expand Up @@ -370,7 +370,7 @@ export class Toast implements OnInit, AfterContentInit, OnDestroy {
});
}

onMessageClose(event: {message: Message, index: number}) {
onMessageClose(event: ToastItemCloseEvent) {
this.messages?.splice(event.index, 1);

this.onClose.emit({
Expand Down

0 comments on commit 3189207

Please sign in to comment.