From 765ec14e0eb151b90210691cc65431df8279356b Mon Sep 17 00:00:00 2001 From: Alex Overbeck Date: Fri, 10 May 2019 13:53:17 -0400 Subject: [PATCH] Fixes the way data is exposed to the go-toast component (#33) There was an issue we were running into when attempting to compile goponents due to the toast component template not having access to the functions that are private inside the component.ts file. This keeps those private, but changes the way we expose those to the template using static variables. This will fix this issue and is probably a little bit more performant. --- .../go-toast/go-toast.component.html | 6 ++-- .../components/go-toast/go-toast.component.ts | 32 ++++++++++++------- projects/go-tester/src/app/app.component.ts | 2 ++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/projects/go-lib/src/lib/components/go-toast/go-toast.component.html b/projects/go-lib/src/lib/components/go-toast/go-toast.component.html index ed26ed46e..3bae1b899 100644 --- a/projects/go-lib/src/lib/components/go-toast/go-toast.component.html +++ b/projects/go-lib/src/lib/components/go-toast/go-toast.component.html @@ -1,7 +1,7 @@
-
+
- +
{{ header }}
@@ -12,4 +12,4 @@
{{ header }}
-
\ No newline at end of file + diff --git a/projects/go-lib/src/lib/components/go-toast/go-toast.component.ts b/projects/go-lib/src/lib/components/go-toast/go-toast.component.ts index 3d9ddd5cf..d93a8b42d 100644 --- a/projects/go-lib/src/lib/components/go-toast/go-toast.component.ts +++ b/projects/go-lib/src/lib/components/go-toast/go-toast.component.ts @@ -5,7 +5,9 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; templateUrl: './go-toast.component.html', styleUrls: ['./go-toast.component.scss'] }) -export class GoToastComponent { +export class GoToastComponent implements OnInit { + statusClass: string = 'go-toast-status--neutral'; + icon: string = 'notifications_none'; @Input() dismissable: boolean = false; @Input() header: string; @@ -14,17 +16,29 @@ export class GoToastComponent { @Output() handleDismiss = new EventEmitter(); + ngOnInit(): void { + this.statusClass = this.getStatus(); + this.icon = this.getIcon(); + } + + public dismiss(): void { + this.handleDismiss.emit(); + } + //#region Private Methods - private statusClasses() : object { - return { - 'go-toast-status--positive': this.type === 'positive', - 'go-toast-status--neutral': this.type === 'neutral' || !this.type, - 'go-toast-status--negative': this.type === 'negative' + private getStatus(): string { + switch (this.type) { + case 'positive': + return 'go-toast-status--positive'; + case 'negative': + return 'go-toast-status--negative'; + default: + return 'go-toast-status--neutral'; } } - private goIconType() : string { + private getIcon(): string { switch (this.type) { case 'positive': return 'done'; @@ -35,9 +49,5 @@ export class GoToastComponent { } } - private dismiss() : void { - this.handleDismiss.emit(); - } - //#endregion } diff --git a/projects/go-tester/src/app/app.component.ts b/projects/go-tester/src/app/app.component.ts index e7ee06d89..67e144760 100644 --- a/projects/go-tester/src/app/app.component.ts +++ b/projects/go-tester/src/app/app.component.ts @@ -42,6 +42,8 @@ export class AppComponent implements OnInit { setTimeout(() => { this.goToasterService.toastInfo({ message: 'Check this out'}); + this.goToasterService.toastSuccess({message: 'Check this out' }); + this.goToasterService.toastError({ message: 'Check this out' }); }, 1500); }