soapbox/app/soapbox/components/ui/form/form.tsx

30 wiersze
741 B
TypeScript
Czysty Zwykły widok Historia

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