clr-angular-static-fix
Version:
1. Install Clarity Icons package through npm:
86 lines (76 loc) • 2.9 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 { AfterContentInit, Component, ContentChildren, EventEmitter, Input, Output, QueryList } from '@angular/core';
import { ClrAlert } from './alert';
import { MultiAlertService } from './providers/multi-alert.service';
// the 'alert-*' alert types are deprecated and should be removed in 0.12 or later
export class ClrAlerts implements AfterContentInit {
allAlerts: QueryList<ClrAlert>;
/**
* Input/Output to support two way binding on current alert index
*/
public set _inputCurrentIndex(index: number) {
if (Number.isInteger(index) && index >= 0) {
this.multiAlertService.current = index;
}
}
public currentAlertIndexChange = new EventEmitter<number>(false);
set currentAlertIndex(index: number) {
this.multiAlertService.current = index;
}
get currentAlertIndex() {
return this.multiAlertService.current;
}
/**
* Input/Output to support two way binding on current alert instance
*/
set currentAlert(alert: ClrAlert) {
if (alert) {
this.multiAlertService.currentAlert = alert;
}
}
get currentAlert() {
return this.multiAlertService.currentAlert;
}
public currentAlertChange = new EventEmitter<ClrAlert>(false);
/**
* Ensure we are only dealing with alerts that have not been closed yet
*/
get alerts() {
return this.allAlerts.filter(alert => {
return alert.isHidden === false;
});
}
get currentAlertType(): string {
if (this.multiAlertService.currentAlert) {
return this.multiAlertService.currentAlert.alertType;
}
return '';
}
constructor(public multiAlertService: MultiAlertService) {}
ngAfterContentInit() {
this.multiAlertService.manage(this.allAlerts);
this.multiAlertService.changes.subscribe(index => {
this.currentAlertIndexChange.next(index);
this.currentAlertChange.next(this.multiAlertService.currentAlert);
});
}
}