UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

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