2022-11-25 09:04:11 -08:00
|
|
|
import React from 'react';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
interface IForm {
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Form submission event handler. */
|
2022-03-21 11:09:01 -07:00
|
|
|
onSubmit?: (event: React.FormEvent) => void,
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Class name override for the <form> element. */
|
2022-04-19 15:11:24 -07:00
|
|
|
className?: string,
|
2023-01-10 15:03:15 -08:00
|
|
|
/** Elements to display within the Form. */
|
|
|
|
children: React.ReactNode,
|
2022-03-21 11:09:01 -07:00
|
|
|
}
|
|
|
|
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Form element with custom styles. */
|
2022-03-21 11:09:01 -07:00
|
|
|
const Form: React.FC<IForm> = ({ onSubmit, children, ...filteredProps }) => {
|
2023-01-10 15:03:15 -08:00
|
|
|
const handleSubmit: React.FormEventHandler = React.useCallback((event) => {
|
2022-03-21 11:09:01 -07:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (onSubmit) {
|
|
|
|
onSubmit(event);
|
|
|
|
}
|
|
|
|
}, [onSubmit]);
|
|
|
|
|
|
|
|
return (
|
2022-04-04 08:53:47 -07:00
|
|
|
<form data-testid='form' onSubmit={handleSubmit} className='space-y-4' {...filteredProps}>
|
2022-03-21 11:09:01 -07:00
|
|
|
{children}
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Form;
|