@@ -4,28 +4,31 @@ import { LibraryProfile, MethodApi, StatusEvents } from '@remixproject/plugin-ut
44import { AppModal } from '@remix-ui/app'
55import { AlertModal } from '@remix-ui/app'
66import { dispatchModalInterface } from '@remix-ui/app'
7+ import { Toaster , toast } from '@remix-ui/toaster'
78
89interface INotificationApi {
910 events : StatusEvents
1011 methods : {
1112 modal : ( args : AppModal ) => void
1213 alert : ( args : AlertModal ) => void
1314 toast : ( message : string ) => void
14-
15+ hideToaster : ( id : number ) => void
1516 }
1617}
1718
1819const profile : LibraryProfile < INotificationApi > = {
1920 name : 'notification' ,
2021 displayName : 'Notification' ,
2122 description : 'Displays notifications' ,
22- methods : [ 'modal' , 'alert' , 'toast' ]
23+ methods : [ 'modal' , 'alert' , 'toast' , 'hideToaster' ]
2324}
2425
2526export class NotificationPlugin extends Plugin implements MethodApi < INotificationApi > {
2627 dispatcher : dispatchModalInterface
28+ toastId : number
2729 constructor ( ) {
2830 super ( profile )
31+ this . toastId = 0
2932 }
3033
3134 setDispatcher ( dispatcher : dispatchModalInterface ) {
@@ -40,7 +43,12 @@ export class NotificationPlugin extends Plugin implements MethodApi<INotificatio
4043 return this . dispatcher . alert ( args )
4144 }
4245
43- async toast ( message : string | JSX . Element ) {
44- this . dispatcher . toast ( message )
46+ async toast ( message : string | JSX . Element , timeout ?: number ) {
47+ this . toastId ++
48+ return this . dispatcher . toast ( message , timeout , this . toastId )
49+ }
50+
51+ async hideToaster ( id : number ) {
52+ toast . dismiss ( id )
4553 }
4654}
0 commit comments