Skip to content

Commit

Permalink
feat(BodyOutputType.Component): added toast instance
Browse files Browse the repository at this point in the history
When rendering BodyOutputType.Component, the toast instance itself is
applied to the rendered component.  This allows the component to
interact with the toast as needed, as well as expose access to the toast
id.  Addresses #84.

ResetTimer on mouseout was not being properly called. It is now called
appropriately when mouseoverTimerStop is set to true.  Thanks to @kb3eua
for the pull request fix.

Documented the mouseoverTimerStop config option and documented the
addition of the toast instance to components when using
BodyOutputType.Component.  Closes
#83.
  • Loading branch information
Stabzs committed Dec 3, 2016
1 parent 28165e9 commit ccc958f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 13 deletions.
23 changes: 20 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
# 1.1.0 (2016-12-02)
### Features
* **toast.component:** When rendering BodyOutputType.Component, the toast instance itself is
applied to the rendered component. This allows the component to interact with the toast as
needed, as well as expose access to the toast id.
Addresses [#84](https://github.com/Stabzs/Angular2-Toaster/issues/84).

### Bug Fix
* **toaster-container.component:** ResetTimer on mouseout was not being properly called. It is
now called appropriately when mouseoverTimerStop is set to true. Thanks to @kb3eua.

### Documentation
* **README:** Documented the mouseoverTimerStop config option and documented the addition of the
toast instance to components when using BodyOutputType.Component. Closes
[#83](https://github.com/Stabzs/Angular2-Toaster/issues/83).


# 1.0.2 (2016-10-12)
### Features
* **Angular 2.0.2 Support:** The library has been tested through to Angular 2.0.2.

### Bug Fixes
* **toast.component:** Dynamic template data would break `bodyOutputType.Component` rendering.
A forced `detectChanges()` call has been added after the component is created and loaded to enable
Expand All @@ -8,9 +28,6 @@ this functionality. Additional test cases were added for the gap. Closes
the `Toast` file is an interface-only file, there is nothing to load. Closes
[#70](https://github.com/Stabzs/Angular2-Toaster/issues/70).

### Features
* **Angular 2.0.2 Support:** The library has been tested through to Angular 2.0.2.


# 1.0.1 (2016-09-16)
### Bug Fix
Expand Down
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
largely based off of [AngularJS-Toaster](https://github.com/jirikavi/AngularJS-Toaster).

[![Build Status](https://travis-ci.org/Stabzs/Angular2-Toaster.svg?branch=master)](https://travis-ci.org/Stabzs/Angular2-Toaster)
[![Coverage Status](https://coveralls.io/repos/github/Stabzs/Angular2-Toaster/badge.svg?branch=master&b=1.0.2)](https://coveralls.io/github/Stabzs/Angular2-Toaster?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/Stabzs/Angular2-Toaster/badge.svg?branch=master&b=1.1.0)](https://coveralls.io/github/Stabzs/Angular2-Toaster?branch=master)

### Current Version 1.0.2
### Current Version 1.1.0

## Installation:

Expand Down Expand Up @@ -335,7 +335,7 @@ The timeout can be configured at three different levels:
By passing the timeout config option as an object instead of a number, you can specify the global
behavior an info-class type should have.

```typescript
```
template:
`<toaster-container [toasterconfig]="toasterconfig"></toaster-container>`

Expand All @@ -353,10 +353,23 @@ If a type is not defined and specified, a timeout will not be applied, making th
showCloseButton: true,
closeHtml: '<button>Close</button>'
};

this.toasterService.pop(toast);
```
### Prevent Timeout on Mouseover
By default, all toasts are dismissed when their timer expires, even if you mouse over the toast.
This can be overriden via the container's config.
```typescript
template:
`<toaster-container [toasterconfig]="toasterconfig"></toaster-container>`

public toasterconfig : ToasterConfig =
new ToasterConfig({mouseoverTimerStop: false});
```
### Body Output Type
There are three different types of body renderings that can be passed via the
`toast.bodyOutputType` argument: 'Default', 'TrustedHtml', and 'Component'. If a `bodyOutputType`
Expand Down Expand Up @@ -399,6 +412,11 @@ of the toast.
this.toasterService.pop(toast);
```
The Component BodyOutputType offers the additional flexibilty of attaching the toast instance to
your component. It is recommended that you expose a public property on your component for type
safe access to the toast instance if you need to consume it inside of your component.
Mutation of the toast instance is not recommended.
### On Show Callback
An onShow callback function can be attached to each toast instance. The callback will be invoked upon toast add.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular2-toaster",
"version": "1.0.2",
"version": "1.1.0",
"description": "An Angular 2 Toaster Notification library based on AngularJS-Toaster",
"main": "angular2-toaster.js",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions src/toast.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class ToastComponent {
ngAfterViewInit() {
if (this.toast.bodyOutputType === this.bodyOutputType.Component) {
let component = this.componentFactoryResolver.resolveComponentFactory(this.toast.body);
this.componentBody.createComponent(component, null, this.componentBody.injector);
let componentInstance : any = this.componentBody.createComponent(component, null, this.componentBody.injector);
componentInstance.instance.toast = this.toast;
this.changeDetectorRef.detectChanges();
}
}
Expand All @@ -61,4 +62,4 @@ export class ToastComponent {
value : { toast: toast, isCloseButton: true}
});
}
}
}
35 changes: 32 additions & 3 deletions src/toaster-container.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ export class TestDynamicComponentModule { }

@Component({
selector: 'bound-dynamic-component',
template: `<div>{{someValue}} loaded via component</div>`
template: '<div>{{someValue}} loaded via component<button (click)="clickHandler()" id="click"></button></div>'
})
export class TestBoundDynamicComponent {
someValue: string = 'Some value';
public toast : Toast = null;

clickHandler() {
this.toast.title = 'updated title';
}
}
@NgModule({
bootstrap: [TestBoundDynamicComponent],
Expand Down Expand Up @@ -979,7 +984,7 @@ describe('ToasterContainerComponent when included as a component with bindings',
});


it('should redner the dynamic bound content', () => {
it('should render the dynamic bound content', () => {
fixture.detectChanges();
var container = fixture.debugElement.children[0].componentInstance;
var toast: Toast = {
Expand All @@ -994,6 +999,30 @@ describe('ToasterContainerComponent when included as a component with bindings',
expect(container.toasts.length).toBe(1);

var renderedToast = fixture.nativeElement.querySelector('bound-dynamic-component');
expect(renderedToast.innerHTML).toBe('<div>Some value loaded via component</div>');
expect(renderedToast.innerHTML).toBe('<div>Some value loaded via component<button id="click"></button></div>');
});

it('should propagate the toast instance to the component', () => {
fixture.detectChanges();
var container = fixture.debugElement.children[0].componentInstance;
var toast: Toast = {
type: 'success',
title: 'test',
body: TestBoundDynamicComponent,
bodyOutputType: BodyOutputType.Component
};

var toastInstance = fixture.componentInstance.toasterService.pop(toast);
fixture.detectChanges();

expect(container.toasts.length).toBe(1);
expect(toastInstance.title).toBe('test');

var clickButton = fixture.nativeElement.querySelector('#click');
clickButton.click();

fixture.detectChanges();

expect(toastInstance.title).toBe('updated title');
});
});

0 comments on commit ccc958f

Please sign in to comment.