import {NgModule,Component,Input,Output,EventEmitter,ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, AfterContentInit, TemplateRef, QueryList, ContentChildren} from '@angular/core';
import {CommonModule} from '@angular/common';
import {ButtonModule} from 'mirra-ui/button';
import { PrimeTemplate } from "mirra-ui/api";
@Component({
selector: 'p-inplaceDisplay',
template: ''
})
export class InplaceDisplay {}
@Component({
selector: 'p-inplaceContent',
template: ''
})
export class InplaceContent {}
@Component({
selector: 'p-inplace',
template: `
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
styleUrls: ['./inplace.scss']
})
export class Inplace implements AfterContentInit {
@Input() active: boolean;
@Input() closable: boolean;
@Input() disabled: boolean;
@Input() preventClick: boolean;
@Input() style: any;
@Input() styleClass: string;
@Input() closeIcon: string = 'far fa-times';
@ContentChildren(PrimeTemplate) templates: QueryList;
@Output() onActivate: EventEmitter = new EventEmitter();
@Output() onDeactivate: EventEmitter = new EventEmitter();
hover: boolean;
displayTemplate: TemplateRef;
contentTemplate: TemplateRef;
constructor(public cd: ChangeDetectorRef) {}
ngAfterContentInit() {
this.templates.forEach((item) => {
switch(item.getType()) {
case 'display':
this.displayTemplate = item.template;
break;
case 'content':
this.contentTemplate = item.template;
break;
}
});
}
onActivateClick(event) {
if (!this.preventClick)
this.activate(event);
}
onDeactivateClick(event) {
if (!this.preventClick)
this.deactivate(event);
}
activate(event?: Event) {
if (!this.disabled) {
this.active = true;
this.onActivate.emit(event);
this.cd.markForCheck();
}
}
deactivate(event?: Event) {
if (!this.disabled) {
this.active = false;
this.hover = false;
this.onDeactivate.emit(event);
this.cd.markForCheck();
}
}
onKeydown(event: KeyboardEvent) {
if (event.which === 13) {
this.activate(event);
event.preventDefault();
}
}
}
@NgModule({
imports: [CommonModule,ButtonModule],
exports: [Inplace,InplaceDisplay,InplaceContent,ButtonModule],
declarations: [Inplace,InplaceDisplay,InplaceContent]
})
export class InplaceModule { }