mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 16:21:25 +02:00
A bunch of changes, including moving prompt/confirm out of context
This commit is contained in:
57
src-web/components/core/Prompt.tsx
Normal file
57
src-web/components/core/Prompt.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { PromptTextRequest } from '@yaakapp-internal/plugins';
|
||||
import type { FormEvent, ReactNode } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import {PlainInput} from "./PlainInput";
|
||||
import { HStack } from './Stacks';
|
||||
import { Button } from './Button';
|
||||
|
||||
export type PromptProps = Omit<PromptTextRequest, 'id' | 'title' | 'description'> & {
|
||||
description?: ReactNode;
|
||||
onCancel: () => void;
|
||||
onResult: (value: string | null) => void;
|
||||
};
|
||||
|
||||
export function Prompt({
|
||||
onCancel,
|
||||
label,
|
||||
defaultValue,
|
||||
placeholder,
|
||||
onResult,
|
||||
require,
|
||||
confirmText,
|
||||
cancelText,
|
||||
}: PromptProps) {
|
||||
const [value, setValue] = useState<string>(defaultValue ?? '');
|
||||
const handleSubmit = useCallback(
|
||||
(e: FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
onResult(value);
|
||||
},
|
||||
[onResult, value],
|
||||
);
|
||||
|
||||
return (
|
||||
<form
|
||||
className="grid grid-rows-[auto_auto] grid-cols-[minmax(0,1fr)] gap-4 mb-4"
|
||||
onSubmit={handleSubmit}
|
||||
>
|
||||
<PlainInput
|
||||
hideLabel
|
||||
autoSelect
|
||||
require={require}
|
||||
placeholder={placeholder ?? 'Enter text'}
|
||||
label={label}
|
||||
defaultValue={defaultValue}
|
||||
onChange={setValue}
|
||||
/>
|
||||
<HStack space={2} justifyContent="end">
|
||||
<Button onClick={onCancel} variant="border" color="secondary">
|
||||
{cancelText || 'Cancel'}
|
||||
</Button>
|
||||
<Button type="submit" color="primary">
|
||||
{confirmText || 'Done'}
|
||||
</Button>
|
||||
</HStack>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user