UNPKG

@rws-aoa/react-library

Version:

RWS AOA Design System

171 lines (170 loc) 6.71 kB
import { jsx as n, jsxs as R } from "react/jsx-runtime"; import { c as G } from "./compiler-runtime.hDcrsMwn.js"; import { createFormHookContexts as U, createFormHook as V } from "@tanstack/react-form"; import { AoaNotification as j } from "../components/atoms/notification/Notification.js"; import { DialogTitle as X, DialogContent as Y, Dialog as Z, DialogActions as ee } from "@mui/material"; import { l as _ } from "./lodash.CA_K01A9.js"; import { AoaButton as z } from "../components/atoms/button/Button.js"; import { AoaModalCloseButton as te } from "../components/molecules/modal-close-button/ModalCloseButton.js"; function oe(l) { const e = G.c(5), { "data-qa": a } = l, s = K(); let i; e[0] !== a ? (i = (r) => { if (r.length) { const o = r.at(0); if (typeof o == "string") return /* @__PURE__ */ n(j, { "data-qa": a ?? "form-error", message: o, severity: "error" }); if (o && typeof o == "object") { const m = ["error", "info", "success", "warning"].includes(o.level) ? o.level : "error"; return /* @__PURE__ */ n(j, { "data-qa": a ?? "form-error", message: o.message, severity: m }); } } return null; }, e[0] = a, e[1] = i) : i = e[1]; let t; return e[2] !== s.Subscribe || e[3] !== i ? (t = /* @__PURE__ */ n(s.Subscribe, { selector: re, children: i }), e[2] = s.Subscribe, e[3] = i, e[4] = t) : t = e[4], t; } function re(l) { return l.errors; } function se(l) { const e = G.c(56), { formModalQas: a, formLabels: s, formName: i, DialogProps: t, DialogTitleProps: r, DialogContentProps: o, AoaSubmitButtonProps: m, modalQas: f, open: O, topic: T, dialogContent: k, closeAction: d } = l; let p; e[0] !== m ? (p = m === void 0 ? {} : m, e[0] = m, e[1] = p) : p = e[1]; let u, b; e[2] !== p ? ({ disableWithFormState: b, ...u } = p, e[2] = p, e[3] = u, e[4] = b) : (u = e[3], b = e[4]); const c = K(); let D; e[5] !== u || e[6] !== b || e[7] !== c.Subscribe || e[8] !== s.submit || e[9] !== a?.submitButton ? (D = b ? /* @__PURE__ */ n(c.Subscribe, { selector: ae, children: (P) => { const [I, J] = P; return /* @__PURE__ */ n(z, { ...u, "aria-disabled": I || !J, buttonType: "submit", "data-qa": a?.submitButton ?? "submit-form", disabled: I || !J, type: "primary", children: s.submit }); } }) : /* @__PURE__ */ n(z, { ...u, buttonType: "submit", "data-qa": a?.submitButton ?? "submit-form", type: "primary", children: s.submit }), e[5] = u, e[6] = b, e[7] = c.Subscribe, e[8] = s.submit, e[9] = a?.submitButton, e[10] = D) : D = e[10]; const E = D, Q = f?.modal ?? "modal", $ = !!O; let g; e[11] !== t?.sx ? (g = _.merge({ "> div > div": { borderRadius: 0 } }, t?.sx), e[11] = t?.sx, e[12] = g) : g = e[12]; const L = f?.title ?? "modal-title"; let x; e[13] !== r?.sx ? (x = _.merge({ padding: "3rem 3rem 1rem", color: "var(--color-rijks-logoblue)", fontSize: "1.1rem", fontWeight: "bolder" }, r?.sx), e[13] = r?.sx, e[14] = x) : x = e[14]; let h; e[15] !== r || e[16] !== L || e[17] !== x || e[18] !== T ? (h = /* @__PURE__ */ n(X, { ...r, "data-qa": L, maxWidth: "sm", sx: x, children: T }), e[15] = r, e[16] = L, e[17] = x, e[18] = T, e[19] = h) : h = e[19]; let A; e[20] !== d ? (A = /* @__PURE__ */ n(te, { closeAction: d }), e[20] = d, e[21] = A) : A = e[21]; const M = a?.form ?? "form"; let C; e[22] !== c ? (C = async (P) => { P.preventDefault(), P.stopPropagation(), await c.handleSubmit(); }, e[22] = c, e[23] = C) : C = e[23]; const W = f?.content ?? "modal-content"; let y; e[24] !== o?.sx ? (y = _.merge({ padding: "0 3rem 2rem" }, o?.sx), e[24] = o?.sx, e[25] = y) : y = e[25]; let S; e[26] !== o || e[27] !== k || e[28] !== W || e[29] !== y ? (S = /* @__PURE__ */ n(Y, { ...o, "data-qa": W, sx: y, children: k }), e[26] = o, e[27] = k, e[28] = W, e[29] = y, e[30] = S) : S = e[30]; const H = a?.dialogActions ?? "dialog-actions", N = a?.cancelButton ?? "cancel-form"; let v; e[31] !== d || e[32] !== c ? (v = () => { c.reset(), d(); }, e[31] = d, e[32] = c, e[33] = v) : v = e[33]; let F; e[34] !== s.cancel || e[35] !== N || e[36] !== v ? (F = /* @__PURE__ */ n(z, { "data-qa": N, onClick: v, type: "secondary", children: s.cancel }), e[34] = s.cancel, e[35] = N, e[36] = v, e[37] = F) : F = e[37]; let q; e[38] !== E || e[39] !== H || e[40] !== F ? (q = /* @__PURE__ */ R(ee, { "data-qa": H, children: [ F, E ] }), e[38] = E, e[39] = H, e[40] = F, e[41] = q) : q = e[41]; let B; e[42] !== i || e[43] !== M || e[44] !== C || e[45] !== S || e[46] !== q ? (B = /* @__PURE__ */ R("form", { "data-qa": M, name: i, onSubmit: C, children: [ S, q ] }), e[42] = i, e[43] = M, e[44] = C, e[45] = S, e[46] = q, e[47] = B) : B = e[47]; let w; return e[48] !== t || e[49] !== A || e[50] !== B || e[51] !== Q || e[52] !== $ || e[53] !== g || e[54] !== h ? (w = /* @__PURE__ */ R(Z, { ...t, "data-qa": Q, open: $, sx: g, children: [ h, A, B ] }), e[48] = t, e[49] = A, e[50] = B, e[51] = Q, e[52] = $, e[53] = g, e[54] = h, e[55] = w) : w = e[55], w; } function ae(l) { return [l.isSubmitting, l.canSubmit]; } const { fieldContext: ie, formContext: ne, useFieldContext: le, useFormContext: K } = U(), { useAppForm: he, withForm: Ae } = V({ fieldContext: ie, formContext: ne, fieldComponents: { AoaFieldError: me }, formComponents: { AoaFormModal: se, AoaFormError: oe } }); function me(l) { const e = G.c(11), { "data-qa": a } = l, s = le(); if (s.state.meta.isTouched && s.state.meta.errors.length) { let i; e[0] !== s.state.meta.errors ? (i = s.state.meta.errors.at(0), e[0] = s.state.meta.errors, e[1] = i) : i = e[1]; const t = i; if (typeof t == "string") { const r = a ?? "field-error"; let o; return e[2] !== t || e[3] !== r ? (o = /* @__PURE__ */ n(j, { "data-qa": r, message: t, severity: "error" }), e[2] = t, e[3] = r, e[4] = o) : o = e[4], o; } else if (t && typeof t == "object") { let r; e[5] !== t.level ? (r = ["error", "info", "success", "warning"].includes(t.level) ? t.level : "error", e[5] = t.level, e[6] = r) : r = e[6]; const o = r, m = a ?? "field-error"; let f; return e[7] !== t.message || e[8] !== o || e[9] !== m ? (f = /* @__PURE__ */ n(j, { "data-qa": m, message: t.message, severity: o }), e[7] = t.message, e[8] = o, e[9] = m, e[10] = f) : f = e[10], f; } } return null; } export { me as A, oe as a, se as b, ie as c, ne as d, le as e, K as f, he as u, Ae as w }; //# sourceMappingURL=FieldError.DXcLGJ_k.js.map