UNPKG

react-forminate

Version:

React.js + Typescript package that creates dynamic UI forms based on the JSON schema

42 lines (41 loc) 1.3 kB
import { a as S, j as l } from "./index-BPZpMa2Y.js"; import { S as v } from "./FieldComponents-Fikvpz9O.js"; import g, { useMemo as d } from "react"; const y = (m) => { const { eventHandlers: p, processedProps: s, fieldParams: u, fieldValue: f, fieldId: r, dynamicOptions: a, fieldErrors: h, hasDefaultStyling: x } = S(m), n = d(() => { const e = a?.[r] || s.options || []; return typeof e[0] == "string" ? e.map((t) => ({ label: t, value: t })) : e; }, [a?.[r], s.options]), o = { ...u, ...p.htmlHandlers, value: f, hasError: !!h, className: s.className // Pass through any className }, c = d( () => /* @__PURE__ */ l.jsxs(l.Fragment, { children: [ /* @__PURE__ */ l.jsx("option", { value: "", disabled: !0, children: s.placeholder || "Select an option" }), n.map((e, t) => { const i = typeof e == "string" ? e : e.value, j = typeof e == "string" ? e : e.label; return /* @__PURE__ */ l.jsx("option", { value: i, children: j }, `${i}-${t}`); }) ] }), [n, s.placeholder] ); return x ? /* @__PURE__ */ l.jsx(v, { ...o, children: c }) : /* @__PURE__ */ l.jsx("select", { ...o, className: s.className, children: c }); }, O = g.memo(y); export { O as default };