mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-05 20:56:13 -05:00
28 lines
814 B
TypeScript
28 lines
814 B
TypeScript
import { Form, FormProps, useTransition } from "remix";
|
|
|
|
interface MyFormProps extends FormProps {
|
|
hiddenFields?: Record<string, string>;
|
|
}
|
|
|
|
/**
|
|
* Wrapper around Remix's Form that has default method of "post",
|
|
* creates <input type="hidden"> elements for each key/value pair in hiddenFields
|
|
* and disables the form when it's submitting.
|
|
*/
|
|
export function MyForm(props: MyFormProps) {
|
|
const { hiddenFields, children, ...rest } = props;
|
|
|
|
const transition = useTransition();
|
|
return (
|
|
<Form method="post" {...rest}>
|
|
<fieldset disabled={transition.state !== "idle"}>
|
|
{hiddenFields &&
|
|
Object.entries(hiddenFields).map(([key, value]) => (
|
|
<input key={key} type="hidden" name={key} value={value} />
|
|
))}
|
|
{children}
|
|
</fieldset>
|
|
</Form>
|
|
);
|
|
}
|