novo-elements
Version:
Bullhorn's NOVO Element Repository for Angular 2
227 lines (198 loc) • 5.16 kB
text/typescript
// NG2
import { Component, Input, EventEmitter, Output, HostBinding } from '@angular/core';
export class NovoNavElement {
theme: string = '';
direction: string = '';
outlet: any;
router: string;
condensed: boolean = false;
items: Array<any> = [];
select(item) {
/**
* Deactivate all other tabs
*/
function _deactivateAllItems(items) {
items.forEach((t) => {
if (t.active === true) {
// t.deselected.next();
}
t.active = false;
});
}
_deactivateAllItems(this.items);
item.active = true;
if (this.outlet) {
this.outlet.show(this.items.indexOf(item));
}
// TODO - remove hack to make DOM rerender - jgodi
let element = document.querySelector('novo-tab-link.active span.indicator') as any;
if (element) {
element.style.opacity = 0.99;
setTimeout(() => {
element.style.opacity = 1;
}, 10);
}
}
add(item) {
if (this.items.length === 0) {
item.active = true;
// item.selected.next();
}
this.items.push(item);
}
}
export class NovoTabElement {
active: boolean = false;
disabled: boolean = false;
activeChange: EventEmitter<boolean> = new EventEmitter<boolean>();
nav: any;
constructor(nav: NovoNavElement) {
this.nav = nav;
this.nav.add(this);
}
select() {
if (!this.disabled) {
this.activeChange.emit(true);
this.nav.select(this);
}
}
}
export class NovoTabButtonElement {
active: boolean = false;
disabled: boolean = false;
nav: any;
constructor(nav: NovoNavElement) {
this.nav = nav;
this.nav.add(this);
}
select() {
if (!this.disabled) {
this.nav.select(this);
}
}
}
export class NovoTabLinkElement {
active: boolean = false;
disabled: boolean = false;
nav: any;
constructor(nav: NovoNavElement) {
this.nav = nav;
this.nav.add(this);
}
select() {
if (!this.disabled) {
this.nav.select(this);
}
}
}
export class NovoNavOutletElement {
items: Array<any> = [];
show(index) {
let item = this.items[index];
/**
* Deactivates other tab items
* @param items - deactivated items
*/
function _deactivateAllItems(items) {
items.forEach((t) => {
if (t.active === true) {
// t.deselected.next();
}
t.active = false;
});
}
_deactivateAllItems(this.items);
item.active = true;
}
add(item) {
if (this.items.length === 0) {
item.active = true;
}
this.items.push(item);
}
}
export class NovoNavContentElement {
active: boolean = false;
constructor(outlet: NovoNavOutletElement) {
outlet.add(this);
}
}
export class NovoNavHeaderElement {
active: boolean = false;
forElement: any;
outlet: any;
constructor(outlet: NovoNavOutletElement) {
this.active = this.active || false;
this.outlet = outlet;
}
show(event?: any) {
try {
const INDEX = this.outlet.items.indexOf(this.forElement);
if (INDEX > -1) {
this.outlet.show(INDEX);
}
} catch (err) {
// do nothing
}
}
}