UNPKG

libmodulor

Version:

A TypeScript library to create platform-agnostic applications

19 lines (18 loc) 1.04 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useRef } from 'react'; import { UCExecRes } from '../../uc/index.js'; import { useStyleContext } from '../lib/react/StyleContextProvider.js'; import { UCFormField } from './UCFormField.js'; import { UCFormSubmitControl } from './UCFormSubmitControl.js'; export function UCForm({ clearAfterExec, disabled, execState, onSubmit: onSubmitBase, uc, }) { const { form } = useStyleContext(); const formRef = useRef(null); const onSubmit = async (e) => { e.preventDefault(); const res = await onSubmitBase(); if (res === UCExecRes.SUCCEEDED && clearAfterExec) { formRef.current?.reset(); } }; return (_jsxs("form", { className: form?.className, onSubmit: onSubmit, ref: formRef, style: form?.style, children: [uc.inputFieldsForForm().map((f) => (_jsx(UCFormField, { disabled: disabled, execState: execState, f: f }, f.key))), _jsx(UCFormSubmitControl, { disabled: disabled, execState: execState, uc: uc })] })); }