mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-17 14:29:46 +02:00
Move a bunch of git ops to use the git binary (#302)
This commit is contained in:
@@ -1,28 +1,27 @@
|
||||
import type { PromptTextRequest } from '@yaakapp-internal/plugins';
|
||||
import type { FormEvent, ReactNode } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import type { FormInput, JsonPrimitive } from '@yaakapp-internal/plugins';
|
||||
import type { FormEvent } from 'react';
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
import { generateId } from '../../lib/generateId';
|
||||
import { DynamicForm } from '../DynamicForm';
|
||||
import { Button } from './Button';
|
||||
import { PlainInput } from './PlainInput';
|
||||
import { HStack } from './Stacks';
|
||||
|
||||
export type PromptProps = Omit<PromptTextRequest, 'id' | 'title' | 'description'> & {
|
||||
description?: ReactNode;
|
||||
export interface PromptProps {
|
||||
inputs: FormInput[];
|
||||
onCancel: () => void;
|
||||
onResult: (value: string | null) => void;
|
||||
};
|
||||
onResult: (value: Record<string, JsonPrimitive> | null) => void;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
}
|
||||
|
||||
export function Prompt({
|
||||
onCancel,
|
||||
label,
|
||||
defaultValue,
|
||||
placeholder,
|
||||
password,
|
||||
inputs,
|
||||
onResult,
|
||||
required,
|
||||
confirmText,
|
||||
cancelText,
|
||||
confirmText = 'Confirm',
|
||||
cancelText = 'Cancel',
|
||||
}: PromptProps) {
|
||||
const [value, setValue] = useState<string>(defaultValue ?? '');
|
||||
const [value, setValue] = useState<Record<string, JsonPrimitive>>({});
|
||||
const handleSubmit = useCallback(
|
||||
(e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
@@ -31,20 +30,14 @@ export function Prompt({
|
||||
[onResult, value],
|
||||
);
|
||||
|
||||
const id = 'prompt.form.' + useRef(generateId()).current;
|
||||
|
||||
return (
|
||||
<form
|
||||
className="grid grid-rows-[auto_auto] grid-cols-[minmax(0,1fr)] gap-4 mb-4"
|
||||
onSubmit={handleSubmit}
|
||||
>
|
||||
<PlainInput
|
||||
autoSelect
|
||||
required={required}
|
||||
placeholder={placeholder ?? 'Enter text'}
|
||||
type={password ? 'password' : 'text'}
|
||||
label={label}
|
||||
defaultValue={defaultValue}
|
||||
onChange={setValue}
|
||||
/>
|
||||
<DynamicForm inputs={inputs} onChange={setValue} data={value} stateKey={id} />
|
||||
<HStack space={2} justifyContent="end">
|
||||
<Button onClick={onCancel} variant="border" color="secondary">
|
||||
{cancelText || 'Cancel'}
|
||||
|
||||
Reference in New Issue
Block a user