Files
yaak/src-web/lib/prompt.ts
Gregory Schier b4a1c418bb Run oxfmt across repo, add format script and docs
Add .oxfmtignore to skip generated bindings and wasm-pack output.
Add npm format script, update DEVELOPMENT.md for Vite+ toolchain,
and format all non-generated files with oxfmt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 10:15:49 -07:00

46 lines
1.1 KiB
TypeScript

import type { FormInput, PromptTextRequest } from "@yaakapp-internal/plugins";
import type { ReactNode } from "react";
import type { DialogProps } from "../components/core/Dialog";
import { showPromptForm } from "./prompt-form";
type PromptProps = Omit<PromptTextRequest, "id" | "title" | "description"> & {
description?: ReactNode;
onCancel: () => void;
onResult: (value: string | null) => void;
};
type PromptArgs = Pick<DialogProps, "title" | "description"> &
Omit<PromptProps, "onClose" | "onCancel" | "onResult"> & { id: string };
export async function showPrompt({
id,
title,
description,
cancelText,
confirmText,
required,
...props
}: PromptArgs) {
const inputs: FormInput[] = [
{
...props,
optional: !required,
type: "text",
name: "value",
},
];
const result = await showPromptForm({
id,
title,
description,
inputs,
cancelText,
confirmText,
});
if (result == null) return null; // Cancelled
if (typeof result.value === "string") return result.value;
return props.defaultValue ?? "";
}