1
- import React , { useContext } from 'react' ;
2
- import { ToastsContext } from '../dist/main' ;
1
+ import React from 'react' ;
2
+ import { useToasts } from '../dist/main' ;
3
3
4
4
export function ToastsExamples ( ) {
5
- const toastsState = useContext ( ToastsContext ) ;
5
+ const { showToast , closeAllToasts } = useToasts ( ) ;
6
6
7
7
return (
8
8
< div className = "row" >
9
9
< div className = "col-6 mb-5" >
10
10
< h1 className = "h4" > Top left </ h1 >
11
11
< button
12
+ type = "button"
12
13
className = "btn btn-info"
13
14
onClick = { ( ) => {
14
- toastsState . show ( 'Top left toast!' , {
15
+ showToast ( 'Top left toast!' , {
15
16
position : 'TOP_LEFT' ,
16
17
} ) ;
17
18
} }
@@ -22,9 +23,10 @@ export function ToastsExamples() {
22
23
< div className = "col-6 mb-5" >
23
24
< h1 className = "h4" > Top right (default)</ h1 >
24
25
< button
26
+ type = "button"
25
27
className = "btn btn-success"
26
28
onClick = { ( ) => {
27
- toastsState . show ( 'Top right toast!' , { autoClose : false , type : 'success' } ) ;
29
+ showToast ( 'Top right toast!' , { autoClose : false , type : 'success' } ) ;
28
30
} }
29
31
>
30
32
Show top right toast
@@ -33,9 +35,10 @@ export function ToastsExamples() {
33
35
< div className = "col-6 mb-5" >
34
36
< h1 className = "h4" > Bottom left </ h1 >
35
37
< button
38
+ type = "button"
36
39
className = "btn btn-danger"
37
40
onClick = { ( ) => {
38
- toastsState . show ( 'Bottom left toast!' , {
41
+ showToast ( 'Bottom left toast!' , {
39
42
position : 'BOTTOM_LEFT' ,
40
43
type : 'danger' ,
41
44
} ) ;
@@ -47,9 +50,10 @@ export function ToastsExamples() {
47
50
< div className = "col-6 mb-5" >
48
51
< h1 className = "h4" > Bottom right </ h1 >
49
52
< button
53
+ type = "button"
50
54
className = "btn btn-warning"
51
55
onClick = { ( ) => {
52
- toastsState . show ( 'Bottom right toast!' , {
56
+ showToast ( 'Bottom right toast!' , {
53
57
position : 'BOTTOM_RIGHT' ,
54
58
type : 'warning' ,
55
59
} ) ;
@@ -58,6 +62,11 @@ export function ToastsExamples() {
58
62
Show bottom right toast
59
63
</ button >
60
64
</ div >
65
+ < div className = "col-12" >
66
+ < button type = "button" className = "btn btn-secondary" onClick = { closeAllToasts } >
67
+ Close all
68
+ </ button >
69
+ </ div >
61
70
</ div >
62
71
) ;
63
72
}
0 commit comments