@harpercollins/harpercollins-design-system 1.32.0 → 1.34.0

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 (22) hide show
  1. package/dist/cjs/components/data-display/Table/Table.cjs +1 -1
  2. package/dist/cjs/components/data-display/Table/Table.styles.cjs +2 -2
  3. package/dist/cjs/components/data-display/Table/TableHeader.cjs +1 -0
  4. package/dist/cjs/components/data-display/Table/TableToolbar.cjs +1 -1
  5. package/dist/cjs/components/data-display/Table/tableUrlUtils.cjs +1 -0
  6. package/dist/cjs/components/feedback/LinearProgress/LinearProgress.cjs +1 -0
  7. package/dist/cjs/hooks/useServerSideTableState.cjs +1 -0
  8. package/dist/cjs/index.cjs +1 -1
  9. package/dist/cjs/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/LinearProgress/LinearProgress.cjs +29 -0
  10. package/dist/cjs/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/LinearProgress/linearProgressClasses.cjs +1 -0
  11. package/dist/esm/components/data-display/Table/Table.js +226 -277
  12. package/dist/esm/components/data-display/Table/Table.styles.js +4 -5
  13. package/dist/esm/components/data-display/Table/TableHeader.js +92 -0
  14. package/dist/esm/components/data-display/Table/TableToolbar.js +10 -8
  15. package/dist/esm/components/data-display/Table/tableUrlUtils.js +108 -0
  16. package/dist/esm/components/feedback/LinearProgress/LinearProgress.js +8 -0
  17. package/dist/esm/hooks/useServerSideTableState.js +47 -0
  18. package/dist/esm/index.js +184 -178
  19. package/dist/esm/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/LinearProgress/LinearProgress.js +262 -0
  20. package/dist/esm/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/LinearProgress/linearProgressClasses.js +8 -0
  21. package/dist/index.d.ts +128 -1
  22. package/package.json +1 -1
@@ -0,0 +1,92 @@
1
+ import { jsx as n, Fragment as p, jsxs as r } from "react/jsx-runtime";
2
+ import { faArrowDown as c, faArrowUp as m } from "../../../node_modules/.pnpm/@fortawesome_free-solid-svg-icons@6.7.2/node_modules/@fortawesome/free-solid-svg-icons/index.js";
3
+ import { flexRender as l } 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";
4
+ import t from "../Icon/Icon.js";
5
+ import { HeaderContent as S, SortButton as C, ColumnHeaderContainer as z } from "./Table.styles.js";
6
+ import { SortDirection as a } from "./Table.types.js";
7
+ import { ColumnFilter as D } from "./filters/FilterComponents.js";
8
+ function w({
9
+ headerGroups: s,
10
+ id: u,
11
+ theadRef: d
12
+ }) {
13
+ return /* @__PURE__ */ n(p, { children: s.map((o) => /* @__PURE__ */ n("thead", { ref: d, children: /* @__PURE__ */ n("tr", { children: o.headers.map((e, f) => {
14
+ const g = f === o.headers.length - 1, i = e.column.getIsPinned();
15
+ return /* @__PURE__ */ r(
16
+ "th",
17
+ {
18
+ colSpan: e.colSpan,
19
+ "data-pinned": i || void 0,
20
+ style: {
21
+ width: !i && g ? "auto" : `calc(var(--${u}-header-${e.id}-size) * 1px)`
22
+ },
23
+ children: [
24
+ e.isPlaceholder ? null : /* @__PURE__ */ r(S, { children: [
25
+ e.column.columnDef.meta?.noSortButton ? l(e.column.columnDef.header, e.getContext()) : e.column.getCanSort() ? /* @__PURE__ */ r(
26
+ C,
27
+ {
28
+ type: "button",
29
+ "aria-label": `Sort ${e.id} column`,
30
+ onClick: e.column.getToggleSortingHandler(),
31
+ title: (
32
+ // eslint-disable-next-line no-nested-ternary
33
+ e.column.getNextSortingOrder() === a.ASC ? "Sort ascending" : e.column.getNextSortingOrder() === a.DESC ? "Sort descending" : "Clear sort"
34
+ ),
35
+ children: [
36
+ l(
37
+ e.column.columnDef.header,
38
+ e.getContext()
39
+ ),
40
+ {
41
+ asc: /* @__PURE__ */ n(t, { icon: m, size: "sm" }),
42
+ desc: /* @__PURE__ */ n(t, { icon: c, size: "sm" })
43
+ }[e.column.getIsSorted()] ?? (e.column.getNextSortingOrder() === "desc" ? /* @__PURE__ */ n(
44
+ t,
45
+ {
46
+ icon: c,
47
+ size: "sm",
48
+ className: "fade"
49
+ }
50
+ ) : /* @__PURE__ */ n(
51
+ t,
52
+ {
53
+ icon: m,
54
+ size: "sm",
55
+ className: "fade"
56
+ }
57
+ ))
58
+ ]
59
+ }
60
+ ) : /* @__PURE__ */ n(z, { children: l(
61
+ e.column.columnDef.header,
62
+ e.getContext()
63
+ ) }),
64
+ e.column.getCanFilter() && e.column.columnDef.meta?.filterType && /* @__PURE__ */ n(
65
+ D,
66
+ {
67
+ column: e.column,
68
+ filterType: e.column.columnDef.meta.filterType,
69
+ filterOptions: e.column.columnDef.meta?.filterOptions,
70
+ filterSearchable: e.column.columnDef.meta?.filterSearchable
71
+ }
72
+ )
73
+ ] }),
74
+ e.column.getCanResize() && /* @__PURE__ */ n(
75
+ "button",
76
+ {
77
+ type: "button",
78
+ "aria-label": `Resize ${e.id} column`,
79
+ onMouseDown: e.getResizeHandler(),
80
+ onTouchStart: e.getResizeHandler(),
81
+ className: `resizer ${e.column.getIsResizing() ? "isResizing" : ""}`
82
+ }
83
+ )
84
+ ]
85
+ },
86
+ e.id
87
+ );
88
+ }) }) }, o.id)) });
89
+ }
90
+ export {
91
+ w as default
92
+ };
@@ -1,4 +1,4 @@
1
- import { jsx as t, jsxs as i } from "react/jsx-runtime";
1
+ import { jsx as t, jsxs as l } from "react/jsx-runtime";
2
2
  import a from "react";
3
3
  import r from "styled-components";
4
4
  import c from "../Typography/Typography.js";
@@ -22,10 +22,10 @@ const g = r(o)`
22
22
  justify-content: space-between;
23
23
  width: 100%;
24
24
  `;
25
- function h({ toolbar: e, columnFilters: l, table: n }, s) {
26
- const d = n.getFilteredRowModel().rows.length, p = l.length > 0;
27
- return /* @__PURE__ */ t(g, { ref: s, children: /* @__PURE__ */ i(m, { children: [
28
- /* @__PURE__ */ i(o, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
25
+ function h({ toolbar: e, columnFilters: n, table: i }, s) {
26
+ const d = i.getFilteredRowModel().rows.length, p = n.length > 0;
27
+ return /* @__PURE__ */ t(g, { ref: s, children: /* @__PURE__ */ l(m, { children: [
28
+ /* @__PURE__ */ l(o, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
29
29
  e.leftContent ? e.leftContent : null,
30
30
  e.exportToExcel?.enabled && /* @__PURE__ */ t(
31
31
  x,
@@ -34,10 +34,12 @@ function h({ toolbar: e, columnFilters: l, table: n }, s) {
34
34
  disabled: e.exportToExcel.disabled
35
35
  }
36
36
  ),
37
- e.showFilterChips ? /* @__PURE__ */ t(f, { columnFilters: l, table: n }) : null
37
+ e.showFilterChips ? /* @__PURE__ */ t(f, { columnFilters: n, table: i }) : null
38
38
  ] }),
39
- /* @__PURE__ */ t(o, { sx: { display: "flex", alignItems: "center", gap: 2 }, children: e.totalResults !== void 0 && /* @__PURE__ */ t(c, { level: "body-sm", sx: { fontWeight: 500 }, children: p ? `Showing ${d.toLocaleString()} of ${e.totalResults.toLocaleString()} results` : `Total Results: ${e.totalResults.toLocaleString()}` }) }),
40
- e.rightContent ? e.rightContent : null
39
+ /* @__PURE__ */ l(o, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
40
+ e.totalResults !== void 0 && /* @__PURE__ */ t(c, { level: "body-sm", sx: { fontWeight: 500 }, children: p ? `Showing ${d.toLocaleString()} of ${e.totalResults.toLocaleString()} results` : `Total Results: ${e.totalResults.toLocaleString()}` }),
41
+ e.rightContent ? e.rightContent : null
42
+ ] })
41
43
  ] }) });
42
44
  }
43
45
  const v = a.forwardRef(h);
@@ -0,0 +1,108 @@
1
+ function i(t, e) {
2
+ return t ? `${t}_${e}` : e;
3
+ }
4
+ function h(t, e) {
5
+ const n = t.get(i(e, "sort_by")), o = t.get(i(e, "sort_order"));
6
+ return n ? [{ id: n, desc: o === "desc" }] : [];
7
+ }
8
+ function f(t, e, n) {
9
+ return Object.entries(n).reduce(
10
+ (o, [r, c]) => {
11
+ if (c === "multiselect") {
12
+ const s = t.get(i(e, r));
13
+ s && o.push({ id: r, value: s.split(",") });
14
+ } else if (c === "date" || c === "number") {
15
+ const s = t.get(i(e, `${r}_gte`)), a = t.get(i(e, `${r}_lte`));
16
+ (s !== null || a !== null) && o.push({
17
+ id: r,
18
+ value: {
19
+ min: s ?? void 0,
20
+ max: a ?? void 0
21
+ }
22
+ });
23
+ } else {
24
+ const s = t.get(i(e, r));
25
+ s && o.push({ id: r, value: s });
26
+ }
27
+ return o;
28
+ },
29
+ []
30
+ );
31
+ }
32
+ function y(t) {
33
+ const e = {};
34
+ return t.forEach((n) => {
35
+ const o = n.id ?? n.accessorKey, r = n.meta?.filterType;
36
+ o && r && (e[o] = r);
37
+ }), e;
38
+ }
39
+ function d(t, e, n) {
40
+ if (t.length === 0 || !t[0]?.id) return;
41
+ const { id: o, desc: r } = t[0];
42
+ n.set(i(e, "sort_by"), o), n.set(i(e, "sort_order"), r ? "desc" : "asc");
43
+ }
44
+ function g(t, e, n) {
45
+ t.forEach((o) => {
46
+ const { value: r } = o;
47
+ if (!(r == null || r === "")) {
48
+ if (Array.isArray(r)) {
49
+ r.length > 0 && n.set(i(e, o.id), r.join(","));
50
+ return;
51
+ }
52
+ if (typeof r == "object" && r !== null) {
53
+ const c = r, s = c.min ?? c.gte ?? c.start, a = c.max ?? c.lte ?? c.end;
54
+ if (s != null && s !== "") {
55
+ const u = s instanceof Date ? s.toISOString().split("T")[0] : String(s);
56
+ n.set(i(e, `${o.id}_gte`), u);
57
+ }
58
+ if (a != null && a !== "") {
59
+ const u = a instanceof Date ? a.toISOString().split("T")[0] : String(a);
60
+ n.set(i(e, `${o.id}_lte`), u);
61
+ }
62
+ return;
63
+ }
64
+ n.set(i(e, o.id), String(r));
65
+ }
66
+ });
67
+ }
68
+ function S(t, e) {
69
+ return [
70
+ i(t, "sort_by"),
71
+ i(t, "sort_order"),
72
+ ...Object.entries(e).flatMap(
73
+ ([n, o]) => o === "date" || o === "number" ? [i(t, `${n}_gte`), i(t, `${n}_lte`)] : [i(t, n)]
74
+ )
75
+ ];
76
+ }
77
+ function _(t, e, n, o) {
78
+ const r = new URL(window.location.href), c = new Set(S(n, o)), s = [];
79
+ r.searchParams.forEach((u, l) => {
80
+ c.has(l) || s.push([l, u]);
81
+ });
82
+ const a = new URLSearchParams();
83
+ s.forEach(([u, l]) => a.append(u, l)), d(t, n, a), g(e, n, a), r.search = a.toString(), window.history.replaceState(null, "", r.toString());
84
+ }
85
+ function m(t, e) {
86
+ if (t.length === 0 || !t[0]?.id) return "";
87
+ const n = new URLSearchParams();
88
+ return d(t, e, n), `&${n.toString()}`;
89
+ }
90
+ function w(t, e) {
91
+ if (t.length === 0) return "";
92
+ const n = new URLSearchParams();
93
+ g(t, e, n);
94
+ const o = n.toString();
95
+ return o ? `&${o}` : "";
96
+ }
97
+ export {
98
+ w as buildFilterQueryString,
99
+ m as buildSortQueryString,
100
+ y as extractColumnFilterTypes,
101
+ S as getManagedUrlKeys,
102
+ f as parseFiltersFromUrl,
103
+ h as parseSortingFromUrl,
104
+ i as prefixKey,
105
+ _ as syncStateToUrl,
106
+ g as writeFiltersToSearchParams,
107
+ d as writeSortToSearchParams
108
+ };
@@ -0,0 +1,8 @@
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import e 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/LinearProgress/LinearProgress.js";
3
+ function i(r) {
4
+ return /* @__PURE__ */ o(e, { ...r });
5
+ }
6
+ export {
7
+ i as default
8
+ };
@@ -0,0 +1,47 @@
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";
3
+ const L = (m = {}) => {
4
+ const {
5
+ initialSortField: s,
6
+ initialSortDirection: p = "asc",
7
+ syncUrl: r = !1,
8
+ urlParamPrefix: e = "",
9
+ columns: a,
10
+ columnFilterTypes: S = {}
11
+ } = m, o = a ? U(a) : S, [t, w] = f(() => {
12
+ if (r && typeof window < "u") {
13
+ const i = new URLSearchParams(window.location.search), u = P(i, e);
14
+ if (u.length > 0) return u;
15
+ }
16
+ return s ? [{ id: s, desc: p === "desc" }] : [];
17
+ }), [n, y] = f(() => {
18
+ if (r && typeof window < "u") {
19
+ const i = new URLSearchParams(window.location.search);
20
+ return T(i, e, o);
21
+ }
22
+ return [];
23
+ }), l = d(e);
24
+ l.current = e;
25
+ const c = d(o);
26
+ c.current = o, h(() => {
27
+ !r || typeof window > "u" || C(
28
+ t,
29
+ n,
30
+ l.current,
31
+ c.current
32
+ );
33
+ }, [t, n, r]);
34
+ const F = R(t, ""), g = x(n, "");
35
+ return {
36
+ sorting: t,
37
+ onSortingChange: w,
38
+ columnFilters: n,
39
+ onColumnFiltersChange: y,
40
+ sortParams: F,
41
+ filterParams: g
42
+ };
43
+ };
44
+ export {
45
+ L as default,
46
+ U as extractColumnFilterTypes
47
+ };