@hortiview/shared-components 0.0.5635 → 0.0.5859

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,83 +1,89 @@
1
1
  import "../../../assets/FormDatePicker.css";
2
- import { jsx as s } from "react/jsx-runtime";
3
- import { Datepicker as D } from "@element/react-components";
4
- import { useMemo as t } from "react";
5
- import { useFormContext as S, Controller as q } from "react-hook-form";
6
- import { g as F } from "../../../get-Dyz8NMrE.js";
7
- const w = "_datePickerContainer_gkrp1_1", H = "_invalid_gkrp1_5", Q = "_fromPickerText_gkrp1_9", Y = "_datePickerCalendar_gkrp1_13", c = {
8
- datePickerContainer: w,
2
+ import { jsx as d } from "react/jsx-runtime";
3
+ import { Datepicker as h } from "@element/react-components";
4
+ import { g as v } from "../../../get-Dyz8NMrE.js";
5
+ import { useMemo as n } from "react";
6
+ import { useFormContext as q, Controller as F } from "react-hook-form";
7
+ const Y = "_datePickerContainer_gkrp1_1", H = "_invalid_gkrp1_5", M = "_fromPickerText_gkrp1_9", Q = "_datePickerCalendar_gkrp1_13", s = {
8
+ datePickerContainer: Y,
9
9
  invalid: H,
10
- fromPickerText: Q,
11
- datePickerCalendar: Y
12
- }, M = ({
13
- propertyName: e,
14
- label: f,
15
- className: P,
16
- minRangeYear: d,
17
- maxRangeYear: l,
18
- locale: g,
19
- rules: i
10
+ fromPickerText: M,
11
+ datePickerCalendar: Q
12
+ }, O = ({
13
+ propertyName: t,
14
+ label: u,
15
+ className: g,
16
+ minRangeYear: l,
17
+ maxRangeYear: m,
18
+ locale: x,
19
+ rules: o
20
20
  }) => {
21
21
  const {
22
- control: x,
23
- formState: { errors: r, isValidating: m }
24
- } = S(), k = t(
25
- () => i?.required?.value,
26
- [i]
27
- ), u = t(
28
- () => i?.required?.message,
29
- [i]
30
- ), _ = t(
31
- () => (/* @__PURE__ */ new Date()).getFullYear() - (d ?? 95),
32
- [d]
33
- ), C = t(
34
- () => (/* @__PURE__ */ new Date()).getFullYear() + (l ?? 15),
22
+ control: _,
23
+ formState: { errors: r, isValidating: f }
24
+ } = q(), k = n(
25
+ () => o?.required?.value,
26
+ [o]
27
+ ), P = n(
28
+ () => o?.required?.message,
29
+ [o]
30
+ ), p = n(
31
+ () => (/* @__PURE__ */ new Date()).getFullYear() - (l ?? 95),
35
32
  [l]
36
- ), n = t(
37
- () => !m && F(r, e) !== void 0,
38
- [r, e, m]
39
- ), p = t(() => ({
40
- valid: !n,
41
- helperTextPersistent: n || k,
33
+ ), C = n(
34
+ () => (/* @__PURE__ */ new Date()).getFullYear() + (m ?? 15),
35
+ [m]
36
+ ), c = n(
37
+ () => !f && v(r, t) !== void 0,
38
+ [r, t, f]
39
+ ), T = n(() => ({
40
+ valid: !c,
41
+ helperTextPersistent: c || k,
42
42
  helperText: (() => {
43
- if (r && r[e]) {
44
- const a = r[e]?.message;
45
- return a || "Invalid input";
43
+ if (r && r[t]) {
44
+ const i = r[t]?.message;
45
+ return i || "Invalid input";
46
46
  }
47
- return u;
47
+ return P;
48
48
  })(),
49
- className: `${c.fromPickerText} ${n ? c.invalid : ""}`
50
- }), [r, u, e, k, n]);
51
- return /* @__PURE__ */ s(
52
- q,
49
+ className: `${s.fromPickerText} ${c ? s.invalid : ""}`
50
+ }), [r, P, t, k, c]);
51
+ return /* @__PURE__ */ d(
52
+ F,
53
53
  {
54
- name: e,
55
- rules: i,
56
- control: x,
57
- render: ({ field: { ref: v, onChange: a, value: T, ...h } }) => /* @__PURE__ */ s("div", { className: c.datePickerContainer, children: /* @__PURE__ */ s(
58
- D,
54
+ name: t,
55
+ rules: o,
56
+ control: _,
57
+ render: ({ field: { ref: D, onChange: i, value: a, ...S } }) => /* @__PURE__ */ d("div", { className: s.datePickerContainer, children: /* @__PURE__ */ d(
58
+ h,
59
59
  {
60
- ...h,
61
- className: P ?? "",
62
- value: T,
60
+ ...S,
61
+ className: g ?? "",
62
+ value: a,
63
63
  variant: "outlined",
64
- label: f,
65
- format: (o) => o ? o.toLocaleDateString(g ?? "en") : "",
64
+ label: u,
65
+ format: (e) => e ? e.toLocaleDateString(x ?? "en") : "",
66
66
  disableClearing: !0,
67
- onSelect: (o) => {
68
- a(o);
67
+ onSelect: (e) => {
68
+ i(e);
69
+ },
70
+ onSelectMonth: (e) => {
71
+ a && (e.setDate(a.getDate()), i(e));
72
+ },
73
+ onSelectYear: (e) => {
74
+ a && (e.setDate(a.getDate()), i(e));
69
75
  },
70
76
  hoisted: !0,
71
- calendarProps: { hoisted: !0, className: c.datePickerCalendar },
72
- minQuickSelectYear: _,
77
+ calendarProps: { hoisted: !0, className: s.datePickerCalendar },
78
+ minQuickSelectYear: p,
73
79
  maxQuickSelectYear: C,
74
80
  readOnly: !0,
75
- textfieldProps: p
81
+ textfieldProps: T
76
82
  }
77
83
  ) })
78
84
  }
79
85
  );
80
86
  };
81
87
  export {
82
- M as FormDatePicker
88
+ O as FormDatePicker
83
89
  };
@@ -1,85 +1,88 @@
1
1
  import "../../../assets/FormSelect.css";
2
- import { jsx as i, Fragment as I } from "react/jsx-runtime";
2
+ import { jsx as l, Fragment as O } from "react/jsx-runtime";
3
3
  import { Select as P } from "@element/react-components";
4
- import { g as V } from "../../../get-Dyz8NMrE.js";
5
- import { useMemo as m } from "react";
6
- import { useFormContext as k, Controller as _ } from "react-hook-form";
7
- const w = "_invalid_1vo1h_1", z = "_formSelect_1vo1h_5", A = "_formSelectContainer_1vo1h_9", d = {
4
+ import { g as d } from "../../../get-Dyz8NMrE.js";
5
+ import { useMemo as u } from "react";
6
+ import { useFormContext as V, Controller as g } from "react-hook-form";
7
+ import { isArray as k } from "lodash";
8
+ const w = "_invalid_1vo1h_1", z = "_formSelect_1vo1h_5", B = "_formSelectContainer_1vo1h_9", S = {
8
9
  invalid: w,
9
10
  formSelect: z,
10
- formSelectContainer: A
11
- }, Q = ({
11
+ formSelectContainer: B
12
+ }, W = ({
12
13
  propertyName: r,
13
- label: g,
14
- options: s,
15
- multi: l = !1,
16
- disabled: h = !1,
17
- hoisted: v = !1,
18
- hidden: C = !1,
19
- valueKey: t = "value",
20
- textKey: q = "text",
21
- clearable: T = !1,
22
- noOptionsMessage: F = "",
23
- rules: n,
24
- ...H
14
+ label: h,
15
+ options: t,
16
+ multi: s = !1,
17
+ disabled: C = !1,
18
+ hoisted: p = !1,
19
+ hidden: q = !1,
20
+ valueKey: n = "value",
21
+ textKey: T = "text",
22
+ clearable: F = !1,
23
+ noOptionsMessage: M = "",
24
+ rules: i,
25
+ ...b
25
26
  }) => {
26
27
  const {
27
- control: u,
28
- formState: { errors: o, isValidating: S }
29
- } = k(), c = m(
30
- () => !S && V(o, r) !== void 0,
31
- [o, r, S]
32
- ), M = m(
33
- () => n?.required?.value,
34
- [n]
35
- ), $ = m(
36
- () => n?.required?.message,
37
- [n]
38
- ), b = () => {
28
+ control: v,
29
+ formState: { errors: o, isValidating: x }
30
+ } = V(), a = u(
31
+ () => !x && d(o, r) !== void 0,
32
+ [o, r, x]
33
+ ), H = u(
34
+ () => i?.required?.value,
35
+ [i]
36
+ ), $ = u(
37
+ () => i?.required?.message,
38
+ [i]
39
+ ), j = () => {
39
40
  if (o && o[r]) {
40
- const a = o[r]?.message;
41
- return a || "Invalid input";
41
+ const f = o[r]?.message;
42
+ return f || "Invalid input";
42
43
  }
43
44
  return $;
44
45
  };
45
- return C ? /* @__PURE__ */ i(_, { name: r, control: u, render: () => /* @__PURE__ */ i(I, {}) }) : /* @__PURE__ */ i("div", { className: d.formSelectContainer, children: /* @__PURE__ */ i(
46
- _,
46
+ return q ? /* @__PURE__ */ l(g, { name: r, control: v, render: () => /* @__PURE__ */ l(O, {}) }) : /* @__PURE__ */ l("div", { className: S.formSelectContainer, children: /* @__PURE__ */ l(
47
+ g,
47
48
  {
48
49
  name: r,
49
- rules: n,
50
- control: u,
51
- render: ({ field: { ref: a, onChange: f, value: x, ...j } }) => {
52
- const p = l ? s?.filter(
53
- (e) => x?.includes(e[t])
54
- ) : s?.find((e) => e[t] === x);
55
- return /* @__PURE__ */ i(
50
+ rules: i,
51
+ control: v,
52
+ render: ({ field: { ref: f, onChange: m, value: _, ...A } }) => {
53
+ let c = t;
54
+ k(t) && d(t[0], "options") !== void 0 && (c = t.flatMap((e) => d(e, "options") ?? []));
55
+ const E = s ? c?.filter(
56
+ (e) => _?.includes(e[n])
57
+ ) : c?.find((e) => e[n] === _);
58
+ return /* @__PURE__ */ l(
56
59
  P,
57
60
  {
58
- ...j,
59
- ...H,
60
- value: p,
61
- label: g,
61
+ ...A,
62
+ ...b,
63
+ value: E,
64
+ label: h,
62
65
  variant: "outlined",
63
- helperText: b(),
64
- helperTextPersistent: M || c,
65
- options: s,
66
- valid: !c,
67
- multiSelect: l,
68
- className: `${d.formSelect} ${c ? d.invalid : ""}`,
69
- disabled: h,
70
- valueKey: t,
71
- textKey: q,
66
+ helperText: j(),
67
+ helperTextPersistent: H || a,
68
+ options: t,
69
+ valid: !a,
70
+ multiSelect: s,
71
+ className: `${S.formSelect} ${a ? S.invalid : ""}`,
72
+ disabled: C,
73
+ valueKey: n,
74
+ textKey: T,
72
75
  onChange: (e) => {
73
76
  if (e == null)
74
- return f(e);
75
- if (l)
76
- return f(e.map((E) => E[t]));
77
- f(e[t]);
77
+ return m(e);
78
+ if (s)
79
+ return m(e.map((I) => I[n]));
80
+ m(e[n]);
78
81
  },
79
- hoisted: v,
80
- noOptionsMessage: F,
82
+ hoisted: p,
83
+ noOptionsMessage: M,
81
84
  searchable: !0,
82
- clearable: T,
85
+ clearable: F,
83
86
  menuMaxHeight: "15rem"
84
87
  }
85
88
  );
@@ -88,5 +91,5 @@ const w = "_invalid_1vo1h_1", z = "_formSelect_1vo1h_5", A = "_formSelectContain
88
91
  ) });
89
92
  };
90
93
  export {
91
- Q as FormSelect
94
+ W as FormSelect
92
95
  };
@@ -1,24 +1,24 @@
1
- import { jsx as s } from "react/jsx-runtime";
2
- import { r as a, s as r } from "../../../react.esm-C0LtovhP.js";
3
- import { FormSelect as c } from "./FormSelect.js";
4
- import { v as e, d as l, t as u, g as t } from "../../../vi.JYQecGiw-BbUbJcT8.js";
5
- const m = e.fn();
6
- e.mock("react-hook-form", () => ({
7
- ...e.importActual("react-hook-form"),
1
+ import { jsx as u } from "react/jsx-runtime";
2
+ import { r as l, s as t, f as i } from "../../../react.esm-C0LtovhP.js";
3
+ import { FormSelect as m } from "./FormSelect.js";
4
+ import { v as n, d as g, t as d, g as e } from "../../../vi.JYQecGiw-BbUbJcT8.js";
5
+ const p = n.fn();
6
+ n.mock("react-hook-form", () => ({
7
+ ...n.importActual("react-hook-form"),
8
8
  Controller: ({
9
- render: o
10
- }) => o({
9
+ render: r
10
+ }) => r({
11
11
  field: {
12
12
  ref: void 0,
13
- onChange: m,
13
+ onChange: p,
14
14
  value: "3"
15
15
  }
16
16
  }),
17
17
  useFormContext: () => ({
18
18
  control: {
19
- register: e.fn(),
20
- unregister: e.fn(),
21
- getFieldState: e.fn(),
19
+ register: n.fn(),
20
+ unregister: n.fn(),
21
+ getFieldState: n.fn(),
22
22
  _names: {
23
23
  array: new Set("test"),
24
24
  mount: new Set("test"),
@@ -28,11 +28,11 @@ e.mock("react-hook-form", () => ({
28
28
  watchAll: !1
29
29
  },
30
30
  _subjects: {
31
- watch: e.fn(),
32
- array: e.fn(),
33
- state: e.fn()
31
+ watch: n.fn(),
32
+ array: n.fn(),
33
+ state: n.fn()
34
34
  },
35
- _getWatch: e.fn(),
35
+ _getWatch: n.fn(),
36
36
  _formValues: ["test"],
37
37
  _defaultValues: ["test"]
38
38
  },
@@ -40,27 +40,63 @@ e.mock("react-hook-form", () => ({
40
40
  getFieldState: () => ({ invalid: !1 })
41
41
  })
42
42
  }));
43
- l("FormSelect Test", () => {
44
- const o = [
43
+ g("FormSelect Test", () => {
44
+ const r = [
45
45
  { id: "1", value: "Germany", description: "" },
46
46
  { id: "2", value: "France", description: "" },
47
47
  { id: "3", value: "Afar", description: "" }
48
+ ], f = [
49
+ {
50
+ groupValue: "Europe",
51
+ groupName: "Europe",
52
+ options: [
53
+ { id: "1", value: "Germany", description: "" },
54
+ { id: "2", value: "France", description: "" }
55
+ ]
56
+ },
57
+ {
58
+ groupValue: "Africa",
59
+ groupName: "Africa",
60
+ options: [{ id: "3", value: "Afar", description: "" }]
61
+ }
48
62
  ];
49
- u("render FormSelect", () => {
50
- a(
51
- /* @__PURE__ */ s(
52
- c,
63
+ d("render FormSelect", () => {
64
+ l(
65
+ /* @__PURE__ */ u(
66
+ m,
67
+ {
68
+ label: "address.country",
69
+ rules: { required: { value: !0, message: "required" } },
70
+ propertyName: "countryId",
71
+ options: r,
72
+ valueKey: "id",
73
+ textKey: "value"
74
+ }
75
+ )
76
+ );
77
+ const o = t.getByRole("combobox");
78
+ e(o).toBeInTheDocument(), e(o).toBeInstanceOf(HTMLInputElement), e(t.getByText("address.country")).toBeInTheDocument(), e(t.getByText("Afar")).toBeInTheDocument(), e(t.getByText("required")).toBeInTheDocument();
79
+ }), d("render grouped FormSelect and click on option", () => {
80
+ l(
81
+ /* @__PURE__ */ u(
82
+ m,
53
83
  {
54
84
  label: "address.country",
55
85
  rules: { required: { value: !0, message: "required" } },
56
86
  propertyName: "countryId",
57
- options: o,
87
+ options: f,
58
88
  valueKey: "id",
59
89
  textKey: "value"
60
90
  }
61
91
  )
62
92
  );
63
- const n = r.getByRole("combobox");
64
- t(n).toBeInTheDocument(), t(n).toBeInstanceOf(HTMLInputElement), t(r.getByText("address.country")).toBeInTheDocument(), t(r.getByText("Afar")).toBeInTheDocument(), t(r.getByText("required")).toBeInTheDocument();
93
+ const o = t.getByRole("combobox");
94
+ e(o).toBeInTheDocument(), e(o).toBeInstanceOf(HTMLInputElement), e(t.getByText("address.country")).toBeInTheDocument(), e(t.getByText("Afar")).toBeInTheDocument(), e(t.getByText("required")).toBeInTheDocument(), i.mouseDown(o);
95
+ const s = t.getByText("Africa");
96
+ e(s).toBeInTheDocument(), e(s.parentElement?.parentElement).toBeInstanceOf(HTMLHeadingElement);
97
+ const c = t.getByText("Europe");
98
+ e(c).toBeInTheDocument(), e(c.parentElement?.parentElement).toBeInstanceOf(HTMLHeadingElement);
99
+ const a = t.getByText("France");
100
+ e(a).toBeInTheDocument(), e(a.parentElement?.parentElement).not.toBeInstanceOf(HTMLHeadingElement), e(t.getByText("Germany")).toBeInTheDocument(), e(t.getAllByText("Afar")).toHaveLength(2), i.click(a), e(p).toBeCalledWith("2");
65
101
  });
66
102
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hortiview/shared-components",
3
3
  "description": "This is a shared component library. It should used in the HortiView platform and its modules.",
4
- "version": "0.0.5635",
4
+ "version": "0.0.5859",
5
5
  "type": "module",
6
6
  "repository": "https://dev.azure.com/sdundc/HV%20Platform/_git/HortiView-Frontend-Shared",
7
7
  "author": "Falk Menge <falk.menge.ext@bayer.com>",