import React from 'react' import * as AlertDialog from '@radix-ui/react-alert-dialog' import NiceModal, { useModal } from '@ebay/nice-modal-react' import { debounce } from 'lodash-es' import classes from './styles.module.css' const { AlertDialogOverlay, AlertDialogContent, AlertDialogTitle, 'lds-roller': LdsRoller, } = classes function CSSLoading() { return (
) } const Loading = NiceModal.create<{ title: string }>( ({ title }: { title: string }) => { const modal = useLoading() return ( {title} ) } ) export function useLoading() { return useModal(Loading) } declare type NiceModalArgs = T extends | keyof JSX.IntrinsicElements | React.JSXElementConstructor ? Omit, 'id'> : Record export type ShowProps = NiceModalArgs export function GetLoading(wait = 0) { const show = debounce((props: ShowProps) => { NiceModal.show(Loading, props) }, wait) return { show: (props: ShowProps) => { show(props) }, hide: () => { show.cancel() HideLoading() }, } } export function ShowLoading(props: ShowProps) { NiceModal.show(Loading, props) } export function HideLoading() { NiceModal.hide(Loading) }