@hortiview/shared-components 0.0.7315 → 0.0.7369

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.
Files changed (70) hide show
  1. package/README.md +83 -1
  2. package/dist/assets/contextMenu.css +1 -1
  3. package/dist/assets/genericCard.css +1 -0
  4. package/dist/assets/genericTable.css +1 -1
  5. package/dist/components/AlertBanner/AlertBanner.d.ts +2 -1
  6. package/dist/components/AlertBanner/AlertBanner.js +17 -11
  7. package/dist/components/AlertBanner/AlertBanner.test.js +2 -2
  8. package/dist/components/BaseView/BaseView.js +1 -1
  9. package/dist/components/BaseView/BaseView.test.js +2 -2
  10. package/dist/components/BasicHeading/BasicHeading.js +1 -1
  11. package/dist/components/BasicHeading/BasicHeading.test.js +1 -1
  12. package/dist/components/BlockView/BlockView.test.js +1 -1
  13. package/dist/components/ContextMenu/ContextMenu.js +16 -15
  14. package/dist/components/ContextMenu/ContextMenu.test.js +1 -1
  15. package/dist/components/DeleteModal/DeleteModal.test.js +1 -1
  16. package/dist/components/Disclaimer/Disclaimer.test.js +1 -1
  17. package/dist/components/EmptyView/EmptyView.test.js +1 -1
  18. package/dist/components/Filter/Filter.js +39 -42
  19. package/dist/components/Filter/Filter.test.js +22 -19
  20. package/dist/components/FormComponents/FormCheckBox/FormCheckBox.test.js +1 -1
  21. package/dist/components/FormComponents/FormDatePicker/FormDatePicker.test.js +1 -1
  22. package/dist/components/FormComponents/FormRadio/FormRadio.test.js +1 -1
  23. package/dist/components/FormComponents/FormSelect/FormSelect.test.js +2 -2
  24. package/dist/components/FormComponents/FormSlider/FormSlider.test.js +1 -1
  25. package/dist/components/FormComponents/FormText/FormText.test.js +1 -1
  26. package/dist/components/GenericTable/GenericTable.d.ts +7 -2
  27. package/dist/components/GenericTable/GenericTable.js +91 -66
  28. package/dist/components/GenericTable/GenericTable.test.js +59 -45
  29. package/dist/components/GenericTable/GenericTableService.d.ts +19 -0
  30. package/dist/components/GenericTable/GenericTableService.js +59 -0
  31. package/dist/components/GenericTable/Mobile/GenericCard.d.ts +19 -0
  32. package/dist/components/GenericTable/Mobile/GenericCard.js +68 -0
  33. package/dist/components/GenericTable/Mobile/GenericCard.test.d.ts +1 -0
  34. package/dist/components/GenericTable/Mobile/GenericCard.test.js +76 -0
  35. package/dist/components/GenericTable/Mobile/GenericCardList.d.ts +22 -0
  36. package/dist/components/GenericTable/Mobile/GenericCardList.js +20 -0
  37. package/dist/components/GenericTable/Mobile/GenericCardList.test.d.ts +1 -0
  38. package/dist/components/GenericTable/Mobile/GenericCardList.test.js +78 -0
  39. package/dist/components/HashTabView/HashTabView.js +1 -1
  40. package/dist/components/HashTabView/HashTabView.test.js +1 -1
  41. package/dist/components/HeaderFilter/HeaderFilter.test.js +1 -1
  42. package/dist/components/Iconify/Iconify.test.js +1 -1
  43. package/dist/components/InfoGroup/InfoGroup.js +1 -1
  44. package/dist/components/InfoGroup/InfoGroup.test.js +1 -1
  45. package/dist/components/ListArea/ListArea.test.js +1 -1
  46. package/dist/components/LoadingSpinner/Big/BigLoadingSpinner.test.js +1 -1
  47. package/dist/components/LoadingSpinner/Default/LoadingSpinner.test.js +1 -1
  48. package/dist/components/OverflowTooltip/OverflowTooltip.js +29 -13
  49. package/dist/components/OverflowTooltip/OverflowTooltip.test.js +2 -2
  50. package/dist/components/Scrollbar/scrollbar.test.js +1 -1
  51. package/dist/components/SearchBar/SearchBar.test.js +1 -1
  52. package/dist/components/VerticalDivider/VerticalDivider.test.js +1 -1
  53. package/dist/contextMenu.module-DNQ8d9Aj.js +8 -0
  54. package/dist/genericCard.module-DzqcufuN.js +12 -0
  55. package/dist/genericTable.module-CXfRg0e4.js +15 -0
  56. package/dist/hooks/useBreakpoints.js +5 -0
  57. package/dist/hooks/useBreakpoints.test.js +2 -2
  58. package/dist/index-DW4oU_OU.js +11708 -0
  59. package/dist/main.d.ts +1 -1
  60. package/dist/main.js +60 -59
  61. package/dist/{react.esm-C3jDj5Fe.js → react.esm-Dy4VzU4L.js} +4 -1
  62. package/dist/types/GenericTable.d.ts +36 -0
  63. package/package.json +10 -10
  64. package/dist/assets/Filter.css +0 -22
  65. package/dist/contextMenu.module-B7aUMFPe.js +0 -7
  66. package/dist/genericTable.module-BkU2VDKR.js +0 -11
  67. package/dist/hooks/useBreakpoint.js +0 -5
  68. package/dist/index-BQnj-5Zt.js +0 -2963
  69. /package/dist/hooks/{useBreakpoint.d.ts → useBreakpoints.d.ts} +0 -0
  70. /package/dist/{useBreakpoint-BNeVhjjZ.js → useBreakpoints-BNeVhjjZ.js} +0 -0
@@ -1,92 +1,117 @@
1
- import { jsx as e, jsxs as T } from "react/jsx-runtime";
2
- import { Elevation as N, Table as B, TableTopBar as v, Group as g, Padding as j, TypoDisplay as C, TypoSubtitle as D } from "@element/react-components";
3
- import { useMemo as b, Fragment as I } from "react";
4
- import { ContextMenu as M } from "../ContextMenu/ContextMenu.js";
5
- import { s as u } from "../../genericTable.module-BkU2VDKR.js";
6
- const G = (r, l) => {
7
- if (!r)
8
- return [];
9
- let i = Object.keys(r).map((t) => t);
10
- return l.length > 0 && (i = i.sort((t, o) => {
11
- const p = l.findIndex((c) => c === t), s = l.findIndex((c) => c === o);
12
- return p === -1 ? 1 : s === -1 ? -1 : p - s;
13
- })), i;
14
- }, F = ({
15
- data: r = [],
16
- hiddenColumns: l = [],
17
- order: i = [],
18
- cellTemplates: t = void 0,
19
- tableActions: o = [],
20
- noContentText: p = "No data available",
21
- headerTranslation: s = (m) => m,
22
- pagination: c = !1,
23
- getRowActions: d = void 0,
24
- customColumnWidth: h,
25
- title: f
1
+ import { jsx as r, jsxs as B } from "react/jsx-runtime";
2
+ import { Elevation as D, Table as G, TableTopBar as u, Group as l, Padding as W, TypoDisplay as k, TypoSubtitle as C } from "@element/react-components";
3
+ import { Fragment as j } from "react";
4
+ import { a as e } from "../../genericTable.module-CXfRg0e4.js";
5
+ import { u as x } from "../../useBreakpoints-BNeVhjjZ.js";
6
+ import "../../alertBanner.module-HneYdVzN.js";
7
+ import "../../iconify.module-C89oaw5b.js";
8
+ import "../../isArray-Ca4KR8TK.js";
9
+ import "../../react-tooltip.min-BzHiZW8k.js";
10
+ import "../../basicHeading.module-BYb8xvuk.js";
11
+ import "../../_baseToString-BNXOi2Mf.js";
12
+ import "../../_equalByTag-DJhSpgVG.js";
13
+ import "../../searchBar.module-9gKyrZRT.js";
14
+ import "../../listArea.module-CGpHPOji.js";
15
+ import "../../verticalDivider.module-C3_GL-fH.js";
16
+ import "../../baseView.module-ve87u_d0.js";
17
+ import "../../BlockView.module-BPlNT5uh.js";
18
+ import "lodash";
19
+ import "../../contextMenu.module-DNQ8d9Aj.js";
20
+ import "../../deleteModal.module-Ds3MDzdl.js";
21
+ import "../../disclaimer.module-BZydt-Q_.js";
22
+ import "../../HashTabView.module-CJX4gxTu.js";
23
+ import "../../HeaderFilter.module-DiBmulr5.js";
24
+ import "../../infoGroup.module-B3E1gCGi.js";
25
+ import "../../bigLoadingSpinner.module-GgbFol8k.js";
26
+ import "../../loadingSpinner.module-CLtqSMWA.js";
27
+ import "../Scrollbar/Scrollbar.js";
28
+ import "react-hook-form";
29
+ import "../../formDatePicker.module-BV3ma_7y.js";
30
+ import "../../formSelect.module-C18N-SsT.js";
31
+ import "../../formText.module-C0by6_DK.js";
32
+ import { useGenerateColumns as _, useGenerateTableData as $ } from "./GenericTableService.js";
33
+ import { GenericCardList as A } from "./Mobile/GenericCardList.js";
34
+ const dr = ({
35
+ data: m = [],
36
+ hiddenColumns: p = [],
37
+ order: f = [],
38
+ cellTemplates: h = void 0,
39
+ tableActions: i = [],
40
+ noContentText: n = "No data available",
41
+ headerTranslation: g = (o) => o,
42
+ pagination: y = !1,
43
+ getRowActions: s = void 0,
44
+ customColumnWidth: b,
45
+ title: t,
46
+ cardTitleColumn: v,
47
+ cardSubTitleColumn: T
26
48
  }) => {
27
- const m = b(() => {
28
- if (r.length === 0)
29
- return [];
30
- const a = G(r[0], i).map((n) => {
31
- const x = h ? h[n] : void 0;
32
- return {
33
- id: n,
34
- header: s(n),
35
- accessor: n,
36
- cellTemplate: t ? t[n] : void 0,
37
- cellProps: { width: x }
38
- };
39
- });
40
- return d ? [...a, { id: "actions", header: "", accessor: "actions" }] : a;
41
- }, [r, t, i, s, d, h]), y = b(() => d ? r.map((a) => {
42
- const n = /* @__PURE__ */ e(M, { actions: d(a), iconOrientation: "horizontal" });
43
- return { ...a, actions: n };
44
- }) : r, [r, d]);
45
- return /* @__PURE__ */ e(N, { elevation: 1, className: u.elevation, children: /* @__PURE__ */ e(
46
- B,
49
+ const { isDesktop: o } = x(), a = _({
50
+ data: m,
51
+ order: f,
52
+ cellTemplates: h,
53
+ headerTranslation: g,
54
+ getRowActions: s,
55
+ customColumnWidth: b,
56
+ cardTitleColumn: v,
57
+ cardSubTitleColumn: T
58
+ }), c = $({
59
+ data: m,
60
+ getRowActions: s
61
+ });
62
+ return o ? /* @__PURE__ */ r(D, { elevation: 1, className: e.elevation, children: /* @__PURE__ */ r(
63
+ G,
47
64
  {
48
- className: u.table,
65
+ className: e.table,
49
66
  fullWidth: !0,
50
67
  alwaysUseDivTags: !0,
51
68
  layout: "standard",
52
- hiddenColumns: l,
53
- data: y,
54
- columns: m,
55
- leadingContent: f && o.length === 0 ? /* @__PURE__ */ e(v, { title: f }) : o.length > 0 && /* @__PURE__ */ e(
56
- v,
69
+ hiddenColumns: p,
70
+ data: c,
71
+ columns: a,
72
+ leadingContent: t && i?.length === 0 ? /* @__PURE__ */ r(u, { title: t }) : i?.length > 0 && /* @__PURE__ */ r(
73
+ u,
57
74
  {
58
- className: u.topBar,
59
- filterBar: /* @__PURE__ */ T(g, { fullWidth: !0, direction: "vertical", gap: "none", children: [
60
- f && /* @__PURE__ */ e(j, { children: /* @__PURE__ */ e(C, { level: 6, children: f }) }),
61
- /* @__PURE__ */ e(
62
- g,
75
+ className: e.topBar,
76
+ filterBar: /* @__PURE__ */ B(l, { fullWidth: !0, direction: "vertical", gap: "none", children: [
77
+ t && /* @__PURE__ */ r(W, { children: /* @__PURE__ */ r(k, { level: 6, children: t }) }),
78
+ /* @__PURE__ */ r(
79
+ l,
63
80
  {
64
- className: u.filterBar,
81
+ className: e.filterBar,
65
82
  fullWidth: !0,
66
83
  primaryAlign: "center",
67
84
  secondaryAlign: "center",
68
- children: o.map((a, n) => /* @__PURE__ */ e(I, { children: a }, `action_${n}`))
85
+ children: i.map((d, N) => /* @__PURE__ */ r(j, { children: d }, `action_${N}_${d.key}`))
69
86
  }
70
87
  )
71
88
  ] })
72
89
  }
73
90
  ),
74
- paginated: c,
91
+ paginated: y,
75
92
  sortable: !0,
76
- noContentIncludeTable: !!m,
77
- noContentMessage: /* @__PURE__ */ e(
78
- g,
93
+ noContentIncludeTable: !!a,
94
+ noContentMessage: /* @__PURE__ */ r(
95
+ l,
79
96
  {
80
97
  fullWidth: !0,
81
98
  primaryAlign: "center",
82
99
  secondaryAlign: "center",
83
- className: u.emptyTable,
84
- children: /* @__PURE__ */ e(D, { children: p })
100
+ className: e.emptyTable,
101
+ children: /* @__PURE__ */ r(C, { children: n })
85
102
  }
86
103
  )
87
104
  }
88
- ) });
105
+ ) }) : /* @__PURE__ */ r(
106
+ A,
107
+ {
108
+ data: c,
109
+ columns: a,
110
+ hiddenColumns: p,
111
+ noContentText: n
112
+ }
113
+ );
89
114
  };
90
115
  export {
91
- F as GenericTable
116
+ dr as GenericTable
92
117
  };
@@ -1,71 +1,85 @@
1
- import { jsx as a, jsxs as u } from "react/jsx-runtime";
2
- import { a as i, s as e } from "../../react.esm-C3jDj5Fe.js";
3
- import { GenericTable as c } from "./GenericTable.js";
4
- import { d as B, t as d, g as t, v as r } from "../../vi.JYQecGiw-BbUbJcT8.js";
5
- B("GenericTable Test", () => {
6
- const m = [];
7
- d("render GenericTable with custom no content text", () => {
8
- i(/* @__PURE__ */ a(c, { data: m, noContentText: "noContent" })), t(e.getByText("noContent")).toBeInTheDocument();
9
- }), d("render GenericTable with data should render headers", () => {
10
- i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }] })), t(e.getByText("id")).toBeInTheDocument(), t(e.getByText("name")).toBeInTheDocument();
11
- }), d("render GenericTable with hidden headers", () => {
12
- i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], hiddenColumns: ["name"] })), t(e.getByText("id")).toBeInTheDocument(), t(e.queryByText("name")).not.toBeInTheDocument();
13
- }), d("render GenericTable with custom header translation", () => {
14
- i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], headerTranslation: (o) => o + ".translated" })), t(e.getByText("id.translated")).toBeInTheDocument(), t(e.getByText("name.translated")).toBeInTheDocument();
15
- }), d("render GenericTable with custom cell template", () => {
16
- i(
1
+ import { jsx as a, jsxs as B } from "react/jsx-runtime";
2
+ import { a as o, s as e } from "../../react.esm-Dy4VzU4L.js";
3
+ import { a as m } from "../../useBreakpoints-BNeVhjjZ.js";
4
+ import { GenericTable as s } from "./GenericTable.js";
5
+ import { d as h, v as r, t as i, g as t } from "../../vi.JYQecGiw-BbUbJcT8.js";
6
+ h("GenericTable Test", () => {
7
+ r.spyOn(m, "useBreakpoints").mockReturnValue({
8
+ isDesktop: !0,
9
+ isMobile: !1,
10
+ isTablet: !1,
11
+ isDesktopNavbar: !1
12
+ });
13
+ const T = [];
14
+ i("render GenericTable with custom no content text", () => {
15
+ o(/* @__PURE__ */ a(s, { data: T, noContentText: "noContent" })), t(e.getByText("noContent")).toBeInTheDocument();
16
+ }), i("render GenericTable with data should render headers", () => {
17
+ o(/* @__PURE__ */ a(s, { data: [{ id: 1, name: "test" }] })), t(e.getByText("id")).toBeInTheDocument(), t(e.getByText("name")).toBeInTheDocument();
18
+ }), i("render GenericTable with hidden headers", () => {
19
+ o(/* @__PURE__ */ a(s, { data: [{ id: 1, name: "test" }], hiddenColumns: ["name"] })), t(e.getByText("id")).toBeInTheDocument(), t(e.queryByText("name")).not.toBeInTheDocument();
20
+ }), i("render GenericTable with custom header translation", () => {
21
+ o(/* @__PURE__ */ a(s, { data: [{ id: 1, name: "test" }], headerTranslation: (d) => d + ".translated" })), t(e.getByText("id.translated")).toBeInTheDocument(), t(e.getByText("name.translated")).toBeInTheDocument();
22
+ }), i("render GenericTable with custom cell template", () => {
23
+ o(
17
24
  /* @__PURE__ */ a(
18
- c,
25
+ s,
19
26
  {
20
27
  data: [{ id: 1, name: "test" }],
21
- cellTemplates: { id: (o) => /* @__PURE__ */ u("div", { children: [
28
+ cellTemplates: { id: (d) => /* @__PURE__ */ B("div", { children: [
22
29
  "label: ",
23
- o.row.original.id
30
+ d.row.original.id
24
31
  ] }) }
25
32
  }
26
33
  )
27
34
  ), t(e.getByText("label: 1")).toBeInTheDocument();
28
- }), d("render GenericTable with custom table actions", () => {
35
+ }), i("render GenericTable with custom table actions", () => {
29
36
  const n = r.fn();
30
- i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], tableActions: [
37
+ o(/* @__PURE__ */ a(s, { data: [{ id: 1, name: "test" }], tableActions: [
31
38
  /* @__PURE__ */ a("button", { "data-testid": "testButton", onClick: n, children: "testbutton" }, "test")
32
39
  ] })), t(e.getByText("testbutton")).toBeInTheDocument(), e.getByTestId("testButton").click(), t(n).toHaveBeenCalled();
33
- }), d("render GenericTable with custom pagination", () => {
34
- i(/* @__PURE__ */ a(c, { data: [
40
+ }), i("render GenericTable with custom pagination", () => {
41
+ o(/* @__PURE__ */ a(s, { data: [
35
42
  { id: 1, name: "test" },
36
43
  { id: 2, name: "test2" },
37
44
  { id: 3, name: "test3" }
38
45
  ], pagination: !0 })), t(e.getByText("1 - 3 of 3")).toBeInTheDocument(), t(e.getByText("last_page")).toBeInTheDocument();
39
- }), d("render GenericTable with custom getRowActions", () => {
40
- const n = [{ id: 1, name: "test" }], o = r.fn();
41
- i(/* @__PURE__ */ a(c, { data: n, getRowActions: (T) => [
46
+ }), i("render GenericTable with custom getRowActions", () => {
47
+ const n = [{ id: 1, name: "test" }], d = r.fn();
48
+ o(/* @__PURE__ */ a(s, { data: n, getRowActions: (u) => [
42
49
  {
43
50
  primaryText: "primText",
44
51
  secondaryText: "secText",
45
- onClick: () => o(T.id),
52
+ onClick: () => d(u.id),
46
53
  leadingBlock: "edit"
47
54
  }
48
- ] })), t(e.getByText("primText")).toBeInTheDocument(), e.getByText("primText").click(), t(o).toHaveBeenCalledWith(1);
49
- }), d("render GenericTable with custom order", () => {
50
- i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test", age: 20 }], order: ["name", "age"] }));
51
- const o = e.getByText("id"), s = e.getByText("name"), l = e.getByText("age");
52
- t(s).toBeInTheDocument(), t(l).toBeInTheDocument(), t(o).toBeInTheDocument(), t(s.compareDocumentPosition(l)).toBe(4), t(l.compareDocumentPosition(o)).toBe(4);
53
- }), d("render GenericTable with custom columnWidth in pixel", () => {
54
- i(
55
- /* @__PURE__ */ a(c, { data: [{ id: 1, name: "test", age: 20 }], customColumnWidth: { id: 200, name: 200, age: 200 } })
55
+ ] })), t(e.getByText("primText")).toBeInTheDocument(), e.getByText("primText").click(), t(d).toHaveBeenCalledWith(1);
56
+ }), i("render GenericTable with custom order", () => {
57
+ o(/* @__PURE__ */ a(s, { data: [{ id: 1, name: "test", age: 20 }], order: ["name", "age"] }));
58
+ const d = e.getByText("id"), c = e.getByText("name"), l = e.getByText("age");
59
+ t(c).toBeInTheDocument(), t(l).toBeInTheDocument(), t(d).toBeInTheDocument(), t(c.compareDocumentPosition(l)).toBe(4), t(l.compareDocumentPosition(d)).toBe(4);
60
+ }), i("render GenericTable with custom columnWidth in pixel", () => {
61
+ o(
62
+ /* @__PURE__ */ a(s, { data: [{ id: 1, name: "test", age: 20 }], customColumnWidth: { id: 200, name: 200, age: 200 } })
56
63
  );
57
- const s = e.getAllByRole("cell")[0].getAttribute("width");
58
- t(s).toBe("200");
59
- }), d("render GenericTable with custom columnWidth in percent", () => {
60
- i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], customColumnWidth: { id: "50%", name: "50%" } }));
61
- const s = e.getAllByRole("cell")[0].getAttribute("width");
62
- t(s).toBe("50%");
63
- }), d("render GenericTable with title", () => {
64
- i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], title: "test-title" })), t(e.getByText("test-title")).toBeInTheDocument();
65
- }), d("render GenericTable with title and table actions", () => {
64
+ const c = e.getAllByRole("cell")[0].getAttribute("width");
65
+ t(c).toBe("200");
66
+ }), i("render GenericTable with custom columnWidth in percent", () => {
67
+ o(/* @__PURE__ */ a(s, { data: [{ id: 1, name: "test" }], customColumnWidth: { id: "50%", name: "50%" } }));
68
+ const c = e.getAllByRole("cell")[0].getAttribute("width");
69
+ t(c).toBe("50%");
70
+ }), i("render GenericTable with title", () => {
71
+ o(/* @__PURE__ */ a(s, { data: [{ id: 1, name: "test" }], title: "test-title" })), t(e.getByText("test-title")).toBeInTheDocument();
72
+ }), i("render GenericTable with title and table actions", () => {
66
73
  const n = r.fn();
67
- i(/* @__PURE__ */ a(c, { data: [{ id: 1, name: "test" }], title: "test-title", tableActions: [
74
+ o(/* @__PURE__ */ a(s, { data: [{ id: 1, name: "test" }], title: "test-title", tableActions: [
68
75
  /* @__PURE__ */ a("button", { "data-testid": "testButton", onClick: n, children: "test-button" }, "test")
69
76
  ] })), t(e.getByText("test-title")).toBeInTheDocument(), t(e.getByText("test-button")).toBeInTheDocument(), e.getByTestId("testButton").click(), t(n).toHaveBeenCalled();
77
+ }), i("render GenericCardList instead of Table when not is desktop", () => {
78
+ r.spyOn(m, "useBreakpoints").mockReturnValue({
79
+ isDesktop: !1,
80
+ isMobile: !0,
81
+ isTablet: !1,
82
+ isDesktopNavbar: !1
83
+ }), o(/* @__PURE__ */ a(s, { data: [{ id: 1, name: "test", age: 20 }], title: "test-title", cardTitleColumn: "name" })), t(e.getAllByTestId("card-title")).toHaveLength(1), t(e.getAllByTestId("card-body")).toHaveLength(1), t(e.getAllByTestId("row")).toHaveLength(2);
70
84
  });
71
85
  });
@@ -0,0 +1,19 @@
1
+ import { GenericColumn, TableLayoutProps } from '../../types/GenericTable';
2
+ /**
3
+ * Generate columns for the table
4
+ * @param data data to be used to generate the columns
5
+ * @param order order of the columns
6
+ * @param cellTemplates cell templates to be used
7
+ * @param headerTranslation translation function for the headers
8
+ * @param getRowActions function that will be called to get the actions for a row to be displayed as actions in a context menu
9
+ * @param customColumnWidth custom column width
10
+ * @returns
11
+ */
12
+ export declare const useGenerateColumns: <T>({ data, order, cellTemplates, headerTranslation, getRowActions, customColumnWidth, cardTitleColumn, cardSubTitleColumn, }: TableLayoutProps<T>) => GenericColumn<T>[];
13
+ /**
14
+ * Adds row actions to the data for the table
15
+ * @param data data to be used to generate the columns
16
+ * @param getRowActions function that will be called to get the actions for a row to be displayed as actions in a context menu
17
+ * @returns
18
+ */
19
+ export declare const useGenerateTableData: <T>({ data, getRowActions, }: TableLayoutProps<T>) => object[];
@@ -0,0 +1,59 @@
1
+ import { jsx as d } from "react/jsx-runtime";
2
+ import { useMemo as a } from "react";
3
+ import { ContextMenu as x } from "../ContextMenu/ContextMenu.js";
4
+ const j = ({
5
+ data: r = [],
6
+ order: n = [],
7
+ cellTemplates: e = void 0,
8
+ headerTranslation: t = (c) => c,
9
+ getRowActions: f = void 0,
10
+ customColumnWidth: o,
11
+ cardTitleColumn: u,
12
+ cardSubTitleColumn: s
13
+ }) => a(() => {
14
+ if (r?.length === 0)
15
+ return [];
16
+ const c = v(r[0], n).map((i) => {
17
+ const p = o ? o[i] : void 0;
18
+ return {
19
+ id: i,
20
+ header: t(i),
21
+ accessor: i,
22
+ cellTemplate: e ? e[i] : void 0,
23
+ cellProps: p ? { width: p } : void 0,
24
+ asCardTitle: i === u,
25
+ asCardSubtitle: i === s
26
+ };
27
+ });
28
+ return f ? [
29
+ ...c,
30
+ { id: "actions", header: "", accessor: "actions" }
31
+ ] : c;
32
+ }, [
33
+ r,
34
+ e,
35
+ n,
36
+ t,
37
+ f,
38
+ o,
39
+ u,
40
+ s
41
+ ]), l = ({
42
+ data: r = [],
43
+ getRowActions: n = void 0
44
+ }) => a(() => n ? r.map((e) => {
45
+ const t = /* @__PURE__ */ d(x, { actions: n(e), iconOrientation: "horizontal" });
46
+ return { ...e, actions: t };
47
+ }) : r, [r, n]), v = (r, n) => {
48
+ if (!r)
49
+ return [];
50
+ let e = Object.keys(r).map((t) => t);
51
+ return n?.length > 0 && (e = e.sort((t, f) => {
52
+ const o = n.findIndex((s) => s === t), u = n.findIndex((s) => s === f);
53
+ return o === -1 ? 1 : u === -1 ? -1 : o - u;
54
+ })), e;
55
+ };
56
+ export {
57
+ j as useGenerateColumns,
58
+ l as useGenerateTableData
59
+ };
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ import { GenericColumn } from '../../../types/GenericTable';
3
+ type GenericCardProps<T> = {
4
+ item: T & {
5
+ actions?: JSX.Element;
6
+ };
7
+ columns: GenericColumn<T>[];
8
+ hiddenColumns?: (keyof T)[];
9
+ };
10
+ /**
11
+ * Renders a generic card component.
12
+ *
13
+ * @template T - The type of the item being rendered.
14
+ * @param item - The item to be rendered in the card.
15
+ * @param columns - The columns to be displayed in the card.
16
+ * @returns {JSX.Element} - The rendered GenericCard component.
17
+ */
18
+ export declare const GenericCard: <T>({ item, columns, hiddenColumns }: GenericCardProps<T>) => import("react/jsx-runtime").JSX.Element;
19
+ export {};
@@ -0,0 +1,68 @@
1
+ import { jsx as e, jsxs as s, Fragment as T } from "react/jsx-runtime";
2
+ import { Card as g, CardContent as y, CardBody as x, Grid as v, GridRow as u, GridCol as n, TypoSubtitle as f, CardTitle as N, CardDivider as b } from "@element/react-components";
3
+ import { useMemo as k } from "react";
4
+ import { OverflowTooltip as c } from "../../OverflowTooltip/OverflowTooltip.js";
5
+ import { s as d } from "../../../genericCard.module-DzqcufuN.js";
6
+ const h = {
7
+ desktopCol: 6,
8
+ phoneCol: 2,
9
+ tabletCol: 4
10
+ }, j = ({ item: t, columns: r, hiddenColumns: a }) => {
11
+ const l = r.find((i) => i.asCardTitle), p = r.find((i) => i.asCardSubtitle), C = k(
12
+ () => r.filter(
13
+ (i) => !i.asCardTitle && !i.asCardSubtitle && i.id !== "actions"
14
+ ),
15
+ [r]
16
+ );
17
+ return /* @__PURE__ */ e(g, { variant: "raised", children: /* @__PURE__ */ s(y, { className: d.cardContent, children: [
18
+ /* @__PURE__ */ e(w, { item: t, titleColumn: l, subTitleColumn: p }),
19
+ /* @__PURE__ */ e(x, { className: d.cardBody, "data-testid": "card-body", children: /* @__PURE__ */ e(v, { fullHeight: !0, fullWidth: !0, variant: "none", children: C.map((i) => a?.includes(i.id) ? null : /* @__PURE__ */ s(u, { className: d.row, "data-testid": "row", children: [
20
+ /* @__PURE__ */ e(n, { horizontalAlign: "right", ...h, children: /* @__PURE__ */ s(
21
+ f,
22
+ {
23
+ level: 2,
24
+ themeColor: "text-secondary-on-background",
25
+ className: d.font,
26
+ children: [
27
+ i.header,
28
+ ":"
29
+ ]
30
+ }
31
+ ) }),
32
+ /* @__PURE__ */ e(n, { horizontalAlign: "left", ...h, children: /* @__PURE__ */ e(o, { column: i, item: t }) })
33
+ ] }, i.id)) }) })
34
+ ] }) });
35
+ }, w = ({ item: t, titleColumn: r, subTitleColumn: a }) => {
36
+ const l = t.actions;
37
+ return !r && !a && !l ? null : /* @__PURE__ */ s(T, { children: [
38
+ /* @__PURE__ */ e(
39
+ N,
40
+ {
41
+ "data-testid": "card-title",
42
+ className: d.cardTitle,
43
+ primaryText: r !== void 0 && /* @__PURE__ */ e(o, { column: r, item: t, isTitle: !0 }),
44
+ secondaryText: a !== void 0 && /* @__PURE__ */ e(o, { column: a, item: t, isTitle: !0 }),
45
+ trailingBlock: l,
46
+ trailingBlockType: "title-actions"
47
+ }
48
+ ),
49
+ /* @__PURE__ */ e(b, {})
50
+ ] });
51
+ }, o = ({ item: t, column: r, isTitle: a = !1 }) => r.cellTemplate ? r.cellTemplate({ row: { original: t } }) : a ? /* @__PURE__ */ e(
52
+ c,
53
+ {
54
+ id: `tip_${r.id}_${t[r.accessor]}`,
55
+ text: t[r.accessor],
56
+ children: /* @__PURE__ */ e("span", { className: d.title, children: t[r.accessor] })
57
+ }
58
+ ) : /* @__PURE__ */ e(
59
+ c,
60
+ {
61
+ id: `tip_${r.id}_${t[r.accessor]}`,
62
+ text: t[r.accessor],
63
+ children: /* @__PURE__ */ e(f, { level: 2, themeColor: "text-primary-on-background", className: d.font, children: t[r.accessor] })
64
+ }
65
+ );
66
+ export {
67
+ j as GenericCard
68
+ };
@@ -0,0 +1,76 @@
1
+ import { jsx as n } from "react/jsx-runtime";
2
+ import { a as c, s as o } from "../../../react.esm-Dy4VzU4L.js";
3
+ import { GenericCard as i } from "./GenericCard.js";
4
+ import { d as m, t as s, g as e } from "../../../vi.JYQecGiw-BbUbJcT8.js";
5
+ m("GenericCard", () => {
6
+ const d = {
7
+ id: 1,
8
+ name: "John Doe",
9
+ age: 30,
10
+ gender: "male",
11
+ actions: /* @__PURE__ */ n("button", { children: "View" })
12
+ }, l = [
13
+ { id: "name", header: "Name", accessor: "name", asCardTitle: !0 },
14
+ { id: "age", header: "Age", accessor: "age", asCardSubtitle: !0 },
15
+ { id: "id", header: "Id", accessor: "id" },
16
+ { id: "gender", header: "Gender", accessor: "gender" }
17
+ ];
18
+ s("renders card title with correct primary text", () => {
19
+ c(/* @__PURE__ */ n(i, { item: d, columns: l }));
20
+ const t = o.getByTestId("card-title");
21
+ e(t).toHaveTextContent("John Doe");
22
+ }), s("renders card title with correct secondary text", () => {
23
+ c(/* @__PURE__ */ n(i, { item: d, columns: l }));
24
+ const r = o.getByTestId("card-title").querySelector(".lmnt-card-title__secondaryText");
25
+ e(r).toHaveTextContent("30");
26
+ }), s("renders actions in trailing block", () => {
27
+ c(/* @__PURE__ */ n(i, { item: d, columns: l }));
28
+ const r = o.getByTestId("card-title").querySelector(".lmnt-card-title__trailingBlock");
29
+ e(r).toContainHTML("<button>View</button>");
30
+ }), s("renders card body with correct number of rows", () => {
31
+ c(/* @__PURE__ */ n(i, { item: d, columns: l }));
32
+ const t = o.getAllByTestId("row");
33
+ e(t).toHaveLength(2);
34
+ }), s("renders correct header and value in each row", () => {
35
+ c(/* @__PURE__ */ n(i, { item: d, columns: l })), e(o.getByText("Id:")).toBeInTheDocument(), e(o.getByText("1")).toBeInTheDocument(), e(o.getByText("Gender:")).toBeInTheDocument(), e(o.getByText("male")).toBeInTheDocument();
36
+ }), s("does not render title, subtitle or actions columns in body", () => {
37
+ c(/* @__PURE__ */ n(i, { item: d, columns: l }));
38
+ const t = o.getByTestId("card-body");
39
+ e(t).not.toHaveTextContent("Name:"), e(t).not.toHaveTextContent("John Doe"), e(t).not.toHaveTextContent("Age:"), e(t).not.toHaveTextContent("30"), e(t).not.toContainHTML("<button>View</button>");
40
+ }), s("renders cell template if provided", () => {
41
+ const t = [
42
+ ...l.filter((a) => a.id !== "name"),
43
+ {
44
+ id: "name",
45
+ header: "Name",
46
+ accessor: "name",
47
+ asCardTitle: !0,
48
+ cellTemplate: ({ row: a }) => /* @__PURE__ */ n("div", { children: a.original.name.toUpperCase() })
49
+ }
50
+ ];
51
+ c(/* @__PURE__ */ n(i, { item: d, columns: t }));
52
+ const r = o.getByTestId("card-title");
53
+ e(r).toHaveTextContent("JOHN DOE");
54
+ }), s("renders no title cells if no title/subtitle column is provided, render them in body instead", () => {
55
+ c(/* @__PURE__ */ n(i, { item: d, columns: [
56
+ { id: "name", header: "Name", accessor: "name" },
57
+ { id: "age", header: "Age", accessor: "age" },
58
+ { id: "id", header: "Id", accessor: "id" },
59
+ { id: "gender", header: "Gender", accessor: "gender" }
60
+ ] }));
61
+ const r = o.queryByTestId("card-title");
62
+ e(r).not.toHaveTextContent("John Doe"), e(r).not.toHaveTextContent("30");
63
+ const a = o.getByTestId("card-body");
64
+ e(a).toHaveTextContent("Name:"), e(a).toHaveTextContent("John Doe"), e(a).toHaveTextContent("Age:"), e(a).toHaveTextContent("30");
65
+ }), s("renders no card title cells if no title/subtitle/action column is provided", () => {
66
+ const t = [
67
+ { id: "name", header: "Name", accessor: "name" },
68
+ { id: "age", header: "Age", accessor: "age" },
69
+ { id: "id", header: "Id", accessor: "id" },
70
+ { id: "gender", header: "Gender", accessor: "gender" }
71
+ ], r = { ...d, actions: void 0 };
72
+ c(/* @__PURE__ */ n(i, { item: r, columns: t }));
73
+ const a = o.queryByTestId("card-title");
74
+ e(a).not.toBeInTheDocument();
75
+ });
76
+ });
@@ -0,0 +1,22 @@
1
+ /// <reference types="react" />
2
+ import { GenericColumn, TableLayoutProps } from '../../../types/GenericTable';
3
+ type GenericCardListProps<T> = Pick<TableLayoutProps<T>, 'hiddenColumns' | 'noContentText' | 'data'> & {
4
+ /**
5
+ * The columns to be displayed in the card.
6
+ */
7
+ columns: GenericColumn<T>[];
8
+ };
9
+ /**
10
+ * Renders a list of generic cards based on the provided data.
11
+ *
12
+ * @template T - The type of data for each card.
13
+ * @param columns - The columns to be displayed in the card.
14
+ * @param data - The data to be displayed in the cards.
15
+ * @param hiddenColumns - The columns to be hidden in the card.
16
+ * @param order - The order of the columns to be displayed in the card.
17
+ * @param noContentText - The text to be displayed when there is no data.
18
+ *
19
+ * @returns {JSX.Element} The rendered list of generic cards.
20
+ */
21
+ export declare const GenericCardList: <T>({ columns, data, hiddenColumns, noContentText, }: GenericCardListProps<T>) => JSX.Element;
22
+ export {};
@@ -0,0 +1,20 @@
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { Group as l } from "@element/react-components";
3
+ import { GenericCard as m } from "./GenericCard.js";
4
+ const f = ({
5
+ columns: i,
6
+ data: e,
7
+ hiddenColumns: n = [],
8
+ noContentText: t
9
+ }) => e?.length === 0 ? /* @__PURE__ */ r("div", { children: t }) : /* @__PURE__ */ r(l, { fullWidth: !0, direction: "vertical", primaryAlign: "center", secondaryAlign: "center", children: e?.map((o, c) => /* @__PURE__ */ r(
10
+ m,
11
+ {
12
+ item: o,
13
+ columns: i,
14
+ hiddenColumns: n
15
+ },
16
+ c
17
+ )) });
18
+ export {
19
+ f as GenericCardList
20
+ };