Skip to content

Commit

Permalink
Add support for autoHide delay per type #9
Browse files Browse the repository at this point in the history
  • Loading branch information
shyallegro committed Apr 30, 2019
1 parent 1bff46d commit ef9a302
Show file tree
Hide file tree
Showing 5 changed files with 731 additions and 644 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ behaviour: {

/**
* Defines whether each notification will hide itself automatically after a timeout passes
* @type {number | false}
* support and object with a key per type defaulting to default key.
* @type {number | false | [{key: string]: number | false}}
*/
autoHide: 5000,

Expand Down Expand Up @@ -510,7 +511,7 @@ const notifierDefaultOptions: NotifierOptions = {
},
theme: 'material',
behaviour: {
autoHide: 5000,
autoHide: {default: 5000, info: 3000, error: false},
onClick: false,
onMouseover: 'pauseAutoHide',
showDismissButton: true,
Expand Down
134 changes: 67 additions & 67 deletions src/demo/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { NotifierModule, NotifierOptions } from './../lib/index';

import { AppComponent } from './app.component';

/**
* Custom angular notifier options
*/
const customNotifierOptions: NotifierOptions = {
position: {
horizontal: {
position: 'left',
distance: 12
},
vertical: {
position: 'bottom',
distance: 12,
gap: 10
}
},
theme: 'material',
behaviour: {
autoHide: false,
onClick: false,
onMouseover: 'pauseAutoHide',
showDismissButton: true,
stacking: 4
},
animations: {
enabled: true,
show: {
preset: 'slide',
speed: 300,
easing: 'ease'
},
hide: {
preset: 'fade',
speed: 300,
easing: 'ease',
offset: 50
},
shift: {
speed: 300,
easing: 'ease'
},
overlap: 150
}
};

/**
* App module
*/
@NgModule( {
bootstrap: [
AppComponent
],
declarations: [
AppComponent
],
imports: [
BrowserModule,
NotifierModule.withConfig( customNotifierOptions )
]
} )
export class AppModule {}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { NotifierModule, NotifierOptions } from './../lib/index';

import { AppComponent } from './app.component';

/**
* Custom angular notifier options
*/
const customNotifierOptions: NotifierOptions = {
position: {
horizontal: {
position: 'left',
distance: 12
},
vertical: {
position: 'bottom',
distance: 12,
gap: 10
}
},
theme: 'material',
behaviour: {
autoHide: {default: 5000, info: 2000, success: 10000, error: false},
onClick: false,
onMouseover: 'pauseAutoHide',
showDismissButton: true,
stacking: 4
},
animations: {
enabled: true,
show: {
preset: 'slide',
speed: 300,
easing: 'ease'
},
hide: {
preset: 'fade',
speed: 300,
easing: 'ease',
offset: 50
},
shift: {
speed: 300,
easing: 'ease'
},
overlap: 150
}
};

/**
* App module
*/
@NgModule( {
bootstrap: [
AppComponent
],
declarations: [
AppComponent
],
imports: [
BrowserModule,
NotifierModule.withConfig( customNotifierOptions )
]
} )
export class AppModule {}
62 changes: 62 additions & 0 deletions src/lib/src/components/notifier-notification.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,68 @@ describe( 'Notifier Notification Component', () => {

} ) );

it( 'should extract autoHide values from key', fakeAsync( () => {

// Setup test module
beforeEachWithConfig( new NotifierConfig( {
animations: {
enabled: false
},
behaviour: {
autoHide: {[testNotification.type]: 787, default: 989}
onMouseover: 'pauseAutoHide'
}
} ) );

componentInstance.notification = testNotification;
componentFixture.detectChanges();
jest.spyOn(timerService, 'start');
componentInstance.show({type: 'info', message: 'test'});

expect( timerService.start ).toHaveBeenCalledWith(787);
} ) );

it( 'should extract autoHide values from default', fakeAsync( () => {

// Setup test module
beforeEachWithConfig( new NotifierConfig( {
animations: {
enabled: false
},
behaviour: {
autoHide: {default: 989}
onMouseover: 'pauseAutoHide'
}
} ) );

componentInstance.notification = testNotification;
componentFixture.detectChanges();
jest.spyOn(timerService, 'start');
componentInstance.show({type: 'info', message: 'test'});

expect( timerService.start ).toHaveBeenCalledWith(989);
} ) );

it( 'should extract autoHide values from fallback', fakeAsync( () => {

// Setup test module
beforeEachWithConfig( new NotifierConfig( {
animations: {
enabled: false
},
behaviour: {
autoHide: {}
onMouseover: 'pauseAutoHide'
}
} ) );

componentInstance.notification = testNotification;
componentFixture.detectChanges();
jest.spyOn(timerService, 'start');
componentInstance.show({type: 'info', message: 'test'});

expect( timerService.start ).not.toHaveBeenCalled();
} ) );
} );

/**
Expand Down
Loading

0 comments on commit ef9a302

Please sign in to comment.