UNPKG

@mitcsutt/kiln-forms

Version:

Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui

41 lines (40 loc) • 1.38 kB
import { formContext as e } from "../../../kit/contexts.js"; import { FieldPresentation as t } from "../../fields/FieldPresentation/FieldPresentation.js"; import { getFormRuntime as n, toFormApi as r } from "../../../runtime/formRuntime.js"; import { resetForm as i } from "../../../runtime/baseline.js"; import { forwardRef as a, useCallback as o } from "react"; import { useSelector as s } from "@tanstack/react-form"; import { jsx as c } from "react/jsx-runtime"; //#region src/components/form/Form/Form.tsx var l = a(function({ form: a, mode: l, viewLines: u, disabled: d, readOnly: f, children: p, ...m }, h) { let g = r(a), _ = n(g), v = s(g.store, (e) => e.isSubmitting), y = o((e) => { _.formElement = e, typeof h == "function" ? h(e) : h && (h.current = e); }, [_, h]); return /* @__PURE__ */ c("form", { ref: y, noValidate: !0, "aria-busy": v || void 0, onSubmit: (e) => { e.preventDefault(), e.stopPropagation(), !(g.state.isSubmitting || _.locked) && g.handleSubmit().catch((e) => { console.error(e); }); }, onReset: (e) => { e.preventDefault(), i(a, "baseline"); }, ...m, children: /* @__PURE__ */ c(e.Provider, { value: g, children: /* @__PURE__ */ c(t, { mode: l, viewLines: u, disabled: d, readOnly: f, children: p }) }) }); }); //#endregion export { l as Form }; //# sourceMappingURL=Form.js.map