@beda.software/web-item-controls 0.1.27 → 0.1.28-tab-validation.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/controls/GroupTabs/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAsC,MAAM,SAAS,CAAC;AAI7E,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,2CA0D9C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/controls/GroupTabs/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAsC,MAAM,SAAS,CAAC;AAM7E,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,2CAgF9C"}
@@ -1,33 +1,47 @@
1
- import { jsx as i } from "react/jsx-runtime";
2
- import { Flex as f, Tabs as d } from "antd";
3
- import { useState as b, useMemo as h } from "react";
4
- import { useWatch as y } from "react-hook-form";
5
- import { getEnabledQuestions as x, QuestionItems as I } from "sdc-qrf";
6
- import { GroupWizardBus as v } from "../GroupWizard/index.js";
7
- function B(p) {
8
- var c;
1
+ import { jsx as s, jsxs as k } from "react/jsx-runtime";
2
+ import { theme as y, Tabs as x, Flex as p, Badge as T } from "antd";
3
+ import v from "lodash";
4
+ import { useState as E } from "react";
5
+ import { useWatch as P, useFormState as B } from "react-hook-form";
6
+ import { getEnabledQuestions as C, QuestionItems as G } from "sdc-qrf";
7
+ import { GroupWizardBus as K } from "../GroupWizard/index.js";
8
+ import { countValidationErrors as j } from "./utils.js";
9
+ function _(d) {
10
+ var m;
9
11
  const {
10
- parentPath: n,
11
- questionItem: o,
12
- context: a
13
- } = p;
14
- o.repeats && console.warn("GroupTabs does not support repeatable groups in the first level");
15
- const m = y(), [l, u] = b(), r = h(() => {
12
+ parentPath: i,
13
+ questionItem: n,
14
+ context: f
15
+ } = d;
16
+ n.repeats && console.warn("GroupTabs does not support repeatable groups in the first level");
17
+ const h = P(), {
18
+ errors: b
19
+ } = B(), {
20
+ token: g
21
+ } = y.useToken(), [I, c] = E(), o = (() => {
16
22
  const {
17
- linkId: s
18
- } = o, t = a[0];
19
- return t ? x(o.item ?? [], n, m, t).filter((e) => !e.hidden).map((e) => ({
20
- key: e.linkId,
21
- label: e.text,
22
- children: /* @__PURE__ */ i(f, { gap: 16, vertical: !0, children: /* @__PURE__ */ i(I, { questionItems: e.item, parentPath: [...n, s, "items", e.linkId, "items"], context: t }) })
23
- })) : [];
24
- }, [a, m, n, o]);
25
- return v.useBus("scrollTo", ({
26
- groupLinkId: s
23
+ linkId: r
24
+ } = n, e = f[0];
25
+ return e ? C(n.item ?? [], i, h, e).filter((t) => !t.hidden).map((t) => {
26
+ const u = [...i, r, "items", t.linkId, "items"], l = j(v.get(b, u)), a = l > 0;
27
+ return {
28
+ key: t.linkId,
29
+ label: /* @__PURE__ */ k(p, { align: "center", gap: 8, "data-testid": `group-tab-${t.linkId}`, "data-has-errors": a, style: a ? {
30
+ color: g.colorError
31
+ } : void 0, children: [
32
+ t.text,
33
+ a ? /* @__PURE__ */ s(T, { count: l, size: "small", "data-testid": `group-tab-errors-count-${t.linkId}` }) : null
34
+ ] }),
35
+ children: /* @__PURE__ */ s(p, { gap: 16, vertical: !0, children: /* @__PURE__ */ s(G, { questionItems: t.item, parentPath: u, context: e }) })
36
+ };
37
+ }) : [];
38
+ })();
39
+ return K.useBus("scrollTo", ({
40
+ groupLinkId: r
27
41
  }) => {
28
- r.some((t) => t.key === s) && u(s);
29
- }, [r]), /* @__PURE__ */ i(d, { type: "card", items: r, activeKey: l ?? ((c = r[0]) == null ? void 0 : c.key), onChange: u, destroyInactiveTabPane: !0 });
42
+ o.some((e) => e.key === r) && c(r);
43
+ }, [o]), /* @__PURE__ */ s(x, { type: "card", items: o, activeKey: I ?? ((m = o[0]) == null ? void 0 : m.key), onChange: c, destroyInactiveTabPane: !0 });
30
44
  }
31
45
  export {
32
- B as GroupTabs
46
+ _ as GroupTabs
33
47
  };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Recursively counts leaf validation errors in a (nested) react-hook-form errors object.
3
+ *
4
+ * @param errors - A react-hook-form errors subtree (object, array or a single field error)
5
+ * @returns Number of field errors found in the subtree
6
+ */
7
+ export declare function countValidationErrors(errors: unknown): number;
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/controls/GroupTabs/utils.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAU7D"}
@@ -0,0 +1,10 @@
1
+ import i from "lodash";
2
+ function n(t) {
3
+ return i.isPlainObject(t) && typeof t.type == "string";
4
+ }
5
+ function o(t) {
6
+ return n(t) ? 1 : i.isObjectLike(t) ? Object.values(t).reduce((r, e) => r + o(e), 0) : 0;
7
+ }
8
+ export {
9
+ o as countValidationErrors
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beda.software/web-item-controls",
3
- "version": "0.1.27",
3
+ "version": "0.1.28-tab-validation.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",