react-forminate
Version:
React.js + Typescript package that creates dynamic UI forms based on the JSON schema
97 lines (96 loc) • 2.35 kB
JavaScript
import { a as b, j as a } from "./index-BPZpMa2Y.js";
import { R as g, a as v, b as I, c as P } from "./FieldComponents-Fikvpz9O.js";
import C from "react";
const k = (n) => {
const {
eventHandlers: f,
processedProps: e,
fieldParams: r,
fieldValue: o,
isTouched: d,
hasDefaultStyling: c = !0,
fieldId: j,
errors: R
} = b(n), i = e?.layout || "inline", N = !!R[j], m = {
...r,
...f.htmlHandlers,
"data-touched": d
}, u = (s, S) => {
const t = typeof s == "string", l = t ? s : s.value, x = t ? s : s.label, y = t ? s : `${s.value}-${S}`, h = t ? {} : s;
return c ? /* @__PURE__ */ a.jsxs(
v,
{
style: e?.itemsStyles,
className: e?.itemsClassName,
children: [
/* @__PURE__ */ a.jsx(
I,
{
...m,
...h,
value: l,
checked: o === l
}
),
/* @__PURE__ */ a.jsx(P, { children: x })
]
},
y
) : /* @__PURE__ */ a.jsxs(
"label",
{
style: {
display: "flex",
alignItems: "center",
gap: "8px",
cursor: "pointer",
...e?.itemsStyles
},
className: e?.itemsClassName,
children: [
/* @__PURE__ */ a.jsx(
"input",
{
type: "radio",
...m,
...h,
value: l,
checked: o === l,
className: N ? "error" : ""
}
),
/* @__PURE__ */ a.jsx(
"span",
{
style: e.innerItemsStyles,
className: e.innerItemsClassName,
children: x
}
)
]
},
y
);
}, p = {
"data-testid": r["data-testid"],
"data-touched": d,
style: e?.containerStyles
};
return c ? /* @__PURE__ */ a.jsx(g, { layout: i, ...p, children: n.options?.map(u) }) : /* @__PURE__ */ a.jsx(
"div",
{
...p,
style: {
display: "flex",
flexDirection: i === "inline" ? "row" : "column",
gap: i === "inline" ? "24px" : "8px",
flexWrap: "wrap",
...e?.containerStyles
},
children: n.options?.map(u)
}
);
}, w = C.memo(k);
export {
w as default
};