aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/submit-button.tsx
blob: c5215c5ab3b8a3bdbda595131ebac91d3f5bd599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Button, ButtonProps } from '@/components/ui/button'
import { Loader2 } from 'lucide-react'
import { ReactNode } from 'react'
import { useFormState } from 'react-hook-form'

type Props = {
  loadingContent: ReactNode
} & ButtonProps

export function SubmitButton({ children, loadingContent, ...props }: Props) {
  const { isSubmitting } = useFormState()
  return (
    <Button type="submit" disabled={isSubmitting} {...props}>
      {isSubmitting ? (
        <>
          <Loader2 className="w-4 h-4 mr-2 animate-spin" /> {loadingContent}
        </>
      ) : (
        children
      )}
    </Button>
  )
}