primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [ • 5.76 kB
JavaScript
import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, Input, Output, ContentChildren, NgModule } from '@angular/core';
import { trigger, state, style, transition, animate } from '@angular/animations';
import { CommonModule } from '@angular/common';
import { PrimeTemplate, SharedModule } from 'primeng/api';
import { RippleModule } from 'primeng/ripple';
let idx = 0;
class Fieldset {
constructor(el) {
this.el = el;
this.collapsed = false;
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-fieldset-${idx++}`;
}
ngAfterContentInit() {
this.templates.forEach((item) => {
switch (item.getType()) {
case 'header':
this.headerTemplate = item.template;
break;
case 'content':
this.contentTemplate = item.template;
break;
}
});
}
toggle(event) {
if (this.animating) {
return false;
}
this.animating = true;
this.onBeforeToggle.emit({ originalEvent: event, collapsed: this.collapsed });
if (this.collapsed)
this.expand(event);
else
this.collapse(event);
this.onAfterToggle.emit({ originalEvent: event, collapsed: this.collapsed });
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;
}
}
Fieldset.decorators = [
{ type: Component, args: [{
selector: 'p-fieldset',
template: `
<fieldset [attr.id]="id" [ngClass]="{'p-fieldset p-component': true, 'p-fieldset-toggleable': toggleable}" [ngStyle]="style" [class]="styleClass">
<legend class="p-fieldset-legend">
<ng-container *ngIf="toggleable; else legendContent">
<a tabindex="0" (click)="toggle($event)" (keydown.enter)="toggle($event)" [attr.aria-controls]="id + '-content'" [attr.aria-expanded]="!collapsed" pRipple>
<span class="p-fieldset-toggler pi" *ngIf="toggleable" [ngClass]="{'pi-minus': !collapsed,'pi-plus':collapsed}"></span>
<ng-container *ngTemplateOutlet="legendContent"></ng-container>
</a>
</ng-container>
<ng-template #legendContent>
<span class="p-fieldset-legend-text">{{legend}}</span>
<ng-content select="p-header"></ng-content>
<ng-container *ngTemplateOutlet="headerTemplate"></ng-container>
</ng-template>
</legend>
<div [attr.id]="id + '-content'" class="p-toggleable-content" []="collapsed ? {value: 'hidden', params: {transitionParams: transitionOptions, height: '0'}} : {value: 'visible', params: {transitionParams: animating ? transitionOptions : '0ms', height: '*'}}"
[attr.aria-labelledby]="id" [attr.aria-hidden]="collapsed"
(.done)="onToggleDone($event)" role="region">
<div class="p-fieldset-content">
<ng-content></ng-content>
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
</div>
</div>
</fieldset>
`,
animations: [
trigger('fieldsetContent', [
state('hidden', style({
height: '0',
overflow: 'hidden'
})),
state('visible', style({
height: '*'
})),
transition('visible <=> hidden', [style({ overflow: 'hidden' }), animate('{{transitionParams}}')]),
transition('void => *', animate(0))
])
],
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
styles: [".p-fieldset-legend>a,.p-fieldset-legend>span{align-items:center;display:flex;justify-content:center}.p-fieldset-toggleable .p-fieldset-legend a{-ms-user-select:none;-webkit-user-select:none;cursor:pointer;overflow:hidden;position:relative;user-select:none}.p-fieldset-legend-text{line-height:1}"]
},] }
];
Fieldset.ctorParameters = () => [
{ type: ElementRef }
];
Fieldset.propDecorators = {
legend: [{ type: Input }],
toggleable: [{ type: Input }],
collapsed: [{ type: Input }],
collapsedChange: [{ type: Output }],
onBeforeToggle: [{ type: Output }],
onAfterToggle: [{ type: Output }],
style: [{ type: Input }],
styleClass: [{ type: Input }],
transitionOptions: [{ type: Input }],
templates: [{ type: ContentChildren, args: [PrimeTemplate,] }]
};
class FieldsetModule {
}
FieldsetModule.decorators = [
{ type: NgModule, args: [{
imports: [CommonModule, RippleModule],
exports: [Fieldset, SharedModule],
declarations: [Fieldset]
},] }
];
/**
* Generated bundle index. Do not edit.
*/
export { Fieldset, FieldsetModule };
//# sourceMappingURL=primeng-fieldset.js.map