@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
70 lines (69 loc) • 1.97 kB
JavaScript
import { jsxs as d, Fragment as x, jsx as i } from "react/jsx-runtime";
import { clsx as T } from "clsx";
import { useFormikContext as $, Field as b } from "formik";
import { useContext as w, useState as D } from "react";
import { RenderContext as H } from "../../context.js";
import N from "../../utils/charcount.js";
import { useValidationErrors as P, ErrorList as R } from "../../utils/errors.js";
import S from "./component.js";
import V from "./description.js";
import { withMultiple as q } from "./multiple.js";
const z = ({
name: t,
label: p,
required: h = !1,
tooltip: F = "",
description: f = "",
showCharCount: C = !1,
onChange: o,
childrenAfterField: v,
onFocus: s,
onBlur: l,
...e
}) => {
const {
getFieldProps: g,
getFieldMeta: k
} = $(), {
value: m,
onChange: E,
onBlur: L
} = g(t), {
touched: M
} = k(t), {
errors: j,
hasErrors: y
} = P(t), {
bareInput: I
} = w(H), [O, a] = D(!1), n = `editform-${t}`;
m === void 0 && e.value === void 0 && (e = {
...e,
value: ""
});
const c = /* @__PURE__ */ d(x, { children: [
/* @__PURE__ */ i(b, { name: t, id: n, as: "input", type: "text", className: T("form-control", {
"is-invalid": y
}), "data-testid": `input-${t}`, onChange: (r) => {
E(r), o == null || o(r);
}, onFocus: (r) => {
a(!0), s == null || s(r);
}, onBlur: (r) => {
L(r), a(!1), l == null || l(r);
}, ...e }),
v
] }), u = C && (M || O) && m && /* @__PURE__ */ i(N, { value: m, maxLength: e.maxLength });
return I ? /* @__PURE__ */ d(x, { children: [
c,
u,
/* @__PURE__ */ i(R, { errors: j })
] }) : /* @__PURE__ */ d(S, { type: "textfield", field: t, required: h, htmlId: n, label: p, tooltip: F, children: [
/* @__PURE__ */ i("div", { children: c }),
u,
f && /* @__PURE__ */ i(V, { text: f })
] });
}, _ = q(z, "");
export {
z as TextField,
_ as TextFieldMultiple,
_ as default
};