44
55import { merge , reject } from 'ramda'
66
7+ import { TThemeMap } from '@/spec'
78import { Global } from './helper'
89import { nilOrEmpty } from './validator'
910
10- const checkValid = ( ) => Global . iziToast || false
11+ type TToastType = 'success' | 'error' | 'warn'
12+
13+ type TToastOption = {
14+ title : string
15+ msg : string
16+ progressBarColor : string
17+ position : 'bottom' | 'top'
18+ }
19+
20+ const checkValid = ( ) => ( Global as any ) . iziToast || false
1121
1222const defaultOptions = {
1323 title : 'coderplanets' ,
@@ -20,26 +30,33 @@ const defaultOptions = {
2030 transitionIn : 'fadeInDown' ,
2131}
2232
23- const doNotify = ( options = { } ) => {
24- if ( ! checkValid ( ) ) return false
25-
26- /* eslint-disable no-undef */
33+ const doNotify = ( options = { } ) : void => {
34+ if ( ! checkValid ( ) ) {
35+ return
36+ }
37+ const { iziToast } = Global as any
2738 iziToast . show ( merge ( defaultOptions , reject ( nilOrEmpty , options ) ) )
28- return false
2939}
3040
3141export const toast = {
32- info : ( { title, msg, progressBarColor, position } ) =>
33- doNotify ( { title, message : msg , progressBarColor, position } ) ,
34- error : ( { title, msg, progressBarColor, position } ) =>
35- doNotify ( { title, message : msg , progressBarColor, position } ) ,
36- success : ( { title, msg, progressBarColor, position } ) =>
37- doNotify ( { title, message : msg , progressBarColor, position } ) ,
38- warn : ( { title, msg, progressBarColor, position } ) =>
39- doNotify ( { title, message : msg , progressBarColor, position } ) ,
42+ info : ( { title, msg, progressBarColor, position } : TToastOption ) : void => {
43+ doNotify ( { title, message : msg , progressBarColor, position } )
44+ } ,
45+ error : ( { title, msg, progressBarColor, position } : TToastOption ) : void => {
46+ doNotify ( { title, message : msg , progressBarColor, position } )
47+ } ,
48+ success : ( { title, msg, progressBarColor, position } : TToastOption ) : void => {
49+ doNotify ( { title, message : msg , progressBarColor, position } )
50+ } ,
51+ warn : ( { title, msg, progressBarColor, position } : TToastOption ) : void => {
52+ doNotify ( { title, message : msg , progressBarColor, position } )
53+ } ,
4054}
4155
42- export const toastBarColor = ( type , themeData ) => {
56+ export const toastBarColor = (
57+ type : TToastType ,
58+ themeData : TThemeMap ,
59+ ) : string => {
4360 switch ( type ) {
4461 case 'success' :
4562 return themeData . toast . successBar
0 commit comments