Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ef9a302

Browse files
Add support for autoHide delay per type #9
1 parent 1bff46d commit ef9a302

File tree

5 files changed

+731
-644
lines changed

5 files changed

+731
-644
lines changed

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ behaviour: {
324324

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

@@ -510,7 +511,7 @@ const notifierDefaultOptions: NotifierOptions = {
510511
},
511512
theme: 'material',
512513
behaviour: {
513-
autoHide: 5000,
514+
autoHide: {default: 5000, info: 3000, error: false},
514515
onClick: false,
515516
onMouseover: 'pauseAutoHide',
516517
showDismissButton: true,

‎src/demo/app.module.ts‎

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
1-
import { NgModule } from '@angular/core';
2-
import { BrowserModule } from '@angular/platform-browser';
3-
4-
import { NotifierModule, NotifierOptions } from './../lib/index';
5-
6-
import { AppComponent } from './app.component';
7-
8-
/**
9-
* Custom angular notifier options
10-
*/
11-
const customNotifierOptions: NotifierOptions = {
12-
position: {
13-
horizontal: {
14-
position: 'left',
15-
distance: 12
16-
},
17-
vertical: {
18-
position: 'bottom',
19-
distance: 12,
20-
gap: 10
21-
}
22-
},
23-
theme: 'material',
24-
behaviour: {
25-
autoHide: false,
26-
onClick: false,
27-
onMouseover: 'pauseAutoHide',
28-
showDismissButton: true,
29-
stacking: 4
30-
},
31-
animations: {
32-
enabled: true,
33-
show: {
34-
preset: 'slide',
35-
speed: 300,
36-
easing: 'ease'
37-
},
38-
hide: {
39-
preset: 'fade',
40-
speed: 300,
41-
easing: 'ease',
42-
offset: 50
43-
},
44-
shift: {
45-
speed: 300,
46-
easing: 'ease'
47-
},
48-
overlap: 150
49-
}
50-
};
51-
52-
/**
53-
* App module
54-
*/
55-
@NgModule( {
56-
bootstrap: [
57-
AppComponent
58-
],
59-
declarations: [
60-
AppComponent
61-
],
62-
imports: [
63-
BrowserModule,
64-
NotifierModule.withConfig( customNotifierOptions )
65-
]
66-
} )
67-
export class AppModule {}
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
4+
import { NotifierModule, NotifierOptions } from './../lib/index';
5+
6+
import { AppComponent } from './app.component';
7+
8+
/**
9+
* Custom angular notifier options
10+
*/
11+
const customNotifierOptions: NotifierOptions = {
12+
position: {
13+
horizontal: {
14+
position: 'left',
15+
distance: 12
16+
},
17+
vertical: {
18+
position: 'bottom',
19+
distance: 12,
20+
gap: 10
21+
}
22+
},
23+
theme: 'material',
24+
behaviour: {
25+
autoHide: {default: 5000,info: 2000,success: 10000,error: false},
26+
onClick: false,
27+
onMouseover: 'pauseAutoHide',
28+
showDismissButton: true,
29+
stacking: 4
30+
},
31+
animations: {
32+
enabled: true,
33+
show: {
34+
preset: 'slide',
35+
speed: 300,
36+
easing: 'ease'
37+
},
38+
hide: {
39+
preset: 'fade',
40+
speed: 300,
41+
easing: 'ease',
42+
offset: 50
43+
},
44+
shift: {
45+
speed: 300,
46+
easing: 'ease'
47+
},
48+
overlap: 150
49+
}
50+
};
51+
52+
/**
53+
* App module
54+
*/
55+
@NgModule( {
56+
bootstrap: [
57+
AppComponent
58+
],
59+
declarations: [
60+
AppComponent
61+
],
62+
imports: [
63+
BrowserModule,
64+
NotifierModule.withConfig( customNotifierOptions )
65+
]
66+
} )
67+
export class AppModule {}

‎src/lib/src/components/notifier-notification.component.spec.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,68 @@ describe( 'Notifier Notification Component', () => {
948948

949949
} ) );
950950

951+
it( 'should extract autoHide values from key', fakeAsync( () => {
952+
953+
// Setup test module
954+
beforeEachWithConfig( new NotifierConfig( {
955+
animations: {
956+
enabled: false
957+
},
958+
behaviour: {
959+
autoHide: {[testNotification.type]: 787, default: 989}
960+
onMouseover: 'pauseAutoHide'
961+
}
962+
} ) );
963+
964+
componentInstance.notification = testNotification;
965+
componentFixture.detectChanges();
966+
jest.spyOn(timerService, 'start');
967+
componentInstance.show({type: 'info', message: 'test'});
968+
969+
expect( timerService.start ).toHaveBeenCalledWith(787);
970+
} ) );
971+
972+
it( 'should extract autoHide values from default', fakeAsync( () => {
973+
974+
// Setup test module
975+
beforeEachWithConfig( new NotifierConfig( {
976+
animations: {
977+
enabled: false
978+
},
979+
behaviour: {
980+
autoHide: {default: 989}
981+
onMouseover: 'pauseAutoHide'
982+
}
983+
} ) );
984+
985+
componentInstance.notification = testNotification;
986+
componentFixture.detectChanges();
987+
jest.spyOn(timerService, 'start');
988+
componentInstance.show({type: 'info', message: 'test'});
989+
990+
expect( timerService.start ).toHaveBeenCalledWith(989);
991+
} ) );
992+
993+
it( 'should extract autoHide values from fallback', fakeAsync( () => {
994+
995+
// Setup test module
996+
beforeEachWithConfig( new NotifierConfig( {
997+
animations: {
998+
enabled: false
999+
},
1000+
behaviour: {
1001+
autoHide: {}
1002+
onMouseover: 'pauseAutoHide'
1003+
}
1004+
} ) );
1005+
1006+
componentInstance.notification = testNotification;
1007+
componentFixture.detectChanges();
1008+
jest.spyOn(timerService, 'start');
1009+
componentInstance.show({type: 'info', message: 'test'});
1010+
1011+
expect( timerService.start ).not.toHaveBeenCalled();
1012+
} ) );
9511013
} );
9521014

9531015
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /