tasko/components/form/form-submit.tsx

42 lines
724 B
TypeScript
Raw Normal View History

2024-02-16 01:49:19 +00:00
'Use client';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import { useFormStatus } from 'react-dom';
2024-02-15 02:30:10 +00:00
2024-02-16 01:49:19 +00:00
import { cn } from '@/lib/utils';
import { Button } from '@/components/ui/button';
2024-02-15 02:30:10 +00:00
interface FormSubmitProps {
children: React.ReactNode;
disabled?: boolean;
className?: string;
variant?:
2024-02-16 01:49:19 +00:00
| 'default'
| 'destructive'
| 'outline'
| 'secondary'
| 'ghost'
| 'link'
| 'primary';
2024-02-15 02:30:10 +00:00
}
export const FormSubmit = ({
children,
disabled,
className,
2024-02-16 01:49:19 +00:00
variant = 'primary',
2024-02-15 02:30:10 +00:00
}: FormSubmitProps) => {
const { pending } = useFormStatus();
return (
<Button
disabled={pending || disabled}
2024-02-16 01:49:19 +00:00
type='submit'
2024-02-15 02:30:10 +00:00
variant={variant}
2024-02-16 01:49:19 +00:00
size='sm'
2024-02-15 02:30:10 +00:00
className={cn(className)}
>
{children}
</Button>
);
};