(themeProps: ThemeProviderProps, options: ConfirmOptions)
| 151 | let hostElement: Element | null = null |
| 152 | export type ConfirmOptions = Omit<ConfirmationDialogProps, 'onClose'> & {content: React.ReactNode} |
| 153 | async function confirm(themeProps: ThemeProviderProps, options: ConfirmOptions): Promise<boolean> { |
| 154 | const {content, ...confirmationDialogProps} = options |
| 155 | return new Promise(resolve => { |
| 156 | hostElement ||= document.createElement('div') |
| 157 | if (!hostElement.isConnected) document.body.append(hostElement) |
| 158 | const root = createRoot(hostElement) |
| 159 | const onClose: ConfirmationDialogProps['onClose'] = gesture => { |
| 160 | root.unmount() |
| 161 | if (gesture === 'confirm') { |
| 162 | resolve(true) |
| 163 | } else { |
| 164 | resolve(false) |
| 165 | } |
| 166 | } |
| 167 | root.render( |
| 168 | <ThemeProvider {...themeProps}> |
| 169 | <BaseStyles> |
| 170 | <ConfirmationDialog {...confirmationDialogProps} onClose={onClose}> |
| 171 | {content} |
| 172 | </ConfirmationDialog> |
| 173 | </BaseStyles> |
| 174 | </ThemeProvider>, |
| 175 | ) |
| 176 | }) |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * This hook takes no parameters and returns an `async` function, `confirm`. When `confirm` |
no outgoing calls