mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-30 03:36:37 +08:00
18 lines
529 B
TypeScript
18 lines
529 B
TypeScript
import { createRoot } from 'react-dom/client'
|
|
|
|
import { ConfirmDialog, type ConfirmOptions } from './ConfirmDialog'
|
|
|
|
export function confirmAction(options: ConfirmOptions): Promise<boolean> {
|
|
return new Promise((resolve) => {
|
|
const host = document.createElement('div')
|
|
document.body.appendChild(host)
|
|
const root = createRoot(host)
|
|
const close = (value: boolean) => {
|
|
root.unmount()
|
|
host.remove()
|
|
resolve(value)
|
|
}
|
|
root.render(<ConfirmDialog options={options} onClose={close} />)
|
|
})
|
|
}
|