UNPKG

@progress/kendo-react-form

Version:

React Form is a small and fast package for form state management with zero dependencies. KendoReact Form package

93 lines (92 loc) 2.64 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import * as e from "react"; import { useUnstyled as L, classNames as g, uForm as h } from "@progress/kendo-react-common"; import { FormContext as M } from "./FormContext.mjs"; import { innerWidth as O, calculateColumns as T, generateColumnClass as U, calculateGutters as W, generateGuttersStyling as E } from "./utils.mjs"; const m = { rows: "0px", cols: "32px" }, A = e.forwardRef((t, F) => { const y = { size: "medium", ...t }, s = e.useRef(null), v = e.useRef(null); e.useImperativeHandle(v, () => ({ element: s.current, props: y })), e.useImperativeHandle(F, () => v.current); const n = e.useContext(M), { className: w, style: H, horizontal: c, size: p, cols: r, gutters: o = m, ...N } = y, C = L(), d = C && C.uForm, [z, R] = e.useState(void 0), [x, f] = e.useState(void 0), S = e.useMemo(() => { if (c) return "horizontal"; if (c === !1) return "vertical"; }, [c]), G = e.useMemo( () => g( h.form({ c: d, size: p, orientation: S }), w ), [w, d, S, p] ); return e.useEffect(() => { if (!r && !o) { R(void 0); return; } if (!o) { f(void 0); return; } const b = () => { let a = 0; if (s.current ? a = O(s.current) : typeof window != "undefined" && (a = window.innerWidth), r) { const u = T(r, a); R(U(u)); } if (o) { const u = W(o, a); f(u ? { gap: E(u, m) } : { gap: E(m, m) }); } }; b(); let i; const l = s.current; return l && typeof window != "undefined" && "ResizeObserver" in window && (i = new ResizeObserver(b), i.observe(l)), () => { i && l && i.unobserve(l); }; }, [r, o]), /* @__PURE__ */ e.createElement( "form", { ref: s, ...N, id: t.id || (n ? n.id : void 0), style: t.style, className: G, onSubmit: n ? n.onSubmit : void 0 }, r ? /* @__PURE__ */ e.createElement( "div", { className: g( h.formLayout({ c: d }), z ), style: x }, t.children ) : t.children ); }); A.displayName = "KendoReactFormElement"; export { m as DEFAULT_FORM_GUTTERS, A as FormElement };