diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 82c6827..ecc324c 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { PlusCircleIcon } from '@heroicons/react/24/outline'; import '../styles/globals.css'; import { Colors } from '../styles/styles'; @@ -16,6 +16,7 @@ type ButtonProps = { className?: string; variant?: 'submit' | 'white' | 'light' | 'icon' | 'gray'; textColor?: string; + type?: 'submit' | 'reset' | 'button' | undefined; }; const Button: React.FC = ({ @@ -31,7 +32,26 @@ const Button: React.FC = ({ className = '', variant = 'submit', textColor = 'white', + type = undefined, }) => { + const [internalDisabled, setInternalDisabled] = useState(false); + + const handleClick = () => { + if (disabled || internalDisabled) return; + + setInternalDisabled(true); + + const result = onClick?.(); + + if (result && typeof result === 'object' && 'then' in result) { + (result as Promise).finally(() => setInternalDisabled(false)); + } else { + setInternalDisabled(false); + } + }; + + const isDisabled = disabled || internalDisabled; + const baseStyles = `font-medium transition duration-200 rounded-md shadow-sm border-transparent px-${paddingX} py-${paddingY} text-${textSize}`; const variantStyles = @@ -47,10 +67,11 @@ const Button: React.FC = ({ return (