@@ -2,9 +2,11 @@ import { App, Plugin, reactive, readonly } from "vue";
2
2
3
3
const InjectionKey = Symbol ( "snackbar" ) ;
4
4
5
+ type SnackbarType = "success" | "error" | "info" | "warning" ;
6
+
5
7
interface SnackbarState {
6
8
message : string ;
7
- type : "success" | "error" | "info" | "warning" | "" ;
9
+ type : SnackbarType | null ;
8
10
show : boolean ;
9
11
}
10
12
@@ -13,17 +15,17 @@ interface ISnackbarPlugin {
13
15
showError : ( msg : string ) => void ;
14
16
showInfo : ( msg : string ) => void ;
15
17
showWarning : ( msg : string ) => void ;
16
- hideSnackbar : ( ) => void ;
18
+ setShow : ( value : boolean ) => void ;
17
19
state : Readonly < SnackbarState > ;
18
20
}
19
21
20
22
const state = reactive < SnackbarState > ( {
21
23
message : "" ,
22
- type : "" ,
24
+ type : null ,
23
25
show : false ,
24
26
} ) ;
25
27
26
- const showSnackbar = ( type : SnackbarState [ "type" ] , message : string ) => {
28
+ const showSnackbar = ( type : SnackbarType , message : string ) => {
27
29
state . message = message ;
28
30
state . type = type ;
29
31
state . show = true ;
@@ -33,7 +35,7 @@ const showSnackbar = (type: SnackbarState["type"], message: string) => {
33
35
} , 4000 ) ;
34
36
} ;
35
37
36
- const plugin = {
38
+ const plugin : ISnackbarPlugin = {
37
39
showSuccess : ( msg : string ) => showSnackbar ( "success" , msg ) ,
38
40
showError : ( msg : string ) => showSnackbar ( "error" , msg ) ,
39
41
showInfo : ( msg : string ) => showSnackbar ( "info" , msg ) ,
@@ -48,5 +50,5 @@ const SnackbarPlugin: Plugin = {
48
50
} ,
49
51
} ;
50
52
51
- export { SnackbarPlugin , InjectionKey , plugin as rawPlugin } ;
53
+ export { SnackbarPlugin , InjectionKey , plugin } ;
52
54
export type { SnackbarState , ISnackbarPlugin } ;
0 commit comments