Skip to content

Commit

Permalink
Refactor #12031 - Added onBeforeShow and onBeforeHide callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Nov 4, 2022
1 parent 856ce90 commit e397612
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/app/components/api/overlayoptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export interface OverlayOnShowEvent {
mode?: OverlayModeType;
}

export interface OverlayOnBeforeShowEvent extends OverlayOnShowEvent {}

export interface OverlayOnBeforeHideEvent extends OverlayOnBeforeShowEvent {}

export interface OverlayOnHideEvent extends OverlayOnShowEvent {}

export interface OverlayOptions {
Expand All @@ -39,7 +43,9 @@ export interface OverlayOptions {
hideTransitionOptions?: string;
listener?: (event: Event, options?: OverlayListenerOptions) => boolean | void;
responsive?: ResponsiveOverlayOptions | undefined;
onBeforeShow?: (event?: OverlayOnBeforeShowEvent) => void;
onShow?: (event?: OverlayOnShowEvent) => void;
onBeforeHide?: (event?: OverlayOnBeforeHideEvent) => void;
onHide?: (event?: OverlayOnHideEvent) => void;
onAnimationStart?: (event?: AnimationEvent) => void;
onAnimationDone?: (event?: AnimationEvent) => void;
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ export class Overlay implements OnDestroy {
this._options = val;
}

@Output() onBeforeShow: EventEmitter<any> = new EventEmitter();

@Output() onShow: EventEmitter<any> = new EventEmitter();

@Output() onBeforeHide: EventEmitter<any> = new EventEmitter();

@Output() onHide: EventEmitter<any> = new EventEmitter();

@Output() onAnimationStart: EventEmitter<any> = new EventEmitter();
Expand Down Expand Up @@ -277,6 +281,8 @@ export class Overlay implements OnDestroy {
onOverlayContentAnimationStart(event: AnimationEvent) {
switch (event.toState) {
case 'visible':
this.handleEvents('onBeforeShow', { overlay: this.overlayEl, target: this.targetEl, mode: this.overlayMode });

if (this.autoZIndex) {
ZIndexUtils.set(this.overlayMode, this.overlayEl, this.baseZIndex + this.config?.zIndex[this.overlayMode]);
}
Expand All @@ -288,6 +294,8 @@ export class Overlay implements OnDestroy {
break;

case 'void':
this.handleEvents('onBeforeHide', { overlay: this.overlayEl, target: this.targetEl, mode: this.overlayMode });

DomHandler.appendOverlay(this.overlayEl, this.targetEl, this.appendTo);
this.modal && DomHandler.addClass(this.overlayEl, 'p-component-overlay-leave');
this.unbindListeners();
Expand Down

0 comments on commit e397612

Please sign in to comment.