-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
969 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
################# | ||
## Misc | ||
################# | ||
**/.DS_Store | ||
nbproject | ||
manifest.mf | ||
build.xml | ||
node_modules/* | ||
npm-debug.log | ||
coverage | ||
*.js | ||
!karma.conf.js | ||
!karma-test-shim.js | ||
*.map | ||
*.d.ts | ||
!make.js | ||
!bundles/*.js | ||
typings | ||
|
||
################# | ||
## JetBrains | ||
################# | ||
.idea | ||
.project | ||
.settings | ||
.idea/* | ||
*.iml | ||
|
||
############ | ||
## Windows | ||
############ | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
############ | ||
## Mac | ||
############ | ||
|
||
# Mac crap | ||
.DS_Store | ||
|
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,39 @@ | ||
################# | ||
## Misc | ||
################# | ||
**/.DS_Store | ||
nbproject | ||
manifest.mf | ||
build.xml | ||
node_modules/* | ||
npm-debug.log | ||
coverage | ||
tests | ||
typings | ||
typings.json | ||
|
||
################# | ||
## JetBrains | ||
################# | ||
.idea | ||
.project | ||
.settings | ||
.idea/* | ||
*.iml | ||
|
||
############ | ||
## Windows | ||
############ | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
############ | ||
## Mac | ||
############ | ||
|
||
# Mac crap | ||
.DS_Store |
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,23 @@ | ||
sudo: false | ||
language: node_js | ||
cache: | ||
directories: | ||
- node_modules | ||
notifications: | ||
email: false | ||
node_js: | ||
- '5' | ||
before_install: | ||
- npm i -g npm@^3.7 | ||
before_script: | ||
- npm prune | ||
script: | ||
- npm run test | ||
after_success: | ||
- npm run semantic-release | ||
branches: | ||
except: | ||
- "/^v\\d+\\.\\d+\\.\\d+$/" | ||
before_script: | ||
- export DISPLAY=:99.0 | ||
- sh -e /etc/init.d/xvfb start |
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,162 @@ | ||
# ng2-toasty [![Build Status](https://travis-ci.org/akserg/ng2-toasty.svg?branch=master)](https://travis-ci.org/akserg/ng2-toasty) [![npm version](https://img.shields.io/npm/v/ng2-toasty.svg)](https://www.npmjs.com/package/ng2-toasty) [![npm monthly downloads](https://img.shields.io/npm/dm/ng2-toasty.svg?style=flat-square)](https://www.npmjs.com/package/ng2-toasty)[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) | ||
|
||
Angular2 Toasty component shows growl-style alerts and messages for your application. | ||
|
||
Simple examples using ng2-toasty: | ||
- with SystemJS in [ng2-systemjs-demo](https://github.com/akserg/ng2-systemjs-demo) | ||
- with Webpack in [ng2-webpack-demo](https://github.com/akserg/ng2-webpack-demo) | ||
|
||
Online demo available [here](http://akserg.github.io/ng2-webpack-demo) | ||
|
||
## Installation | ||
First you need to install the npm module: | ||
```sh | ||
npm install ng2-toasty --save | ||
``` | ||
|
||
If you use SystemJS to load your files, you might have to update your config with this if you don't use `defaultJSExtensions: true`: | ||
```js | ||
System.config({ | ||
packages: { | ||
"/ng2-toasty": {"defaultExtension": "js"} | ||
} | ||
}); | ||
``` | ||
|
||
Finally, you can use *ng2-toasty* in your Angular 2 project: | ||
- Import `ToastyService, ToastyConfig, Toasty, ToastOptions` from `ng2-toasty/ng2-toasty` | ||
- Instantiate `ToastyService, ToastyConfig` in the bootstrap of your application; | ||
- Add `Toasty` to the "directives" property of your application component; | ||
- Add `<ng2-toasty></ng2-toasty>` tag in template of your application component. | ||
|
||
```js | ||
import {Component} from 'angular2/core'; | ||
import {ToastyService, ToastyConfig, Toasty, ToastOptions, ToastData} from 'ng2-toasty/ng2-toasty'; | ||
import {bootstrap} from 'angular2/platform/browser'; | ||
|
||
bootstrap(AppComponent, [ | ||
ToastyService, ToastyConfig // It is required to have 1 unique instance of your service | ||
]); | ||
|
||
@Component({ | ||
selector: 'app', | ||
directives: [Toasty], | ||
template: ` | ||
<div>Hello world</div> | ||
<button (click)="addToast()">Add Toast</button> | ||
<ng2-toasty></ng2-toasty> | ||
` | ||
}) | ||
export class AppComponent { | ||
|
||
constructor(private toastyService:ToastyService) { } | ||
|
||
addToast() { | ||
// Just add default Toast with title only | ||
this.toastyService.default('Hi there'); | ||
// Or create the instance of ToastOptions | ||
var toastOptions:ToastOptions = { | ||
title: "My title", | ||
msg: "The message", | ||
showClose: true, | ||
timeout: 5000, | ||
theme: 'default' | ||
onAdd: (toast:ToastData) => { | ||
console.log('Toast ' + toast.id + ' has been added!'); | ||
}, | ||
onRemove: function(toast:ToastData) { | ||
console.log('Toast ' + toast.id + ' has been removed!'); | ||
} | ||
}; | ||
// Add see all possible types in one shot | ||
this.toastyService.info(toastOptions); | ||
this.toastyService.success(toastOptions); | ||
this.toastyService.wait(toastOptions); | ||
this.toastyService.error(toastOptions); | ||
this.toastyService.warning(toastOptions); | ||
} | ||
} | ||
``` | ||
|
||
## How dynamically update title and message of toast | ||
Here is an example of how to dynamically update message and title of individual toast: | ||
|
||
```js | ||
import {Component} from 'angular2/core'; | ||
import {ToastyService, ToastyConfig, Toasty, ToastOptions, ToastData} from 'ng2-toasty/ng2-toasty'; | ||
import {bootstrap} from 'angular2/platform/browser'; | ||
import {Subject, Observable, Subscription} from 'rxjs/Rx'; | ||
|
||
bootstrap(AppComponent, [ | ||
ToastyService, ToastyConfig // It is required to have 1 unique instance of your service | ||
]); | ||
|
||
@Component({ | ||
selector: 'app', | ||
directives: [Toasty], | ||
template: ` | ||
<div>Hello world</div> | ||
<button (click)="addToast()">Add Toast</button> | ||
<ng2-toasty></ng2-toasty> | ||
` | ||
}) | ||
export class AppComponent { | ||
|
||
getTitle(num: number): string { | ||
return 'Countdown: ' + num; | ||
} | ||
|
||
getMessage(num: number): string { | ||
return 'Seconds left: ' + num; | ||
} | ||
|
||
constructor(private toastyService:ToastyService) { } | ||
|
||
addToast() { | ||
let interval = 1000; | ||
let timeout = 5000; | ||
let seconds = timeout / 1000; | ||
let subscription: Subscription; | ||
|
||
let toastOptions: ToastOptions = { | ||
title: this.getTitle(seconds), | ||
msg: this.getMessage(seconds), | ||
showClose: true, | ||
timeout: timeout, | ||
onAdd: (toast: ToastData) => { | ||
console.log('Toast ' + toast.id + ' has been added!'); | ||
// Run the timer with 1 second iterval | ||
let observable = Observable.interval(interval).take(seconds); | ||
// Start listen seconds beat | ||
subscription = observable.subscribe((count: number) => { | ||
// Update title of toast | ||
toast.title = this.getTitle(seconds - count - 1); | ||
// Update message of toast | ||
toast.msg = this.getMessage(seconds - count - 1); | ||
}); | ||
|
||
}, | ||
onRemove: function(toast: ToastData) { | ||
console.log('Toast ' + toast.id + ' has been removed!'); | ||
// Stop listenning | ||
subscription.unsubscribe(); | ||
} | ||
}; | ||
|
||
switch (this.options.type) { | ||
case 'default': this.toastyService.default(toastOptions); break; | ||
case 'info': this.toastyService.info(toastOptions); break; | ||
case 'success': this.toastyService.success(toastOptions); break; | ||
case 'wait': this.toastyService.wait(toastOptions); break; | ||
case 'error': this.toastyService.error(toastOptions); break; | ||
case 'warning': this.toastyService.warning(toastOptions); break; | ||
} | ||
} | ||
} | ||
``` | ||
|
||
# License | ||
[MIT](/LICENSE) | ||
|
||
# Credits | ||
Inspired by [angular-toasty](https://github.com/teamfa/angular-toasty) |
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,53 @@ | ||
// Turn on full stack traces in errors to help debugging | ||
Error.stackTraceLimit=Infinity; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 500; | ||
|
||
// Cancel Karma's synchronous start, | ||
// we will call `__karma__.start()` later, once all the specs are loaded. | ||
__karma__.loaded = function() {}; | ||
|
||
System.config({ | ||
baseURL: '/base/', | ||
defaultJSExtensions: true, | ||
map: { | ||
'angular2': 'node_modules/angular2', | ||
'rxjs': 'node_modules/rxjs' | ||
} | ||
}); | ||
|
||
System.import('angular2/src/platform/browser/browser_adapter').then(function(browser_adapter) { | ||
browser_adapter.BrowserDomAdapter.makeCurrent(); | ||
}).then(function() { | ||
return Promise.all( | ||
Object.keys(window.__karma__.files) // All files served by Karma. | ||
.filter(onlySpecFiles) | ||
.map(file2moduleName) | ||
.map(function(path) { | ||
return System.import(path).then(function(module) { | ||
if (module.hasOwnProperty('main')) { | ||
module.main(); | ||
} else { | ||
throw new Error('Module ' + path + ' does not implement main() method.'); | ||
} | ||
}); | ||
})); | ||
}) | ||
.then(function() { | ||
__karma__.start(); | ||
}, function(error) { | ||
console.error(error.stack || error); | ||
__karma__.start(); | ||
}); | ||
|
||
|
||
function onlySpecFiles(path) { | ||
return /[\.|_]spec\.js$/.test(path); | ||
} | ||
|
||
// Normalize paths to module names. | ||
function file2moduleName(filePath) { | ||
return filePath.replace(/\\/g, '/') | ||
.replace(/^\/base\//, '') | ||
.replace(/\.js/, ''); | ||
} |
Oops, something went wrong.