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