Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for autoHide delay per type #9 #125

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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