import * as React from 'react' ; import CheckCircleOutlined from '@jdcfe/icons-react/CheckCircleOutlined' ; import TipOutlined from '@jdcfe/icons-react/TipOutlined' ; import Icon from '../icon' ; import Notification , { NotificationProps } from './Notification' ; const { JiaZai } = Icon ; let messageInstance = null ; interface IToastOptions { duration : number ; mask : boolean ; } const SHORT = 3 ; const options = { duration : SHORT , mask : false , } ; function getInstance ( props , callback ) { if ( messageInstance ) { messageInstance . destroy ( ) ; messageInstance = null ; } Notification . newInstance ( props , ( notification ) => { return callback && callback ( notification ) ; } ) ; } function notice ( message , icon , duration = options . duration , onClose , mask = options . mask ) { function close ( ) { if ( messageInstance ) { messageInstance . destroy ( ) ; messageInstance = null ; } if ( onClose ) { onClose ( ) ; } } getInstance ( { message , icon , duration , onClose : close , mask , } , ( notification ) => { messageInstance = notification ; } ) ; } export default { SHORT , LONG : 8 , show ( message , duration ? , onClose ? , mask ? ) { return notice ( message , null , duration , onClose , mask ) ; } , success ( message , duration ? , onClose ? , mask ? ) { return notice ( message , < CheckCircleOutlined />, duration, onClose, mask); } , fail ( message , duration ? , onClose ? , mask ? ) { return notice ( message , < TipOutlined />, duration, onClose, mask); } , loading ( message , duration ? , onClose ? , mask ? ) { return notice ( message , < JiaZai className = { 'Yep-toast-notice-icon Yep-icon-jiazai' } / > , duration , onClose , mask ) ; } , hide ( ) { if ( messageInstance ) { messageInstance . destroy ( ) ; messageInstance = null ; } } , config ( option = { } ) { const { duration = SHORT , mask } = option ; options . duration = duration ; if ( mask === true ) { options . mask = true ; } } , } ;