UNPKG

scrivito-pisasales-questionnaire-builder

Version:
129 lines (128 loc) 3.93 kB
import { jsxs as I, jsx as t } from "react/jsx-runtime"; import { T as S, a as R, L as U, M as O, E as H, Q, c as G, H as P, D as X, A as j, V as Y, d as B } from "./scrivitoConfig-WST4rsmc.js"; import { u as W, Q as z } from "./FormContext-CyyAThXO.js"; import { u as _, a as $, M as V, H as F, b as J } from "./useValidationField-BrRv6UCn.js"; import { useState as y, useEffect as D } from "react"; import { ContentTag as M } from "scrivito"; const A = "true", K = "false", Z = ({ required: e, externalId: c, questionId: r, identifier: i, help: h, widget: s, defaultValue: u, alignment: n, validationText: m }) => { const o = `form_checkbox_widget_${s.id()}`, { values: a, handleChange: N } = _(r, [u], [i]), [L, T] = y(a[0] === A), { isLocallyValid: g, setIsLocallyValid: x, ref: E } = $(c, e), l = !g; D(() => { T(a[0] === A); }, [a]); const C = (f) => { const v = f.target.checked ? A : K; T(f.target.checked), e && x(f.target.checked), N([v]); }; return /* @__PURE__ */ I("div", { ref: E, className: `mb-3 checkbox-container ${n}`, children: [ /* @__PURE__ */ t( "input", { className: `form-check-input ${l ? "is-invalid" : ""}`, id: o, type: "checkbox", name: c, checked: L, onChange: C } ), /* @__PURE__ */ I("label", { className: "form-check-label", htmlFor: o, children: [ /* @__PURE__ */ t(M, { content: s, attribute: S, tag: "p" }), e && /* @__PURE__ */ t(V, {}), h && /* @__PURE__ */ t(F, { widget: s }) ] }), l && /* @__PURE__ */ t("div", { className: `invalid-feedback ${n}`, children: m }) ] }); }, b = "true", p = "false", d = "unset", q = ({ required: e, externalId: c, questionId: r, identifier: i, help: h, widget: s, defaultValue: u, alignment: n, validationText: m }) => { const o = `form_checkbox_widget_${c}`, { values: a, handleChange: N } = _(r, [u], [i]), { isLocallyValid: L, setIsLocallyValid: T, ref: g } = $(c, e), x = !L, E = () => a[0] === b ? b : a[0] === p ? p : d, [l, C] = y(E()); D(() => { C(E()); }, [a]); const f = (k) => { switch (k) { case d: return b; case b: return p; case p: return d; default: return d; } }, v = () => { const k = f(l); C(k), e && T(k != d), N([k]); }; return /* @__PURE__ */ I("div", { ref: g, className: `mb-3 checkbox-container ${n}`, children: [ /* @__PURE__ */ t( "input", { className: `form-check-input ${l === d ? "unset" : ""} ${x ? "is-invalid" : ""}`, id: o, type: "checkbox", "data-tristate": l, name: c, checked: l === b, onChange: v } ), /* @__PURE__ */ I("label", { className: "form-check-label", htmlFor: o, children: [ /* @__PURE__ */ t(M, { attribute: S, content: s, tag: "p" }), e && /* @__PURE__ */ t(V, {}), h && /* @__PURE__ */ t(F, { widget: s }) ] }), x && /* @__PURE__ */ t("div", { className: `invalid-feedback ${n}`, children: m }) ] }); }, ne = ({ widget: e }) => { const c = e.get(R) || U, r = e.get(O), i = e.get(H), h = e.get(Q), s = e.get(G), u = e.get(P), n = e.get(X), m = e.get(j) || "left", o = e.get(Y) || "Please tick the box", a = W(); return J(e), a ? c === B ? /* @__PURE__ */ t( q, { required: r, externalId: i, questionId: h, identifier: s, help: u, widget: e, defaultValue: n, alignment: m, validationText: o } ) : /* @__PURE__ */ t( Z, { required: r, externalId: i, questionId: h, identifier: s, help: u, widget: e, defaultValue: n, alignment: m, validationText: o } ) : /* @__PURE__ */ t(z, { status: "noFormContext" }); }; export { ne as default }; //# sourceMappingURL=CheckboxWidgetContent-4rke0IKm.js.map