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) [![Discord](https://img.shields.io/discord/557940238991753

172 lines (167 loc) 7.3 kB
import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, Input, Output, ContentChild, ContentChildren, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { Footer, PrimeTemplate, SharedModule } from 'primeng/api'; import { RippleModule } from 'primeng/ripple'; import { trigger, state, style, transition, animate } from '@angular/animations'; let idx = 0; class Panel { constructor(el) { this.el = el; this.collapsed = false; this.expandIcon = 'pi pi-plus'; this.collapseIcon = 'pi pi-minus'; this.showHeader = true; this.toggler = "icon"; this.collapsedChange = new EventEmitter(); this.onBeforeToggle = new EventEmitter(); this.onAfterToggle = new EventEmitter(); this.transitionOptions = '400ms cubic-bezier(0.86, 0, 0.07, 1)'; this.id = `p-panel-${idx++}`; } ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'header': this.headerTemplate = item.template; break; case 'content': this.contentTemplate = item.template; break; case 'footer': this.footerTemplate = item.template; break; case 'icons': this.iconTemplate = item.template; break; default: this.contentTemplate = item.template; break; } }); } onHeaderClick(event) { if (this.toggler === 'header') { this.toggle(event); } } onIconClick(event) { if (this.toggler === 'icon') { this.toggle(event); } } toggle(event) { if (this.animating) { return false; } this.animating = true; this.onBeforeToggle.emit({ originalEvent: event, collapsed: this.collapsed }); if (this.toggleable) { if (this.collapsed) this.expand(event); else this.collapse(event); } event.preventDefault(); } expand(event) { this.collapsed = false; this.collapsedChange.emit(this.collapsed); } collapse(event) { this.collapsed = true; this.collapsedChange.emit(this.collapsed); } getBlockableElement() { return this.el.nativeElement.children[0]; } onToggleDone(event) { this.animating = false; this.onAfterToggle.emit({ originalEvent: event, collapsed: this.collapsed }); } } Panel.decorators = [ { type: Component, args: [{ selector: 'p-panel', template: ` <div [attr.id]="id" [ngClass]="{'p-panel p-component': true, 'p-panel-toggleable': toggleable}" [ngStyle]="style" [class]="styleClass"> <div class="p-panel-header" *ngIf="showHeader" (click)="onHeaderClick($event)" [attr.id]="id + '-titlebar'"> <span class="p-panel-title" *ngIf="header" [attr.id]="id + '_header'">{{header}}</span> <ng-content select="p-header"></ng-content> <ng-container *ngTemplateOutlet="headerTemplate"></ng-container> <div class="p-panel-icons"> <ng-template *ngTemplateOutlet="iconTemplate"></ng-template> <button *ngIf="toggleable" type="button" [attr.id]="id + '-label'" class="p-panel-header-icon p-panel-toggler p-link" pRipple (click)="onIconClick($event)" (keydown.enter)="onIconClick($event)" [attr.aria-controls]="id + '-content'" role="tab" [attr.aria-expanded]="!collapsed"> <span [class]="collapsed ? expandIcon : collapseIcon"></span> </button> </div> </div> <div [attr.id]="id + '-content'" class="p-toggleable-content" [@panelContent]="collapsed ? {value: 'hidden', params: {transitionParams: animating ? transitionOptions : '0ms', height: '0', opacity:'0'}} : {value: 'visible', params: {transitionParams: animating ? transitionOptions : '0ms', height: '*', opacity: '1'}}" (@panelContent.done)="onToggleDone($event)" role="region" [attr.aria-hidden]="collapsed" [attr.aria-labelledby]="id + '-titlebar'"> <div class="p-panel-content"> <ng-content></ng-content> <ng-container *ngTemplateOutlet="contentTemplate"></ng-container> </div> <div class="p-panel-footer" *ngIf="footerFacet || footerTemplate"> <ng-content select="p-footer"></ng-content> <ng-container *ngTemplateOutlet="footerTemplate"></ng-container> </div> </div> </div> `, animations: [ trigger('panelContent', [ state('hidden', style({ height: '0', overflow: 'hidden' })), state('void', style({ height: '{{height}}' }), { params: { height: '0' } }), state('visible', style({ height: '*' })), transition('visible <=> hidden', [style({ overflow: 'hidden' }), animate('{{transitionParams}}')]), transition('void => hidden', animate('{{transitionParams}}')), transition('void => visible', animate('{{transitionParams}}')) ]) ], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, styles: [".p-panel-header{align-items:center;display:flex;justify-content:space-between}.p-panel-title{line-height:1}.p-panel-header-icon{align-items:center;cursor:pointer;display:inline-flex;justify-content:center;overflow:hidden;position:relative;text-decoration:none}"] },] } ]; Panel.ctorParameters = () => [ { type: ElementRef } ]; Panel.propDecorators = { toggleable: [{ type: Input }], header: [{ type: Input }], collapsed: [{ type: Input }], style: [{ type: Input }], styleClass: [{ type: Input }], expandIcon: [{ type: Input }], collapseIcon: [{ type: Input }], showHeader: [{ type: Input }], toggler: [{ type: Input }], collapsedChange: [{ type: Output }], onBeforeToggle: [{ type: Output }], onAfterToggle: [{ type: Output }], transitionOptions: [{ type: Input }], footerFacet: [{ type: ContentChild, args: [Footer,] }], templates: [{ type: ContentChildren, args: [PrimeTemplate,] }] }; class PanelModule { } PanelModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, SharedModule, RippleModule], exports: [Panel, SharedModule], declarations: [Panel] },] } ]; /** * Generated bundle index. Do not edit. */ export { Panel, PanelModule }; //# sourceMappingURL=primeng-panel.js.map