import {NgModule,Component,Input,Output,EventEmitter,ElementRef} from '@angular/core'; import {trigger,state,style,transition,animate} from '@angular/animations'; import {CommonModule} from '@angular/common'; import {SharedModule} from '../common/shared'; import {BlockableUI} from '../common/blockableui'; let idx: number = 0; @Component({ selector: 'p-fieldset', template: `
{{legend}}
`, animations: [ trigger('fieldsetContent', [ state('hidden', style({ height: '0px' })), state('visible', style({ height: '*' })), transition('visible => hidden', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)')), transition('hidden => visible', animate('400ms cubic-bezier(0.86, 0, 0.07, 1)')) ]) ] }) export class Fieldset implements BlockableUI { @Input() legend: string; @Input() toggleable: boolean; @Input() collapsed: boolean = false; @Output() collapsedChange: EventEmitter = new EventEmitter(); @Output() onBeforeToggle: EventEmitter = new EventEmitter(); @Output() onAfterToggle: EventEmitter = new EventEmitter(); @Input() style: any; @Input() styleClass: string public animating: boolean; constructor(private el: ElementRef) {} id: string = `ui-fieldset-${idx++}`; 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(): HTMLElement { return this.el.nativeElement.children[0]; } onToggleDone(event: Event) { this.animating = false; } } @NgModule({ imports: [CommonModule], exports: [Fieldset,SharedModule], declarations: [Fieldset] }) export class FieldsetModule { }