@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
63 lines (62 loc) • 2.4 kB
JavaScript
import { jsx as e, jsxs as o } from "react/jsx-runtime";
import { useFormikContext as y, FieldArray as N } from "formik";
import { FormattedMessage as p } from "react-intl";
import { RenderContext as v } from "../../context.js";
import M from "./component-label.js";
import C from "./description.js";
const P = (t) => {
const {
label: n,
description: r,
required: a,
tooltip: l
} = t, {
as: i,
defaultValue: s,
name: d,
...h
} = t, f = h, {
getFieldProps: b
} = y();
let {
value: c
} = b(d);
return Array.isArray(c) || (c = []), /* @__PURE__ */ o(v.Provider, { value: {
bareInput: !0
}, children: [
n && /* @__PURE__ */ e(M, { label: n, required: a, tooltip: l }),
/* @__PURE__ */ e(N, { name: d, children: (u) => /* @__PURE__ */ e("table", { className: "table table-bordered", children: /* @__PURE__ */ o("tbody", { children: [
(c || []).map((A, m) => /* @__PURE__ */ o("tr", { children: [
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(i, { name: `${d}[${m}]`, ...f }) }),
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ o("button", { className: "btn btn-secondary", type: "button", onClick: () => u.remove(m), children: [
/* @__PURE__ */ e("span", { className: "sr-only", children: /* @__PURE__ */ e(p, { id: "d5SKAT", defaultMessage: [{
type: 0,
value: "Remove item"
}] }) }),
/* @__PURE__ */ e("i", { className: "fa fa-times-circle-o", "aria-hidden": "true" })
] }) })
] }, m)),
/* @__PURE__ */ e("tr", { children: /* @__PURE__ */ e("td", { colSpan: 2, children: /* @__PURE__ */ o("button", { type: "button", className: "btn btn-primary formio-button-add-another", onClick: () => u.push(s), children: [
/* @__PURE__ */ e("i", { className: "fa fa-plus", "aria-hidden": "true" }),
/* @__PURE__ */ e(p, { id: "Fc/emc", defaultMessage: [{
type: 0,
value: "Add another"
}] })
] }) }) })
] }) }) }),
r && /* @__PURE__ */ e(C, { text: r })
] });
};
function w(t, n) {
const r = (a) => {
const {
multiple: l,
...i
} = a, s = i;
return l ? /* @__PURE__ */ e(P, { as: t, defaultValue: n, ...i }) : /* @__PURE__ */ e(t, { ...s });
};
return r.displayName = `withMultiple(${t.displayName ?? "Component"})`, r;
}
export {
w as withMultiple
};