import { NgModule, Component, Input, ElementRef, ContentChild, ChangeDetectionStrategy, ViewEncapsulation, TemplateRef, AfterContentInit, ContentChildren, QueryList } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule, Header, Footer, PrimeTemplate } from 'mirra-ui/api';
import { BlockableUI } from 'mirra-ui/api';
@Component({
selector: 'p-card',
template: `
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
styleUrls: ['./card.scss']
})
export class Card implements AfterContentInit,BlockableUI {
@Input() header: string;
@Input() subheader: string;
@Input() style: any;
@Input() styleClass: string;
@ContentChild(Header) headerFacet;
@ContentChild(Footer) footerFacet;
@ContentChildren(PrimeTemplate) templates: QueryList;
headerTemplate: TemplateRef;
titleTemplate: TemplateRef;
subtitleTemplate: TemplateRef;
contentTemplate: TemplateRef;
footerTemplate: TemplateRef;
constructor(private el: ElementRef) { }
ngAfterContentInit() {
this.templates.forEach((item) => {
switch(item.getType()) {
case 'header':
this.headerTemplate = item.template;
break;
case 'title':
this.titleTemplate = item.template;
break;
case 'subtitle':
this.subtitleTemplate = item.template;
break;
case 'content':
this.contentTemplate = item.template;
break;
case 'footer':
this.footerTemplate = item.template;
break;
default:
this.contentTemplate = item.template;
break;
}
});
}
getBlockableElement(): HTMLElement {
return this.el.nativeElement.children[0];
}
}
@NgModule({
imports: [CommonModule],
exports: [Card, SharedModule],
declarations: [Card]
})
export class CardModule { }