1
1
import m from 'mithril' ;
2
- import { Button , Toaster , Toast } from '@/' ;
2
+ import { Button , Toaster , Toast , Switch } from '@/' ;
3
3
import { Example } from '@shared/examples' ;
4
4
5
5
const EXAMPLE_SRC = 'components/toast/examples/declarative.ts' ;
@@ -11,9 +11,10 @@ interface INotification {
11
11
12
12
export class ToastDeclarativeExample {
13
13
private notifications : INotification [ ] = [ ] ;
14
+ private timeout : number = 3000 ;
14
15
15
16
public view ( ) {
16
- return m ( Example , { src : EXAMPLE_SRC } , [
17
+ return m ( Example , { options : this . renderOptions ( ) , src : EXAMPLE_SRC } , [
17
18
m ( Button , {
18
19
label : 'Show toast' ,
19
20
intent : 'primary' ,
@@ -24,7 +25,8 @@ export class ToastDeclarativeExample {
24
25
toasts : this . notifications . map ( notification => m ( Toast , {
25
26
key : notification . key ,
26
27
message : notification . message ,
27
- onDismiss : this . dismiss
28
+ onDismiss : this . dismiss ,
29
+ timeout : this . timeout
28
30
} ) )
29
31
} )
30
32
] ) ;
@@ -41,4 +43,14 @@ export class ToastDeclarativeExample {
41
43
const index = this . notifications . findIndex ( x => x . key === key ) ;
42
44
this . notifications . splice ( index , 1 ) ;
43
45
}
46
+
47
+ private renderOptions ( ) {
48
+ return [
49
+ m ( Switch , {
50
+ checked : this . timeout === 0 ,
51
+ label : 'Timeout = 0' ,
52
+ onchange : ( ) => this . timeout = this . timeout === 0 ? 3000 : 0
53
+ } )
54
+ ] ;
55
+ }
44
56
}
0 commit comments