@@ -3,27 +3,31 @@ import { LibraryProfile, MethodApi, StatusEvents } from '@remixproject/plugin-ut
33import { AppModal } from '@remix-ui/app'
44import { AlertModal } from '@remix-ui/app'
55import { dispatchModalInterface } from '@remix-ui/app'
6+ import { Toaster , toast } from '@remix-ui/toaster'
67
78interface INotificationApi {
89 events : StatusEvents
910 methods : {
1011 modal : ( args : AppModal ) => void
1112 alert : ( args : AlertModal ) => void
1213 toast : ( message : string ) => void
14+ hideToaster : ( id : number ) => void
1315 }
1416}
1517
1618const profile : LibraryProfile < INotificationApi > = {
1719 name : 'notification' ,
1820 displayName : 'Notification' ,
1921 description : 'Displays notifications' ,
20- methods : [ 'modal' , 'alert' , 'toast' ]
22+ methods : [ 'modal' , 'alert' , 'toast' , 'hideToaster' ]
2123}
2224
2325export class NotificationPlugin extends Plugin implements MethodApi < INotificationApi > {
2426 dispatcher : dispatchModalInterface
27+ toastId : number
2528 constructor ( ) {
2629 super ( profile )
30+ this . toastId = 0
2731 }
2832
2933 setDispatcher ( dispatcher : dispatchModalInterface ) {
@@ -38,7 +42,12 @@ export class NotificationPlugin extends Plugin implements MethodApi<INotificatio
3842 return this . dispatcher . alert ( args )
3943 }
4044
41- async toast ( message : string | JSX . Element ) {
42- this . dispatcher . toast ( message )
45+ async toast ( message : string | JSX . Element , timeout ?: number ) {
46+ this . toastId ++
47+ return this . dispatcher . toast ( message , timeout , this . toastId )
48+ }
49+
50+ async hideToaster ( id : number ) {
51+ toast . dismiss ( id )
4352 }
4453}
0 commit comments