-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathsubmit-button.tsx
42 lines (39 loc) · 1.1 KB
/
submit-button.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
'use client';
import { useFormStatus } from 'react-dom';
export function SubmitButton({ children }: { children: React.ReactNode }) {
const { pending } = useFormStatus();
return (
<button
type={pending ? 'button' : 'submit'}
aria-disabled={pending}
className="flex h-10 w-full items-center justify-center rounded-md border text-sm transition-all focus:outline-none"
>
{children}
{pending && (
<svg
className="animate-spin ml-2 h-4 w-4 text-black"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
/>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
/>
</svg>
)}
<span aria-live="polite" className="sr-only" role="status">
{pending ? 'Loading' : 'Submit form'}
</span>
</button>
);
}