bia-framework
Version:
Bia Framework to work with angular 2
172 lines (133 loc) • 4.14 kB
text/typescript
import {
Input,
Output,
OnInit,
EventEmitter,
AfterContentInit,
Component,
ViewEncapsulation,
Host,
ViewContainerRef,
ViewChild,
ComponentResolver
} from "@angular/core";
import {NgClass, NgFor} from "@angular/common";
import {Observable} from "rxjs/Observable";
import {Observer} from "rxjs/Observer";
import {RippleEffect} from "../ripple-effect/RippleEffect";
import {ICoreDialogArguments} from "../core-dialog/core-dialog.service";
import {CoreIcon} from "../core-icon/core-icon";
import {CoreAnimations} from "../core-animations/CoreAnimations";
declare var System:any;
export class CoreTabs implements AfterContentInit
{
public tabs:Array<CoreTab> = [];
public IsVisible:boolean = false;
isNavegationFull:boolean;
private _selectedIndex:number = 0;
public get selectedIndex():number
{
return this._selectedIndex;
}
public set selectedIndex(index:number)
{
if (this._selectedIndex != index)
{
this._selectedIndex = index;
this.selectedIndexChange.emit(index);
this.selectTab(index);
}
}
public selectedIndexChange = new EventEmitter<number>();
constructor()
{
this.tabs = [];
}
ngAfterContentInit():any
{
return undefined;
}
private selectTab = (index:number):void =>
{
this.tabs.forEach(item => item.isActive = false);
this.tabs[index].isActive = true;
};
public addTab = (tab:CoreTab):void =>
{
this.tabs.push(tab);
};
public getColor = (isactive:boolean):string =>
{
if (isactive) return "white";
else return "secondary";
};
}
export class CoreTab implements OnInit, AfterContentInit
{
ngAfterContentInit():any
{
this.setupDynamicContent().subscribe();
return undefined;
}
icon:string;
title:string;
isActive:boolean;
dynamic:ViewContainerRef;
dynamicContent:ICoreDialogArguments;
private isContentProcessing:boolean = false;
constructor( private tabHost:CoreTabs, private resolver:ComponentResolver)
{
tabHost.addTab(this);
}
ngOnInit():any
{
this.title = this.title || "";
this.isActive = this.isActive || false;
return undefined;
}
public setupDynamicContent = ():Observable<void> =>
{
return Observable.create((observer:Observer<void>) =>
{
if (this.dynamicContent == null)
observer.complete();
else
{
this.isContentProcessing = true;
System.import(this.dynamicContent.path)
.then(c => c[this.dynamicContent.className])
.then((result)=>
{
this.resolver.resolveComponent(result).then(factory =>
{
this.dynamic.createComponent(factory, 0, this.dynamic.injector);
this.isContentProcessing = false;
});
});
}
});
};
}