chatbot-template/components/chat/submit-button.tsx

39 lines
820 B
TypeScript
Raw Normal View History

"use client";
2024-10-11 18:00:22 +05:30
import { useFormStatus } from "react-dom";
2024-10-11 18:00:22 +05:30
import { LoaderIcon } from "@/components/chat/icons";
2024-10-11 18:00:22 +05:30
import { Button } from "../ui/button";
2024-10-11 18:00:22 +05:30
2024-11-08 17:59:06 +03:00
export function SubmitButton({
children,
isSuccessful,
}: {
children: React.ReactNode;
isSuccessful: boolean;
}) {
2024-10-11 18:00:22 +05:30
const { pending } = useFormStatus();
return (
<Button
2024-11-08 17:59:06 +03:00
aria-disabled={pending || isSuccessful}
className="relative"
disabled={pending || isSuccessful}
type={pending ? "button" : "submit"}
2024-10-11 18:00:22 +05:30
>
{children}
2024-11-08 17:59:06 +03:00
{(pending || isSuccessful) && (
2025-09-09 15:44:07 -04:00
<span className="absolute right-4 animate-spin">
2024-10-11 18:00:22 +05:30
<LoaderIcon />
</span>
)}
2024-11-08 17:59:06 +03:00
2024-11-15 12:18:17 -05:00
<output aria-live="polite" className="sr-only">
{pending || isSuccessful ? "Loading" : "Submit form"}
2024-11-15 12:18:17 -05:00
</output>
2024-10-11 18:00:22 +05:30
</Button>
);
}