mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-16 22:16:49 +01:00
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import type { DialogProps } from '../components/core/Dialog';
|
|
import type { PromptProps } from './Prompt';
|
|
import { Prompt } from './Prompt';
|
|
import {useDialog} from "./useDialog";
|
|
|
|
type Props = Pick<DialogProps, 'title' | 'description'> &
|
|
Omit<PromptProps, 'onClose' | 'onCancel' | 'onResult'> & { id: string };
|
|
|
|
export function usePrompt() {
|
|
const dialog = useDialog();
|
|
return ({ id, title, description, ...props }: Props) =>
|
|
new Promise((resolve: PromptProps['onResult']) => {
|
|
dialog.show({
|
|
id,
|
|
title,
|
|
description,
|
|
hideX: true,
|
|
size: 'sm',
|
|
onClose: () => {
|
|
// Click backdrop, close, or escape
|
|
resolve(null);
|
|
},
|
|
render: ({ hide }) =>
|
|
Prompt({
|
|
onCancel: () => {
|
|
// Click cancel button within dialog
|
|
resolve(null);
|
|
hide();
|
|
},
|
|
onResult: (v) => {
|
|
resolve(v);
|
|
hide();
|
|
},
|
|
...props,
|
|
}),
|
|
});
|
|
});
|
|
}
|