/*-------------------------------------------------------------------------------------------------------------- * Copyright (c) insite-gmbh. All rights reserved. * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------------------------*/ import { Component, Input, OnInit, OnDestroy, Inject } from '@angular/core'; import { IExpandablePanel, IExpandablePanelCollection, IEXPANDABLEPANELCOLLECTIONSERVICE_TOKEN } from '../interfaces/index'; @Component({ selector: 'expandable-panel', templateUrl: './@inax/commonUi/src/expandablePanel/expandablePanelComponent/expandablePanel.component.html' }) export class ExpandablePanelComponent implements OnInit, OnDestroy, IExpandablePanel { private _isExpanded: boolean; @Input() panelId: string; @Input() initiallyExpanded: boolean; @Input() pinnable: boolean; get id(): string { return this.panelId; } get isExpanded(): boolean { return this._isExpanded; } onShrink(): void { let p: IExpandablePanel = this._expandablePanelCollection.get(this.id); if (p) { p.shrink(); } } constructor(@Inject(IEXPANDABLEPANELCOLLECTIONSERVICE_TOKEN) private _expandablePanelCollection: IExpandablePanelCollection) {} ngOnInit() { console.log("ExpandablePanelComponent.ngOnInit", this.panelId); this._isExpanded = this.initiallyExpanded || false; this._expandablePanelCollection.add(this); } ngOnDestroy() { this._expandablePanelCollection.remove(this); } expand(): void { this._isExpanded = true; } shrink(): void { this._isExpanded = false; } toggle(): void { this._isExpanded = !this._isExpanded; } }