@harpercollins/harpercollins-design-system 1.34.0 → 1.35.2

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 (32) hide show
  1. package/dist/cjs/components/data-display/DataGrid/DataGrid.cjs +1 -0
  2. package/dist/cjs/components/data-display/DataGrid/hooks/useDataGrid.cjs +1 -0
  3. package/dist/cjs/components/data-display/Table/Table.cjs +1 -1
  4. package/dist/cjs/components/data-display/Table/TableHeader.cjs +1 -1
  5. package/dist/cjs/components/data-display/Table/TableLayout.cjs +1 -0
  6. package/dist/cjs/hooks/useServerSideTableState.cjs +1 -1
  7. package/dist/cjs/index.cjs +1 -1
  8. package/dist/esm/components/data-display/DataGrid/DataGrid.js +70 -0
  9. package/dist/esm/components/data-display/DataGrid/hooks/useDataGrid.js +189 -0
  10. package/dist/esm/components/data-display/Table/Table.js +51 -295
  11. package/dist/esm/components/data-display/Table/TableHeader.js +1 -1
  12. package/dist/esm/components/data-display/Table/TableLayout.js +112 -0
  13. package/dist/esm/hooks/useServerSideTableState.js +1 -1
  14. package/dist/esm/index.js +192 -190
  15. package/dist/index.d.ts +66 -25
  16. package/package.json +1 -1
  17. package/dist/cjs/components/data-display/Table/index.cjs +0 -1
  18. package/dist/esm/components/data-display/Table/index.js +0 -4
  19. /package/dist/cjs/components/data-display/{Table → DataGrid}/ExportToExcelButton.cjs +0 -0
  20. /package/dist/cjs/components/data-display/{Table → DataGrid}/FilterChipsSection.cjs +0 -0
  21. /package/dist/cjs/components/data-display/{Table → DataGrid}/TableToolbar.cjs +0 -0
  22. /package/dist/cjs/components/data-display/{Table → DataGrid}/filters/FilterComponents.cjs +0 -0
  23. /package/dist/cjs/components/data-display/{Table → DataGrid}/filters/filterFunctions.cjs +0 -0
  24. /package/dist/cjs/components/data-display/{Table → DataGrid}/hooks/useInfiniteScroll.cjs +0 -0
  25. /package/dist/cjs/components/data-display/{Table → DataGrid}/tableUrlUtils.cjs +0 -0
  26. /package/dist/esm/components/data-display/{Table → DataGrid}/ExportToExcelButton.js +0 -0
  27. /package/dist/esm/components/data-display/{Table → DataGrid}/FilterChipsSection.js +0 -0
  28. /package/dist/esm/components/data-display/{Table → DataGrid}/TableToolbar.js +0 -0
  29. /package/dist/esm/components/data-display/{Table → DataGrid}/filters/FilterComponents.js +0 -0
  30. /package/dist/esm/components/data-display/{Table → DataGrid}/filters/filterFunctions.js +0 -0
  31. /package/dist/esm/components/data-display/{Table → DataGrid}/hooks/useInfiniteScroll.js +0 -0
  32. /package/dist/esm/components/data-display/{Table → DataGrid}/tableUrlUtils.js +0 -0
@@ -1,302 +1,58 @@
1
- import { jsxs as h, Fragment as Se, jsx as i } from "react/jsx-runtime";
2
- import { useReactTable as he, flexRender as pe } from "../../../node_modules/.pnpm/@tanstack_react-table@8.21.3_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@tanstack/react-table/build/lib/index.js";
3
- import r from "react";
4
- import { useLocalStorage as Re } from "../../../hooks/useLocalStorage.js";
5
- import Ce from "../../feedback/Alert/Alert.js";
6
- import L from "../../feedback/CircularProgress/CircularProgress.js";
7
- import j from "../../inputs/Checkbox/Checkbox.js";
8
- import we from "../Typography/Typography.js";
9
- import Fe from "./StickyHorizontalScrollbar.js";
10
- import { LoadingOverlay as ze, TableWrapper as xe, getTableStyles as ye } from "./Table.styles.js";
11
- import { TableBody as Me } from "./TableBody.js";
12
- import be from "./TableHeader.js";
13
- import ve from "./TableToolbar.js";
14
- import { multiSelectFilter as ke, selectFilter as He, dateFilter as Ee, numericFilter as Ie, textFilter as Be } from "./filters/filterFunctions.js";
15
- import { useInfiniteScroll as Ne } from "./hooks/useInfiniteScroll.js";
16
- import { useStickyHeader as Te } from "./hooks/useStickyHeader.js";
17
- import { useStickyScrollbar as $e } from "./hooks/useStickyScrollbar.js";
18
- import { extractColumnFilterTypes as P, parseSortingFromUrl as Ae, parseFiltersFromUrl as Le, syncStateToUrl as Pe } from "./tableUrlUtils.js";
19
- import D from "../../../node_modules/.pnpm/@mui_joy@5.0.0-beta.52_@emotion_react@11.14.0_@types_react@18.3.28_react@18.3.1__@emoti_58201694b486b0db36cbf79098c4edaa/node_modules/@mui/joy/Box/Box.js";
20
- import De from "../../../node_modules/.pnpm/@mui_joy@5.0.0-beta.52_@emotion_react@11.14.0_@types_react@18.3.28_react@18.3.1__@emoti_58201694b486b0db36cbf79098c4edaa/node_modules/@mui/joy/Table/Table.js";
21
- import { getFilteredRowModel as je, getSortedRowModel as Ge, getCoreRowModel as Ve } from "../../../node_modules/.pnpm/@tanstack_table-core@8.21.3/node_modules/@tanstack/table-core/build/lib/index.js";
22
- function We({ table: s }) {
23
- return /* @__PURE__ */ i(
24
- j,
25
- {
26
- checked: s.getIsAllRowsSelected(),
27
- indeterminate: s.getIsSomeRowsSelected(),
28
- onChange: (a) => s.toggleAllRowsSelected(a.target.checked),
29
- size: "md"
30
- }
31
- );
32
- }
33
- function _e({ row: s }) {
34
- return /* @__PURE__ */ i(
35
- j,
36
- {
37
- checked: s.getIsSelected(),
38
- disabled: !s.getCanSelect(),
39
- onChange: (a) => s.toggleSelected(a.target.checked),
40
- size: "md"
41
- }
42
- );
43
- }
44
- function dt({
45
- id: s,
46
- loading: a = !1,
47
- maxHeight: w = !1,
48
- wrapText: G = !1,
49
- rowRender: V,
50
- reactTableOptions: o,
51
- gridCheckboxes: p = !1,
52
- allSelected: F = !1,
53
- onSelectionChange: z,
54
- showStickyScrollbar: W = !1,
55
- enableStickyHeader: _ = !1,
56
- stickyHeaderOffset: U = 0,
57
- infiniteScroll: c,
58
- toolbar: x,
59
- footer: q,
60
- isError: J = !1,
61
- errorMessage: K = "An error occurred while loading data. Please try again.",
62
- syncUrl: f = !1,
63
- urlParamPrefix: S = ""
1
+ import { jsx as a } from "react/jsx-runtime";
2
+ import h from "../DataGrid/DataGrid.js";
3
+ import j from "./TableLayout.js";
4
+ function G({
5
+ id: e,
6
+ loading: r = !1,
7
+ maxHeight: l = !1,
8
+ wrapText: f = !1,
9
+ rowRender: o,
10
+ reactTableOptions: s,
11
+ gridCheckboxes: t = !1,
12
+ allSelected: i = !1,
13
+ onSelectionChange: n,
14
+ showStickyScrollbar: d = !1,
15
+ enableStickyHeader: m = !1,
16
+ stickyHeaderOffset: u = 0,
17
+ infiniteScroll: p,
18
+ toolbar: c,
19
+ footer: y,
20
+ isError: b = !1,
21
+ errorMessage: g = "An error occurred while loading data. Please try again.",
22
+ syncUrl: x = !1,
23
+ urlParamPrefix: L = ""
64
24
  }) {
65
- const { columns: m } = o, Q = r.useRef(
66
- P(m)
67
- ), [y, X] = r.useState(() => {
68
- if (f && typeof window < "u") {
69
- const e = new URLSearchParams(window.location.search);
70
- return Ae(e, S);
71
- }
72
- return [];
73
- }), [M, Y] = r.useState(
74
- () => {
75
- if (f && typeof window < "u") {
76
- const e = new URLSearchParams(window.location.search);
77
- return Le(
78
- e,
79
- S,
80
- Q.current
81
- );
82
- }
83
- return [];
84
- }
85
- ), [Z, O] = Re(
86
- `table.${s}.columnSizing`,
87
- {}
88
- ), [ee, te] = r.useState({}), oe = r.useCallback(
89
- (e) => {
90
- te((t) => {
91
- const n = typeof e == "function" ? e(t) : e;
92
- return z?.(n), n;
93
- });
94
- },
95
- [z]
96
- ), b = r.useRef(null), R = r.useRef(o.data), ne = a && R.current.length > 0 ? R.current : o.data;
97
- r.useEffect(() => {
98
- !a && o.data.length > 0 && (R.current = o.data);
99
- }, [a, o.data]);
100
- const d = r.useRef(null), v = r.useRef(null), k = r.useRef(null), re = $e(d), le = Te({
101
- enabled: _,
102
- stickyHeaderOffset: U,
103
- tableWrapperRef: d,
104
- theadRef: v,
105
- toolbarRef: k
106
- }), ie = r.useMemo(() => {
107
- const e = [], t = [];
108
- return m.forEach((n) => {
109
- n.meta?.pinned === "left" && n.id ? e.push(n.id) : n.meta?.pinned === "right" && n.id && t.push(n.id);
110
- }), { left: e, right: t };
111
- }, [m]), se = r.useMemo(() => {
112
- let e = [...m];
113
- return e = e.map((t) => {
114
- const n = t.meta?.filterType;
115
- return n && !t.filterFn ? {
116
- ...t,
117
- filterFn: {
118
- text: Be,
119
- number: Ie,
120
- date: Ee,
121
- select: He,
122
- multiselect: ke
123
- }[n]
124
- } : t;
125
- }), p && (e = [{
126
- id: "select",
127
- size: 26,
128
- enableSorting: !1,
129
- enableResizing: !1,
130
- meta: { noSortButton: !0 },
131
- header: We,
132
- cell: _e
133
- }, ...e]), e;
134
- }, [p, m]), l = he({
135
- // Overridable defaults
136
- columnResizeDirection: "ltr",
137
- defaultColumn: { size: 200, minSize: 20, maxSize: 500 },
138
- // Consumer customisation
139
- ...o,
140
- // Values always controlled by this component
141
- getCoreRowModel: Ve(),
142
- getSortedRowModel: Ge(),
143
- getFilteredRowModel: je(),
144
- columns: se,
145
- data: ne,
146
- enableSorting: o.enableSorting ?? !0,
147
- enableColumnResizing: o.enableColumnResizing ?? !0,
148
- columnResizeMode: o.columnResizeMode ?? "onChange",
149
- onColumnSizingChange: o.onColumnSizingChange ?? O,
150
- onSortingChange: o.onSortingChange ?? X,
151
- onColumnFiltersChange: o.onColumnFiltersChange ?? Y,
152
- enableRowSelection: p,
153
- onRowSelectionChange: o.onRowSelectionChange ?? oe,
154
- state: {
155
- ...o.state,
156
- rowSelection: o.state?.rowSelection ?? ee,
157
- sorting: o.state?.sorting ?? y,
158
- columnFilters: o.state?.columnFilters ?? M,
159
- columnSizing: Z,
160
- columnPinning: ie
161
- }
162
- }), { rows: H } = l.getRowModel(), {
163
- enabled: g,
164
- virtualItems: ae,
165
- paddingTop: ce,
166
- paddingBottom: me,
167
- measureElement: ue
168
- } = Ne(H.length, c, d), E = c?.enabled, I = c?.hasNextPage, B = c?.isFetchingNextPage, N = c?.fetchNextPage, de = 200, C = r.useCallback(
169
- (e) => {
170
- if (!e || !E) return;
171
- const { scrollHeight: t, scrollTop: n, clientHeight: u } = e;
172
- t - n - u < de && !B && I && N?.();
173
- },
174
- [E, I, B, N]
175
- );
176
- r.useEffect(() => {
177
- C(d.current);
178
- }, [C]), b.current = l, r.useEffect(() => {
179
- b.current?.toggleAllRowsSelected(F);
180
- }, [F]);
181
- const T = o.state?.sorting ?? y, $ = o.state?.columnFilters ?? M, A = r.useMemo(
182
- () => P(
183
- m
184
- ),
185
- [m]
186
- );
187
- r.useEffect(() => {
188
- !f || typeof window > "u" || Pe(
189
- T,
190
- $,
191
- S,
192
- A
193
- );
194
- }, [
195
- f,
196
- T,
197
- $,
198
- S,
199
- A
200
- ]);
201
- const ge = r.useMemo(() => {
202
- const e = l.getFlatHeaders(), t = {};
203
- for (let n = 0; n < e.length; n += 1) {
204
- const u = e[n];
205
- t[`--${s}-header-${u.id}-size`] = u.getSize(), t[`--${s}-col-${u.column.id}-size`] = u.column.getSize();
206
- }
207
- return t;
208
- }, [s, l.getState().columnSizingInfo, l.getState().columnSizing]), fe = r.useMemo(() => l.getFlatHeaders().reduce((t, n) => t + n.getSize(), 0), [l.getState().columnSizingInfo, l.getState().columnSizing]);
209
- return /* @__PURE__ */ h(Se, { children: [
210
- J && /* @__PURE__ */ i(Ce, { color: "danger", sx: { marginBottom: 1 }, children: K }),
211
- x?.enabled && /* @__PURE__ */ i(
212
- ve,
213
- {
214
- ref: k,
215
- toolbar: x,
216
- columnFilters: l.getState().columnFilters,
217
- table: l
218
- }
219
- ),
220
- /* @__PURE__ */ h(D, { sx: { position: "relative" }, children: [
221
- a && /* @__PURE__ */ i(ze, { children: /* @__PURE__ */ i(L, {}) }),
222
- /* @__PURE__ */ i(
223
- xe,
25
+ return /* @__PURE__ */ a(
26
+ h,
27
+ {
28
+ id: e,
29
+ loading: r,
30
+ reactTableOptions: s,
31
+ gridCheckboxes: t,
32
+ allSelected: i,
33
+ onSelectionChange: n,
34
+ infiniteScroll: p,
35
+ toolbar: c,
36
+ isError: b,
37
+ errorMessage: g,
38
+ syncUrl: x,
39
+ urlParamPrefix: L,
40
+ renderLayout: (T) => /* @__PURE__ */ a(
41
+ j,
224
42
  {
225
- ref: d,
226
- "data-testid": "table-wrapper",
227
- $maxHeight: w,
228
- onScroll: (e) => C(e.currentTarget),
229
- children: /* @__PURE__ */ h(
230
- De,
231
- {
232
- hoverRow: !0,
233
- "data-testid": s,
234
- sx: ye(
235
- ge,
236
- fe,
237
- G,
238
- le,
239
- w
240
- ),
241
- children: [
242
- /* @__PURE__ */ i(
243
- be,
244
- {
245
- headerGroups: l.getHeaderGroups(),
246
- id: s,
247
- theadRef: v
248
- }
249
- ),
250
- /* @__PURE__ */ i(
251
- Me,
252
- {
253
- rows: H,
254
- columns: l.getAllColumns(),
255
- rowRender: V,
256
- loading: a,
257
- rowSelectionState: l.getState().rowSelection,
258
- virtualItems: g ? ae : void 0,
259
- paddingTop: g ? ce : void 0,
260
- paddingBottom: g ? me : void 0,
261
- measureElement: g ? ue : void 0
262
- }
263
- ),
264
- q && l.getFooterGroups().length > 0 && /* @__PURE__ */ i("tfoot", { children: l.getFooterGroups().map((e) => /* @__PURE__ */ i("tr", { children: e.headers.map((t) => /* @__PURE__ */ i("td", { colSpan: t.colSpan, children: pe(
265
- t.column.columnDef.footer,
266
- t.getContext()
267
- ) }, t.id)) }, e.id)) })
268
- ]
269
- }
270
- )
43
+ ctx: T,
44
+ maxHeight: l,
45
+ wrapText: f,
46
+ rowRender: o,
47
+ showStickyScrollbar: d,
48
+ enableStickyHeader: m,
49
+ stickyHeaderOffset: u,
50
+ footer: y
271
51
  }
272
52
  )
273
- ] }),
274
- g && c?.isFetchingNextPage && /* @__PURE__ */ h(
275
- D,
276
- {
277
- sx: {
278
- display: "flex",
279
- justifyContent: "center",
280
- alignItems: "center",
281
- gap: 1,
282
- padding: 1
283
- },
284
- children: [
285
- /* @__PURE__ */ i(L, { size: "sm" }),
286
- /* @__PURE__ */ i(we, { children: c.loadingText ?? "Loading more..." })
287
- ]
288
- }
289
- ),
290
- W && /* @__PURE__ */ i(
291
- Fe,
292
- {
293
- scrollContainerRef: d,
294
- visible: re,
295
- constrainToContainer: "main"
296
- }
297
- )
298
- ] });
53
+ }
54
+ );
299
55
  }
300
56
  export {
301
- dt as default
57
+ G as default
302
58
  };
@@ -4,7 +4,7 @@ import { flexRender as l } from "../../../node_modules/.pnpm/@tanstack_react-tab
4
4
  import t from "../Icon/Icon.js";
5
5
  import { HeaderContent as S, SortButton as C, ColumnHeaderContainer as z } from "./Table.styles.js";
6
6
  import { SortDirection as a } from "./Table.types.js";
7
- import { ColumnFilter as D } from "./filters/FilterComponents.js";
7
+ import { ColumnFilter as D } from "../DataGrid/filters/FilterComponents.js";
8
8
  function w({
9
9
  headerGroups: s,
10
10
  id: u,
@@ -0,0 +1,112 @@
1
+ import { jsxs as u, Fragment as I, jsx as r } from "react/jsx-runtime";
2
+ import { flexRender as G } from "../../../node_modules/.pnpm/@tanstack_react-table@8.21.3_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@tanstack/react-table/build/lib/index.js";
3
+ import c from "react";
4
+ import M from "./StickyHorizontalScrollbar.js";
5
+ import { TableWrapper as V, getTableStyles as W } from "./Table.styles.js";
6
+ import { TableBody as j } from "./TableBody.js";
7
+ import E from "./TableHeader.js";
8
+ import { useStickyHeader as _ } from "./hooks/useStickyHeader.js";
9
+ import { useStickyScrollbar as A } from "./hooks/useStickyScrollbar.js";
10
+ import D from "../../../node_modules/.pnpm/@mui_joy@5.0.0-beta.52_@emotion_react@11.14.0_@types_react@18.3.28_react@18.3.1__@emoti_58201694b486b0db36cbf79098c4edaa/node_modules/@mui/joy/Table/Table.js";
11
+ function Y({
12
+ ctx: p,
13
+ maxHeight: d = !1,
14
+ wrapText: f = !1,
15
+ rowRender: g,
16
+ showStickyScrollbar: S = !1,
17
+ enableStickyHeader: h = !1,
18
+ stickyHeaderOffset: b = 0,
19
+ footer: z
20
+ }) {
21
+ const {
22
+ id: a,
23
+ table: e,
24
+ rows: T,
25
+ isVirtual: i,
26
+ virtualItems: R,
27
+ paddingTop: v,
28
+ paddingBottom: y,
29
+ measureElement: w,
30
+ wrapperRef: n,
31
+ toolbarRef: x,
32
+ loading: H,
33
+ fetchMoreOnBottomReached: k
34
+ } = p, m = c.useRef(null), F = A(n), $ = _({
35
+ enabled: h,
36
+ stickyHeaderOffset: b,
37
+ tableWrapperRef: n,
38
+ theadRef: m,
39
+ toolbarRef: x
40
+ }), B = c.useMemo(() => {
41
+ const o = e.getFlatHeaders(), t = {};
42
+ for (let l = 0; l < o.length; l += 1) {
43
+ const s = o[l];
44
+ t[`--${a}-header-${s.id}-size`] = s.getSize(), t[`--${a}-col-${s.column.id}-size`] = s.column.getSize();
45
+ }
46
+ return t;
47
+ }, [a, e.getState().columnSizingInfo, e.getState().columnSizing]), C = c.useMemo(() => e.getFlatHeaders().reduce((t, l) => t + l.getSize(), 0), [e.getState().columnSizingInfo, e.getState().columnSizing]);
48
+ return /* @__PURE__ */ u(I, { children: [
49
+ /* @__PURE__ */ r(
50
+ V,
51
+ {
52
+ ref: n,
53
+ "data-testid": "table-wrapper",
54
+ $maxHeight: d,
55
+ onScroll: (o) => k(o.currentTarget),
56
+ children: /* @__PURE__ */ u(
57
+ D,
58
+ {
59
+ hoverRow: !0,
60
+ "data-testid": a,
61
+ sx: W(
62
+ B,
63
+ C,
64
+ f,
65
+ $,
66
+ d
67
+ ),
68
+ children: [
69
+ /* @__PURE__ */ r(
70
+ E,
71
+ {
72
+ headerGroups: e.getHeaderGroups(),
73
+ id: a,
74
+ theadRef: m
75
+ }
76
+ ),
77
+ /* @__PURE__ */ r(
78
+ j,
79
+ {
80
+ rows: T,
81
+ columns: e.getAllColumns(),
82
+ rowRender: g,
83
+ loading: H,
84
+ rowSelectionState: e.getState().rowSelection,
85
+ virtualItems: i ? R : void 0,
86
+ paddingTop: i ? v : void 0,
87
+ paddingBottom: i ? y : void 0,
88
+ measureElement: i ? w : void 0
89
+ }
90
+ ),
91
+ z && e.getFooterGroups().length > 0 && /* @__PURE__ */ r("tfoot", { children: e.getFooterGroups().map((o) => /* @__PURE__ */ r("tr", { children: o.headers.map((t) => /* @__PURE__ */ r("td", { colSpan: t.colSpan, children: G(
92
+ t.column.columnDef.footer,
93
+ t.getContext()
94
+ ) }, t.id)) }, o.id)) })
95
+ ]
96
+ }
97
+ )
98
+ }
99
+ ),
100
+ S && /* @__PURE__ */ r(
101
+ M,
102
+ {
103
+ scrollContainerRef: n,
104
+ visible: F,
105
+ constrainToContainer: "main"
106
+ }
107
+ )
108
+ ] });
109
+ }
110
+ export {
111
+ Y as default
112
+ };
@@ -1,5 +1,5 @@
1
1
  import { useState as f, useRef as d, useEffect as h } from "react";
2
- import { extractColumnFilterTypes as U, parseSortingFromUrl as P, parseFiltersFromUrl as T, syncStateToUrl as C, buildSortQueryString as R, buildFilterQueryString as x } from "../components/data-display/Table/tableUrlUtils.js";
2
+ import { extractColumnFilterTypes as U, parseSortingFromUrl as P, parseFiltersFromUrl as T, syncStateToUrl as C, buildSortQueryString as R, buildFilterQueryString as x } from "../components/data-display/DataGrid/tableUrlUtils.js";
3
3
  const L = (m = {}) => {
4
4
  const {
5
5
  initialSortField: s,