v3: code quality and visual consistency pass (refactored all forms across the app), fixed filename-related upload bug
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 47s
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 47s
This commit is contained in:
30
src/components/form/SubmitButton.tsx
Normal file
30
src/components/form/SubmitButton.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { useFormState } from "react-hook-form";
|
||||
|
||||
interface SubmitButtonProps {
|
||||
children: ReactNode;
|
||||
/** Replaces the label while the form is submitting (e.g. "Saving…"). */
|
||||
pendingLabel?: ReactNode;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit button that reflects react-hook-form's `isSubmitting` from the
|
||||
* surrounding `FormProvider`: it disables itself while submitting and swaps in
|
||||
* `pendingLabel`. Standardizes the hand-rolled "Save → Saving…" pattern.
|
||||
*/
|
||||
export function SubmitButton({
|
||||
children,
|
||||
pendingLabel,
|
||||
disabled,
|
||||
className = "btn-primary",
|
||||
}: SubmitButtonProps) {
|
||||
const { isSubmitting } = useFormState();
|
||||
|
||||
return (
|
||||
<button type="submit" className={className} disabled={isSubmitting || disabled}>
|
||||
{isSubmitting && pendingLabel != null ? pendingLabel : children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user