bigbuffet-rw/app/soapbox/components/ui/form/form.tsx

28 lines
650 B
TypeScript
Raw Normal View History

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