This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Steve's comments. Added fading close to toasts
- Loading branch information
1 parent
28c09b6
commit 3b5d5cb
Showing
10 changed files
with
154 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
<div> | ||
<button (click)='openMessage()'>Open toast</button> | ||
<sky-toast></sky-toast> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
Injectable, | ||
Renderer2, | ||
RendererFactory2 | ||
} from '@angular/core'; | ||
|
||
import { SkyWindowRefService } from '../window'; | ||
|
||
@Injectable() | ||
export class SkyToastAdapterService { | ||
private renderer: Renderer2; | ||
|
||
constructor( | ||
private rendererFactory: RendererFactory2, | ||
private windowRef: SkyWindowRefService | ||
) { | ||
this.renderer = this.rendererFactory.createRenderer(undefined, undefined); | ||
} | ||
|
||
public appendToBody(element: any): void { | ||
const body = this.windowRef.getWindow().document.body; | ||
this.renderer.appendChild(body, element); | ||
} | ||
|
||
public removeHostElement(): void { | ||
const document = this.windowRef.getWindow().document; | ||
const hostElement = document.querySelector('sky-toast'); | ||
this.renderer.removeChild(document.body, hostElement); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './toast-config'; | ||
export * from './toast-message'; | ||
export * from './toast-message-type'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { SkyToastType } from './toast-message-type'; | ||
|
||
export interface ToastConfig { | ||
message?: string, | ||
disableTimeout?: boolean, | ||
timeout?: number, | ||
toastType?: SkyToastType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum SkyToastType { | ||
Info, | ||
Success, | ||
Warning, | ||
Danger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { SkyToastMessageType } from './toast-message-type'; | ||
import { BehaviorSubject } from 'rxjs/BehaviorSubject'; | ||
import { Observable } from 'rxjs/Observable'; | ||
|
||
export class SkyToastMessage { | ||
public timeout?: NodeJS.Timer; | ||
private _isClosed: BehaviorSubject<boolean>; | ||
private _isClosing: BehaviorSubject<boolean>; | ||
public isClosed: Observable<boolean>; | ||
public isClosing: Observable<boolean>; | ||
|
||
constructor(public message: string, public toastType: string, private removeFromQueue: Function, timeout?: number) { | ||
this._isClosed = new BehaviorSubject(false); | ||
this._isClosing = new BehaviorSubject(false); | ||
this.isClosed = this._isClosed.asObservable(); | ||
this.isClosing = this._isClosing.asObservable(); | ||
if (timeout) { | ||
this.timeout = setTimeout(this.close, timeout); | ||
} | ||
} | ||
|
||
public close = () => { | ||
if (this.timeout) { | ||
clearTimeout(this.timeout); | ||
} | ||
if (!this._isClosing.getValue()) { | ||
this._isClosing.next(true); | ||
setTimeout(() => { | ||
this.removeFromQueue(this); | ||
this._isClosed.next(true); | ||
}, 500); | ||
} | ||
} | ||
} |