import { Component, Input, Output, EventEmitter } from '@angular/core'; import { Alert, AlertType } from '../../models/alert.interface'; @Component({ selector: 'alert-dialog', templateUrl: 'alert.component.html' }) export class AlertComponent { @Input('alerts') alerts: Alert[]; @Output() alertClosed = new EventEmitter(); constructor() {} removeAlertById(id: string) { this.alerts = this.alerts.filter(x => x.id !== id); } cssClass(alert: Alert) { if (!alert) { return; } // return css class based on alert type switch (alert.type) { case AlertType.Success: return 'hdca-alert--is-success'; case AlertType.Error: return 'hdca-alert--is-error'; case AlertType.Info: return 'hdca-alert--is-info hdca-alert--is-subtle'; case AlertType.Warning: return 'hdca-alert--is-warning'; case AlertType.Savings: return 'hdca-alert--is-savings hdca-alert--is-compact hdca-alert--is-subtle'; } } dismissAlert(alert) { this.alertClosed.emit(alert.id); } }