Refactor to use hooks (#436)
This commit is contained in:
parent
124efca9a1
commit
cb60f8b143
139 changed files with 8871 additions and 8726 deletions
29
components/custom/submit-button.tsx
Normal file
29
components/custom/submit-button.tsx
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"use client";
|
||||
|
||||
import { useFormStatus } from "react-dom";
|
||||
|
||||
import { LoaderIcon } from "@/components/custom/icons";
|
||||
|
||||
import { Button } from "../ui/button";
|
||||
|
||||
export function SubmitButton({ children }: { children: React.ReactNode }) {
|
||||
const { pending } = useFormStatus();
|
||||
|
||||
return (
|
||||
<Button
|
||||
type={pending ? "button" : "submit"}
|
||||
aria-disabled={pending}
|
||||
className="relative"
|
||||
>
|
||||
{children}
|
||||
{pending && (
|
||||
<span className="animate-spin absolute right-4">
|
||||
<LoaderIcon />
|
||||
</span>
|
||||
)}
|
||||
<span aria-live="polite" className="sr-only" role="status">
|
||||
{pending ? "Loading" : "Submit form"}
|
||||
</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue