clr-angular-static-fix
Version:
1. Install Clarity Icons package through npm:
102 lines (92 loc) • 3.13 kB
text/typescript
/*
* Copyright (c) 2016-2018 VMware, Inc. All Rights Reserved.
* This software is released under MIT license.
* The full license information can be found in LICENSE in the root directory of this project.
*/
import { animate, state, style, transition, trigger } from '@angular/animations';
import { Component, EventEmitter, HostBinding, Input, OnInit, Optional, Output, SkipSelf } from '@angular/core';
export class ClrStackBlock implements OnInit {
expanded: boolean = false;
expandedChange: EventEmitter<boolean> = new EventEmitter<boolean>(false);
expandable: boolean = false;
private _changedChildren: number = 0;
private _fullyInitialized: boolean = false;
private _changed: boolean = false;
get getChangedValue(): boolean {
return this._changed || (this._changedChildren > 0 && !this.expanded);
}
set setChangedValue(value: boolean) {
this._changed = value;
if (this.parent && this._fullyInitialized) {
if (value) {
this.parent._changedChildren++;
} else {
this.parent._changedChildren--;
}
}
}
/*
* This would be more efficient with @ContentChildren, with the parent ClrStackBlock
* querying for children StackBlocks, but this feature is not available when downgrading
* the component for Angular 1.
*/
constructor(
private parent: ClrStackBlock
) {
if (parent) {
parent.addChild();
}
}
ngOnInit(): void {
// in order to access the parent ClrStackBlock's properties,
// the child ClrStackBlock has to be fully initialized at first.
this._fullyInitialized = true;
}
addChild(): void {
this.expandable = true;
}
toggleExpand(): void {
if (this.expandable) {
this.expanded = !this.expanded;
this.expandedChange.emit(this.expanded);
}
}
}