Skip to content

Commit

Permalink
Merge pull request #847 from HealthCatalyst/dev
Browse files Browse the repository at this point in the history
dev -> master
  • Loading branch information
andrew-frueh committed Apr 30, 2019
2 parents 2aea131 + 60a4be1 commit bb0d0e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Component} from '@angular/core';
color: white;
padding: 20px 10px;
display: flex;
width: 400px;
width: 100%;
}
.custom-toast-icon {
margin-right: 20px;
Expand All @@ -25,6 +25,7 @@ import {Component} from '@angular/core';
}
.custom-toast-body {
font-size: 12px;
width: 319px
}
`
]
Expand Down
4 changes: 2 additions & 2 deletions projects/cashmere/src/lib/toaster/hc-toast.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, EventEmitter, ElementRef, ViewContainerRef, ComponentRef} from '@angular/core';
import {Component, EventEmitter, ElementRef, ViewContainerRef, ComponentRef, ChangeDetectorRef} from '@angular/core';
import {trigger, state, style, transition, animate, AnimationEvent} from '@angular/animations';
import {Portal, CdkPortalOutletAttachedRef} from '@angular/cdk/portal';
import {BehaviorSubject} from 'rxjs';
Expand Down Expand Up @@ -30,7 +30,7 @@ export class HcToastComponent {
_toastPortal: Portal<any>;
readonly _componentInstance = new BehaviorSubject<any>(null);

constructor(public _el: ElementRef, public _viewContainerRef: ViewContainerRef) {}
constructor(public _el: ElementRef, public _viewContainerRef: ViewContainerRef, public _changeRef: ChangeDetectorRef) {}

_onAnimationStart(event: AnimationEvent) {
this._animationStateChanged.emit(event);
Expand Down
46 changes: 19 additions & 27 deletions projects/cashmere/src/lib/toaster/hc-toaster.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,7 @@ export class HcToasterService {
if (options.clickDismiss) {
_toastRef.componentInstance._canDismiss = options.clickDismiss;
_toastRef.componentInstance._closeClick.subscribe(() => {
this._removeToastPointer(_toastRef);
_toastRef.close();
if (options.toastClosed) {
options.toastClosed();
}
_toastRef.componentInstance._animationStateChanged
.pipe(
filter(event => event.phaseName === 'done' && event.toState === 'leave'),
take(1)
)
.subscribe(() => {
this._updateToastPositions();
});
_toastRef.componentInstance._closeClick.unsubscribe();
});
}

Expand Down Expand Up @@ -111,31 +98,36 @@ export class HcToasterService {
if (options.timeout !== 0) {
setTimeout(() => {
if (_toastRef.componentInstance) {
this._removeToastPointer(_toastRef);
_toastRef.close();
if (options.toastClosed) {
options.toastClosed();
}
_toastRef.componentInstance._animationStateChanged
.pipe(
filter(event => event.phaseName === 'done' && event.toState === 'leave'),
take(1)
)
.subscribe(() => {
this._updateToastPositions();
});
}
}, options.timeout);
}

// Cleanup functions called when the toast close animation is triggered
_toastRef.componentInstance._animationStateChanged
.pipe(
filter(event => event.phaseName === 'done' && event.toState === 'leave'),
take(1)
)
.subscribe(() => {
this._removeToastPointer(_toastRef);
if (options.toastClosed) {
options.toastClosed();
}
this._updateToastPositions();
_toastRef.componentInstance._animationStateChanged.unsubscribe();
_toastRef.componentInstance._closeClick.unsubscribe();
});

_toastRef.componentInstance._changeRef.detectChanges();
this._toasts.push(_toastRef);
return _toastRef;
}

/** Closes the most recent toast displayed */
closeLastToast() {
if (this._toasts.length > 0) {
const element = this._toasts.pop();
const element = this._toasts[this._toasts.length - 1];
if (element) {
element.close();
}
Expand All @@ -146,7 +138,7 @@ export class HcToasterService {
closeAllToasts() {
let len = this._toasts.length;
for (let index = 0; index < len; index++) {
const element = this._toasts.pop();
const element = this._toasts[index];
if (element) {
element.close();
}
Expand Down

0 comments on commit bb0d0e5

Please sign in to comment.