import _ from "lodash"; import { DetailedHTMLProps, FormHTMLAttributes } from "react"; import { twMerge } from "tailwind-merge"; /** * # Form Element * @className twui-form */ export default function Form({ ...props }: DetailedHTMLProps, HTMLFormElement> & { submitHandler?: (e: React.FormEvent, data: T) => void; }) { const finalProps = _.omit(props, "submitHandler"); return (
{ e.preventDefault(); const formEl = e.target as HTMLFormElement; const formData = new FormData(formEl); const data = Object.fromEntries(formData.entries()) as T; props.submitHandler?.(e, data); }} > {props.children}
); }