@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
68 lines (67 loc) • 2.04 kB
JavaScript
import { jsx as o, jsxs as a, Fragment as w } from "react/jsx-runtime";
import M from "clsx";
import { useFormikContext as T, Field as j } from "formik";
import { useRef as k, useContext as A, useLayoutEffect as I } from "react";
import { RenderContext as L } from "../../context.js";
import S from "../../utils/charcount.js";
import { useValidationErrors as W, ErrorList as B } from "../../utils/errors.js";
import D from "./component.js";
import H from "./description.js";
import { withMultiple as N } from "./multiple.js";
const O = ({
name: e,
label: p,
required: h = !1,
tooltip: x = "",
description: n = "",
showCharCount: v = !1,
autoExpand: c = !1,
onChange: l,
...r
}) => {
const {
getFieldProps: y,
getFieldMeta: C
} = T(), {
value: i,
onChange: F
} = y(e), {
touched: g
} = C(e), {
errors: $,
hasErrors: E
} = W(e), s = k(null), {
bareInput: R
} = A(L);
I(() => {
const t = s.current;
if (c && t) {
const f = window.getComputedStyle(t);
t.style.height = "inherit", t.style.height = `calc(${t.scrollHeight}px + ${f.borderTopWidth} + ${f.borderBottomWidth})`;
}
}, [c, s, i]);
const d = `editform-${e}`;
i === void 0 && r.value === void 0 && (r = {
...r,
value: ""
});
const m = /* @__PURE__ */ o(j, { innerRef: s, name: e, id: d, as: "textarea", type: "textarea", className: M("form-control", {
"is-invalid": E
}), "data-testid": `input-${e}`, onChange: (t) => {
F(t), l == null || l(t);
}, ...r }), b = s.current === document.activeElement, u = v && (g || b) && i && /* @__PURE__ */ o(S, { value: i });
return R ? /* @__PURE__ */ a(w, { children: [
m,
u,
/* @__PURE__ */ o(B, { errors: $ })
] }) : /* @__PURE__ */ a(D, { type: "textarea", field: e, required: h, htmlId: d, label: p, tooltip: x, children: [
/* @__PURE__ */ o("div", { children: m }),
u,
n && /* @__PURE__ */ o(H, { text: n })
] });
}, Y = N(O, "");
export {
O as TextArea,
Y as TextAreaMultiple,
Y as default
};