-
Notifications
You must be signed in to change notification settings - Fork 597
Expand file tree
/
Copy pathprompt-form.js
More file actions
46 lines (40 loc) · 1.13 KB
/
prompt-form.js
File metadata and controls
46 lines (40 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { useEffect, useState } from "react";
export default function PromptForm({
initialPrompt,
onSubmit,
scribbleExists,
}) {
const [prompt, setPrompt] = useState(initialPrompt);
const disabled = !(scribbleExists && prompt?.length > 0);
useEffect(() => {
setPrompt(initialPrompt);
}, [initialPrompt]);
const handleSubmit = (e) => {
e.preventDefault();
onSubmit(e);
};
return (
<form onSubmit={handleSubmit} className="animate-in fade-in duration-700">
<div className="flex mt-4">
<input
id="prompt-input"
type="text"
name="prompt"
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
placeholder="Describe the image you want to create..."
className="block w-full flex-grow rounded-l-md"
/>
<button
className={`bg-black text-white rounded-r-md text-small inline-block px-5 py-3 flex-none ${
disabled ? "opacity-20 cursor-not-allowed " : ""
}`}
type="submit"
disabled={disabled}
>
Go
</button>
</div>
</form>
);
}