-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformComponent.tsx
75 lines (72 loc) · 2.27 KB
/
formComponent.tsx
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Spinner } from "@/components/ui/spinner";
import { Switch } from "@/components/ui/switch";
import { cn } from "@/lib/utils";
import { CornerDownLeft } from "lucide-react";
interface FormComponentProps {
isLoading: boolean;
message: string | null;
setMessage: React.Dispatch<React.SetStateAction<string | null>>;
submitForm: (
e: React.FormEvent<HTMLFormElement>,
message: string | null
) => void;
setIsEmojiSupport: React.Dispatch<React.SetStateAction<boolean>>;
}
const FormComponent: React.FC<FormComponentProps> = ({
isLoading,
message,
setMessage,
submitForm,
setIsEmojiSupport,
}) => {
return (
<form
onSubmit={(e) => submitForm(e, message)}
className="relative overflow-hidden rounded-lg border bg-primary-foreground/25 focus-within:ring-1 focus-within:ring-ring shadow"
>
<Label htmlFor="message" className="sr-only">
Message
</Label>
<Input
id="message"
placeholder="Describe your changes here..."
className="min-h-12 resize-none border-0 p-3 shadow-none focus-visible:ring-0"
onChange={(e) => setMessage(e.target.value)}
value={message || ""}
disabled={isLoading}
autoComplete="off"
autoFocus
required
/>
<div className="flex items-center p-3 pt-0">
<div className="flex items-center space-x-2">
<Switch
onCheckedChange={(e) => setIsEmojiSupport(e)}
id="emoji-mode"
name="emoji-mode"
aria-label="Emoji Mode"
/>
<Label htmlFor="emoji-mode">Emoji Mode</Label>
</div>
<Button
type="submit"
size="sm"
className={cn("ml-auto gap-1.5", {
"bg-primary-foreground text-muted-foreground border cursor-not-allowed hover:bg-primary-foreground":
!message || isLoading,
})}
disabled={isLoading}
>
{isLoading && <Spinner className="size-4" />}
Generate
<CornerDownLeft className="size-3.5" />
</Button>
</div>
</form>
);
};
export default FormComponent;