mirror of
https://github.com/run-llama/ai-chatbot.git
synced 2026-07-01 21:14:02 -04:00
39 lines
814 B
TypeScript
39 lines
814 B
TypeScript
'use client';
|
|
|
|
import { useFormStatus } from 'react-dom';
|
|
|
|
import { LoaderIcon } from '@/components/icons';
|
|
|
|
import { Button } from './ui/button';
|
|
|
|
export function SubmitButton({
|
|
children,
|
|
isSuccessful,
|
|
}: {
|
|
children: React.ReactNode;
|
|
isSuccessful: boolean;
|
|
}) {
|
|
const { pending } = useFormStatus();
|
|
|
|
return (
|
|
<Button
|
|
type={pending ? 'button' : 'submit'}
|
|
aria-disabled={pending || isSuccessful}
|
|
disabled={pending || isSuccessful}
|
|
className="relative"
|
|
>
|
|
{children}
|
|
|
|
{(pending || isSuccessful) && (
|
|
<span className="animate-spin absolute right-4">
|
|
<LoaderIcon />
|
|
</span>
|
|
)}
|
|
|
|
<output aria-live="polite" className="sr-only">
|
|
{pending || isSuccessful ? 'Loading' : 'Submit form'}
|
|
</output>
|
|
</Button>
|
|
);
|
|
}
|