mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-25 10:51:26 +01:00
Make prompt() to return null on cancel
This commit is contained in:
@@ -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,
|
||||
}),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user