import React from 'react'
import * as Toast from '@radix-ui/react-toast'
import NiceModal, { useModal } from '@ebay/nice-modal-react'
import { debounce } from 'lodash-es'
import classes from './styles.module.css'
import classNames from 'classnames'
const {
ToastViewport,
ToastRoot,
ToastTitle,
ToastAction,
Button,
small,
green,
} = classes
const MyToast = NiceModal.create<{
title: string
button?: string
duration?: number
}>(({ title, button, duration = 3000 }) => {
const modal = useToast()
return (
{
if (open == false) {
modal.hide()
}
}}
>
{title}
{button ? (
) : undefined}
)
})
export function useToast() {
return useModal(MyToast)
}
declare type NiceModalArgs = T extends
| keyof JSX.IntrinsicElements
| React.JSXElementConstructor
? Omit, 'id'>
: Record
export type ShowProps = NiceModalArgs
export function GetToast(wait = 0) {
const show = debounce((props: ShowProps) => {
NiceModal.show(MyToast, props)
}, wait)
return {
show: (props: ShowProps) => {
show(props)
},
hide: () => {
show.cancel()
HideToast()
},
}
}
export async function ShowToast(props: ShowProps): Promise {
return await NiceModal.show(MyToast, props)
}
export function HideToast() {
return NiceModal.hide(MyToast)
}