UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![npm downloads](https://img.shields.io/npm/dm/primeng.sv

251 lines (247 loc) 13.5 kB
import * as i0 from '@angular/core'; import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Optional, Input, ContentChildren, Output, NgModule } from '@angular/core'; import * as i2 from '@angular/common'; import { CommonModule } from '@angular/common'; import { trigger, transition, style, animate } from '@angular/animations'; import * as i1 from 'primeng/api'; import { PrimeTemplate } from 'primeng/api'; import * as i3 from 'primeng/ripple'; import { RippleModule } from 'primeng/ripple'; class Messages { constructor(messageService, el, cd) { this.messageService = messageService; this.el = el; this.cd = cd; this.closable = true; this.enableService = true; this.escape = true; this.showTransitionOptions = '300ms ease-out'; this.hideTransitionOptions = '200ms cubic-bezier(0.86, 0, 0.07, 1)'; this.valueChange = new EventEmitter(); } ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'content': this.contentTemplate = item.template; break; default: this.contentTemplate = item.template; break; } }); if (this.messageService && this.enableService && !this.contentTemplate) { this.messageSubscription = this.messageService.messageObserver.subscribe((messages) => { if (messages) { if (messages instanceof Array) { let filteredMessages = messages.filter(m => this.key === m.key); this.value = this.value ? [...this.value, ...filteredMessages] : [...filteredMessages]; } else if (this.key === messages.key) { this.value = this.value ? [...this.value, ...[messages]] : [messages]; } this.cd.markForCheck(); } }); this.clearSubscription = this.messageService.clearObserver.subscribe(key => { if (key) { if (this.key === key) { this.value = null; } } else { this.value = null; } this.cd.markForCheck(); }); } } hasMessages() { let parentEl = this.el.nativeElement.parentElement; if (parentEl && parentEl.offsetParent) { return this.contentTemplate != null || this.value && this.value.length > 0; } return false; } clear() { this.value = []; this.valueChange.emit(this.value); } removeMessage(i) { this.value = this.value.filter((msg, index) => index !== i); this.valueChange.emit(this.value); } get icon() { const severity = this.severity || (this.hasMessages() ? this.value[0].severity : null); if (this.hasMessages()) { switch (severity) { case 'success': return 'pi-check'; break; case 'info': return 'pi-info-circle'; break; case 'error': return 'pi-times'; break; case 'warn': return 'pi-exclamation-triangle'; break; default: return 'pi-info-circle'; break; } } return null; } ngOnDestroy() { if (this.messageSubscription) { this.messageSubscription.unsubscribe(); } if (this.clearSubscription) { this.clearSubscription.unsubscribe(); } } } Messages.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: Messages, deps: [{ token: i1.MessageService, optional: true }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); Messages.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.4", type: Messages, selector: "p-messages", inputs: { value: "value", closable: "closable", style: "style", styleClass: "styleClass", enableService: "enableService", key: "key", escape: "escape", severity: "severity", showTransitionOptions: "showTransitionOptions", hideTransitionOptions: "hideTransitionOptions" }, outputs: { valueChange: "valueChange" }, queries: [{ propertyName: "templates", predicate: PrimeTemplate }], ngImport: i0, template: ` <div class="p-messages p-component" role="alert" [ngStyle]="style" [class]="styleClass"> <ng-container *ngIf="!contentTemplate; else staticMessage"> <div *ngFor="let msg of value; let i=index" [ngClass]="'p-message p-message-' + msg.severity" role="alert" [@messageAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}"> <div class="p-message-wrapper"> <span [class]="'p-message-icon pi' + (msg.icon ? ' ' + msg.icon : '')" [ngClass]="{'pi-info-circle': msg.severity === 'info', 'pi-check': msg.severity === 'success', 'pi-exclamation-triangle': msg.severity === 'warn', 'pi-times-circle': msg.severity === 'error'}"></span> <ng-container *ngIf="!escape; else escapeOut"> <span *ngIf="msg.summary" class="p-message-summary" [innerHTML]="msg.summary"></span> <span *ngIf="msg.detail" class="p-message-detail" [innerHTML]="msg.detail"></span> </ng-container> <ng-template #escapeOut> <span *ngIf="msg.summary" class="p-message-summary">{{msg.summary}}</span> <span *ngIf="msg.detail" class="p-message-detail">{{msg.detail}}</span> </ng-template> <button class="p-message-close p-link" (click)="removeMessage(i)" *ngIf="closable" type="button" pRipple> <i class="p-message-close-icon pi pi-times"></i> </button> </div> </div> </ng-container> <ng-template #staticMessage> <div [ngClass]="'p-message p-message-' + severity" role="alert"> <div class="p-message-wrapper"> <ng-container *ngTemplateOutlet="contentTemplate"></ng-container> </div> </div> </ng-template> </div> `, isInline: true, styles: [".p-message-close,.p-message-wrapper{display:flex;align-items:center}.p-message-close{justify-content:center}.p-message-close.p-link{margin-left:auto;overflow:hidden;position:relative}"], directives: [{ type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i3.Ripple, selector: "[pRipple]" }, { type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }], animations: [ trigger('messageAnimation', [ transition(':enter', [ style({ opacity: 0, transform: 'translateY(-25%)' }), animate('{{showTransitionParams}}') ]), transition(':leave', [ animate('{{hideTransitionParams}}', style({ height: 0, marginTop: 0, marginBottom: 0, marginLeft: 0, marginRight: 0, overflow: 'hidden', opacity: 0 })) ]) ]) ], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: Messages, decorators: [{ type: Component, args: [{ selector: 'p-messages', template: ` <div class="p-messages p-component" role="alert" [ngStyle]="style" [class]="styleClass"> <ng-container *ngIf="!contentTemplate; else staticMessage"> <div *ngFor="let msg of value; let i=index" [ngClass]="'p-message p-message-' + msg.severity" role="alert" [@messageAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}"> <div class="p-message-wrapper"> <span [class]="'p-message-icon pi' + (msg.icon ? ' ' + msg.icon : '')" [ngClass]="{'pi-info-circle': msg.severity === 'info', 'pi-check': msg.severity === 'success', 'pi-exclamation-triangle': msg.severity === 'warn', 'pi-times-circle': msg.severity === 'error'}"></span> <ng-container *ngIf="!escape; else escapeOut"> <span *ngIf="msg.summary" class="p-message-summary" [innerHTML]="msg.summary"></span> <span *ngIf="msg.detail" class="p-message-detail" [innerHTML]="msg.detail"></span> </ng-container> <ng-template #escapeOut> <span *ngIf="msg.summary" class="p-message-summary">{{msg.summary}}</span> <span *ngIf="msg.detail" class="p-message-detail">{{msg.detail}}</span> </ng-template> <button class="p-message-close p-link" (click)="removeMessage(i)" *ngIf="closable" type="button" pRipple> <i class="p-message-close-icon pi pi-times"></i> </button> </div> </div> </ng-container> <ng-template #staticMessage> <div [ngClass]="'p-message p-message-' + severity" role="alert"> <div class="p-message-wrapper"> <ng-container *ngTemplateOutlet="contentTemplate"></ng-container> </div> </div> </ng-template> </div> `, animations: [ trigger('messageAnimation', [ transition(':enter', [ style({ opacity: 0, transform: 'translateY(-25%)' }), animate('{{showTransitionParams}}') ]), transition(':leave', [ animate('{{hideTransitionParams}}', style({ height: 0, marginTop: 0, marginBottom: 0, marginLeft: 0, marginRight: 0, overflow: 'hidden', opacity: 0 })) ]) ]) ], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, styleUrls: ['./messages.css'] }] }], ctorParameters: function () { return [{ type: i1.MessageService, decorators: [{ type: Optional }] }, { type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { value: [{ type: Input }], closable: [{ type: Input }], style: [{ type: Input }], styleClass: [{ type: Input }], enableService: [{ type: Input }], key: [{ type: Input }], escape: [{ type: Input }], severity: [{ type: Input }], showTransitionOptions: [{ type: Input }], hideTransitionOptions: [{ type: Input }], templates: [{ type: ContentChildren, args: [PrimeTemplate] }], valueChange: [{ type: Output }] } }); class MessagesModule { } MessagesModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: MessagesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); MessagesModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: MessagesModule, declarations: [Messages], imports: [CommonModule, RippleModule], exports: [Messages] }); MessagesModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: MessagesModule, imports: [[CommonModule, RippleModule]] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.4", ngImport: i0, type: MessagesModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, RippleModule], exports: [Messages], declarations: [Messages] }] }] }); /** * Generated bundle index. Do not edit. */ export { Messages, MessagesModule }; //# sourceMappingURL=primeng-messages.js.map