Make prompt() to return null on cancel

This commit is contained in:
Gregory Schier
2024-10-02 05:54:44 -07:00
parent 89ff25cd54
commit 4160e5b1c4
26 changed files with 436 additions and 108 deletions

View File

@@ -4,19 +4,27 @@ import type { PromptProps } from './Prompt';
import { Prompt } from './Prompt';
type Props = Pick<DialogProps, 'title' | 'description'> &
Omit<PromptProps, 'onResult' | 'onHide'> & { id: string };
Omit<PromptProps, 'onClose' | 'onHide' | 'onResult'> & { id: string };
export function usePrompt() {
const dialog = useDialog();
return ({ id, title, description, ...props }: Props) =>
new Promise((onResult: PromptProps['onResult']) => {
new Promise((resolve: PromptProps['onResult']) => {
dialog.show({
id,
title,
description,
hideX: true,
size: 'sm',
render: ({ hide: onHide }) => Prompt({ onHide, onResult, ...props }),
render: ({ hide }) =>
Prompt({
onHide: () => {
hide();
resolve(null);
},
onResult: resolve,
...props,
}),
});
});
}