Skip to content

Commit

Permalink
Refactor #12031 - content template support
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Nov 4, 2022
1 parent 6ce9c94 commit e426ef1
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions src/app/components/overlay/overlay.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
import { animate, animation, AnimationEvent, style, transition, trigger, useAnimation } from '@angular/animations';
import { CommonModule, DOCUMENT } from '@angular/common';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, forwardRef, Inject, Input, NgModule, OnDestroy, Output, Renderer2, ViewChild, ViewEncapsulation } from '@angular/core';
import {
AfterContentInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ContentChildren,
ElementRef,
EventEmitter,
forwardRef,
Inject,
Input,
NgModule,
OnDestroy,
Output,
QueryList,
Renderer2,
TemplateRef,
ViewChild,
ViewEncapsulation
} from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { OverlayModeType, OverlayOptions, OverlayService, PrimeNGConfig, SharedModule } from 'primeng/api';
import { OverlayModeType, OverlayOptions, OverlayService, PrimeNGConfig, PrimeTemplate, SharedModule } from 'primeng/api';
import { ConnectedOverlayScrollHandler, DomHandler } from 'primeng/dom';
import { ZIndexUtils } from 'primeng/utils';

Expand Down Expand Up @@ -44,6 +63,7 @@ const hideOverlayContentAnimation = animation([animate('{{hideTransitionParams}}
(@overlayContentAnimation.done)="onOverlayContentAnimationDone($event)"
>
<ng-content></ng-content>
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
</div>
</div>
`,
Expand All @@ -56,7 +76,7 @@ const hideOverlayContentAnimation = animation([animate('{{hideTransitionParams}}
class: 'p-element'
}
})
export class Overlay implements OnDestroy {
export class Overlay implements AfterContentInit, OnDestroy {
@Input() get visible(): boolean {
return this._visible;
}
Expand Down Expand Up @@ -170,10 +190,14 @@ export class Overlay implements OnDestroy {

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

@ContentChildren(PrimeTemplate) templates: QueryList<any>;

@ViewChild('overlay') overlayViewChild: ElementRef;

@ViewChild('content') contentViewChild: ElementRef;

contentTemplate: TemplateRef<any>;

_visible: boolean;

_mode: OverlayModeType | string;
Expand Down Expand Up @@ -253,6 +277,20 @@ export class Overlay implements OnDestroy {
this.window = this.document.defaultView;
}

ngAfterContentInit() {
this.templates.forEach((item) => {
switch (item.getType()) {
case 'content':
this.contentTemplate = item.template;
break;
// TODO: new template types may be added.
default:
this.contentTemplate = item.template;
break;
}
});
}

show(overlay?: HTMLElement, isFocus: boolean = false) {
this.onVisibleChange(true);
this.handleEvents('onShow', { overlay: overlay || this.overlayEl, target: this.targetEl, mode: this.overlayMode });
Expand Down

0 comments on commit e426ef1

Please sign in to comment.