Opens a dialog and returns a handle to it.
The element or component to render. If a component is provided, it will be provided with a dialog prop that contains the dialog handle.
The provided element or component is rendered as-is in the app's React tree. It is the caller's responsibility to provide all dialog chrome, such as an overlay, backdrop, and dialog surface. This makes the method agnostic to the design library used for the dialog.
const dialog = dialogApi.open<boolean>(
<Dialog isOpen onOpenChange={isOpen => !isOpen && dialog.close()}>
<DialogHeader>Are you sure?</DialogHeader>
<DialogBody>This action cannot be undone.</DialogBody>
<DialogFooter>
<Button onPress={() => dialog.close(false)}>Cancel</Button>
<Button onPress={() => dialog.close(true)}>Confirm</Button>
</DialogFooter>
</Dialog>
);
const result = await dialog.result();
function ConfirmDialog({ dialog }: { dialog: DialogApiDialog<boolean> }) {
return (
<Dialog isOpen onOpenChange={isOpen => !isOpen && dialog.close()}>
<DialogHeader>Are you sure?</DialogHeader>
<DialogBody>This action cannot be undone.</DialogBody>
<DialogFooter>
<Button onPress={() => dialog.close(false)}>Cancel</Button>
<Button onPress={() => dialog.close(true)}>Confirm</Button>
</DialogFooter>
</Dialog>
);
}
const result = await dialogApi.open(ConfirmDialog).result();
A Utility API for showing dialogs that render in the React tree and return a result.