aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/submit-button.tsx
diff options
context:
space:
mode:
authorSebastien Castiel <sebastien@castiel.me>2023-12-06 12:22:24 -0500
committerSebastien Castiel <sebastien@castiel.me>2023-12-06 12:22:24 -0500
commit6c4ced0f79f801d85da5e4973ae4154f01b04dba (patch)
treedbb8eab58ef6d3e8cec6f3c7187e2a4596134d4a /src/components/submit-button.tsx
parented55c696cd083bfaa5429082a9c5edd4ebde0cd8 (diff)
Loading screens & layouts
Diffstat (limited to 'src/components/submit-button.tsx')
-rw-r--r--src/components/submit-button.tsx23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/components/submit-button.tsx b/src/components/submit-button.tsx
new file mode 100644
index 0000000..7489c6c
--- /dev/null
+++ b/src/components/submit-button.tsx
@@ -0,0 +1,23 @@
+import { Button } from '@/components/ui/button'
+import { Loader2 } from 'lucide-react'
+import { PropsWithChildren, ReactNode } from 'react'
+import { useFormState } from 'react-hook-form'
+
+type Props = PropsWithChildren<{
+ loadingContent: ReactNode
+}>
+
+export function SubmitButton({ children, loadingContent }: Props) {
+ const { isSubmitting } = useFormState()
+ return (
+ <Button type="submit" disabled={isSubmitting}>
+ {isSubmitting ? (
+ <>
+ <Loader2 className="w-4 h-4 mr-2 animate-spin" /> {loadingContent}
+ </>
+ ) : (
+ children
+ )}
+ </Button>
+ )
+}