@spscommerce/ds-react 5.22.0 → 5.23.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.
package/lib/index.es.js CHANGED
@@ -26166,6 +26166,8 @@ const usePinnedTableBackgroundStyle = (containerRef) => {
26166
26166
  React.useLayoutEffect(() => {
26167
26167
  if (containerRef.current) {
26168
26168
  const pinnedThs = containerRef.current.querySelectorAll("table > thead > tr:first-child > .sps-table__cell--pinned");
26169
+ const verticalScrollbarWidth = containerRef.current.offsetWidth - containerRef.current.clientWidth;
26170
+ const horizontalScrollbarHeight = containerRef.current.offsetHeight - containerRef.current.clientHeight;
26169
26171
  if (pinnedThs.length > 0) {
26170
26172
  const leftPinnedThs = [];
26171
26173
  const rightPinnedThs = [];
@@ -26187,12 +26189,18 @@ const usePinnedTableBackgroundStyle = (containerRef) => {
26187
26189
  });
26188
26190
  const leftPinnedWidth = leftPinnedThs.reduce((acc, th) => acc + th.clientWidth, 0);
26189
26191
  const rightPinnedWidth = rightPinnedThs.reduce((acc, th) => acc + th.clientWidth, 0);
26190
- containerRef.current.style.backgroundPosition = `${leftPinnedWidth}px 0, calc(100% - ${rightPinnedWidth}px) 0, ${leftPinnedWidth}px 0, calc(100% - ${rightPinnedWidth}px) 0`;
26192
+ containerRef.current.style.backgroundPosition = `${leftPinnedWidth}px 0,
26193
+ calc(100% - ${rightPinnedWidth}px) 0,
26194
+ ${leftPinnedWidth}px ${-horizontalScrollbarHeight}px,
26195
+ calc(100% - ${rightPinnedWidth + verticalScrollbarWidth}px) ${-horizontalScrollbarHeight}px`;
26196
+ } else {
26197
+ containerRef.current.style.backgroundPosition = `0 0, 100% 0, 0 ${-horizontalScrollbarHeight}px,
26198
+ calc(100% - ${verticalScrollbarWidth}px) ${-horizontalScrollbarHeight}px`;
26191
26199
  }
26192
26200
  }
26193
26201
  });
26194
26202
  };
26195
- const usePinnedTableHeadStyle = (containerRef) => {
26203
+ const usePinnedTableHeadStyle = (containerRef, maxHeight) => {
26196
26204
  React.useLayoutEffect(() => {
26197
26205
  const container = containerRef.current;
26198
26206
  const headElement = container == null ? void 0 : container.querySelector("thead");
@@ -26205,8 +26213,8 @@ const usePinnedTableHeadStyle = (containerRef) => {
26205
26213
  let scrollableParent = null;
26206
26214
  const resetAppliedStyles = () => {
26207
26215
  if (headElement) {
26208
- headElement.style.position = null;
26209
- headElement.style.top = null;
26216
+ headElement.style.position = maxHeight ? "sticky" : null;
26217
+ headElement.style.top = maxHeight ? "0" : null;
26210
26218
  headElement.style.overflow = null;
26211
26219
  headElement.style.maxWidth = null;
26212
26220
  headElement.style.width = null;
@@ -26244,7 +26252,8 @@ const usePinnedTableHeadStyle = (containerRef) => {
26244
26252
  headElement.style.position = "fixed";
26245
26253
  headElement.style.top = `${topPosition}px`;
26246
26254
  headElement.style.overflow = "hidden";
26247
- const headElementWidth = `${containerRect.width}px`;
26255
+ const verticalScrollbarWidth = containerRef.current.offsetWidth - containerRef.current.clientWidth;
26256
+ const headElementWidth = `${containerRect.width - verticalScrollbarWidth}px`;
26248
26257
  headElement.style.maxWidth = headElementWidth;
26249
26258
  headElement.style.width = headElementWidth;
26250
26259
  headElement.style.minWidth = headElementWidth;
@@ -26299,6 +26308,52 @@ const usePinnedTableHeadStyle = (containerRef) => {
26299
26308
  };
26300
26309
  });
26301
26310
  };
26311
+ const useMaxHeightTableStyle = (containerRef, maxHeight) => {
26312
+ const applyVerticalScrollShadow = () => {
26313
+ const container = containerRef.current;
26314
+ const tableHead = container == null ? void 0 : container.querySelector("table > thead");
26315
+ const table = container == null ? void 0 : container.querySelector("table");
26316
+ const shadowTop = container == null ? void 0 : container.querySelector(".shadow--top");
26317
+ const shadowBottom = container == null ? void 0 : container.querySelector(".shadow--bottom");
26318
+ if (tableHead && table && shadowTop && shadowBottom) {
26319
+ shadowBottom.style.left = "0";
26320
+ shadowBottom.style.bottom = "0";
26321
+ shadowTop.style.left = "0";
26322
+ const horizontalScrollbarHeight = container.offsetHeight - (container == null ? void 0 : container.clientHeight);
26323
+ const tableHeight = table.getBoundingClientRect().height;
26324
+ const tableHeadHeight = tableHead.getBoundingClientRect().height;
26325
+ const containerScrollTop = container.scrollTop;
26326
+ const containerScrollBottom = tableHeight + horizontalScrollbarHeight - container.getBoundingClientRect().height - container.scrollTop;
26327
+ const containerScrollLeft = container.scrollLeft;
26328
+ shadowBottom.style.bottom = `${-containerScrollTop}px`;
26329
+ shadowBottom.style.left = `${containerScrollLeft}px`;
26330
+ shadowBottom.style.opacity = containerScrollBottom > 0 ? "1" : "0";
26331
+ shadowTop.style.top = `${containerScrollTop + tableHeadHeight}px`;
26332
+ shadowTop.style.left = `${containerScrollLeft}px`;
26333
+ shadowTop.style.opacity = containerScrollTop > 0 ? "1" : "0";
26334
+ }
26335
+ };
26336
+ React.useLayoutEffect(() => {
26337
+ if (containerRef.current && maxHeight) {
26338
+ const tableHead = containerRef.current.querySelector("table > thead");
26339
+ if (tableHead) {
26340
+ tableHead.style.position = "sticky";
26341
+ tableHead.style.top = "0";
26342
+ tableHead.style.zIndex = "2";
26343
+ tableHead.style.backgroundColor = "#fff";
26344
+ }
26345
+ containerRef.current.addEventListener("scroll", applyVerticalScrollShadow);
26346
+ return () => {
26347
+ containerRef.current.removeEventListener("scroll", applyVerticalScrollShadow);
26348
+ };
26349
+ }
26350
+ }, []);
26351
+ React.useLayoutEffect(() => {
26352
+ if (containerRef.current && maxHeight) {
26353
+ applyVerticalScrollShadow();
26354
+ }
26355
+ });
26356
+ };
26302
26357
  const propsDoc$13 = {
26303
26358
  controlCell: "boolean",
26304
26359
  currentSort: "Array<SortedColumn>",
@@ -26492,12 +26547,16 @@ Object.assign(SpsThead, {
26492
26547
  const propsDoc$10 = {
26493
26548
  sort: "SortedColumn",
26494
26549
  onSortChange: "SortChangeHandler",
26495
- selectable: "boolean"
26550
+ selectable: "boolean",
26551
+ maxHeightPx: "number",
26552
+ maxHeightRem: "number"
26496
26553
  };
26497
26554
  const propTypes$13 = __spreadProps(__spreadValues({}, spsGlobalPropTypes), {
26498
26555
  onSortChange: fun(),
26499
26556
  sort: propTypes$1O.exports.arrayOf(impl()),
26500
- selectable: propTypes$1O.exports.bool
26557
+ selectable: propTypes$1O.exports.bool,
26558
+ maxHeightPx: propTypes$1O.exports.number,
26559
+ maxHeightRem: propTypes$1O.exports.number
26501
26560
  });
26502
26561
  function SpsTable(props2) {
26503
26562
  const _a = props2, {
@@ -26506,14 +26565,18 @@ function SpsTable(props2) {
26506
26565
  onSortChange,
26507
26566
  sort,
26508
26567
  "data-testid": testId,
26509
- unsafelyReplaceClassName
26568
+ unsafelyReplaceClassName,
26569
+ maxHeightPx,
26570
+ maxHeightRem
26510
26571
  } = _a, rest = __objRest(_a, [
26511
26572
  "children",
26512
26573
  "className",
26513
26574
  "onSortChange",
26514
26575
  "sort",
26515
26576
  "data-testid",
26516
- "unsafelyReplaceClassName"
26577
+ "unsafelyReplaceClassName",
26578
+ "maxHeightPx",
26579
+ "maxHeightRem"
26517
26580
  ]);
26518
26581
  const [currentSort, setSort] = React.useState(sort);
26519
26582
  const updateSortingDisplay = (newSort) => {
@@ -26535,13 +26598,21 @@ function SpsTable(props2) {
26535
26598
  currentSort
26536
26599
  };
26537
26600
  const classes = clsx(unsafelyReplaceClassName || "sps-table-container", className);
26601
+ const maxHeight = maxHeightPx ? maxHeightPx / 16 : maxHeightRem;
26602
+ const tableContainerInlineStyles = maxHeight ? { maxHeight: `${maxHeight}rem` } : {};
26538
26603
  const containerRef = React.useRef(null);
26604
+ useMaxHeightTableStyle(containerRef, maxHeight);
26539
26605
  usePinnedTableBackgroundStyle(containerRef);
26540
- usePinnedTableHeadStyle(containerRef);
26606
+ usePinnedTableHeadStyle(containerRef, maxHeight);
26541
26607
  return /* @__PURE__ */ React.createElement("div", {
26542
26608
  ref: containerRef,
26543
- className: classes
26544
- }, /* @__PURE__ */ React.createElement("table", __spreadValues({
26609
+ className: classes,
26610
+ style: tableContainerInlineStyles
26611
+ }, /* @__PURE__ */ React.createElement("div", {
26612
+ className: "sps-table__shadow shadow--top"
26613
+ }), /* @__PURE__ */ React.createElement("div", {
26614
+ className: "sps-table__shadow shadow--bottom"
26615
+ }), /* @__PURE__ */ React.createElement("table", __spreadValues({
26545
26616
  className: "sps-table",
26546
26617
  role: "table",
26547
26618
  "data-testid": `${testId}`
@@ -4,6 +4,8 @@ declare const propTypes: {
4
4
  onSortChange: PropTypes.Requireable<SortChangeHandler>;
5
5
  sort: PropTypes.Requireable<SortedColumn[]>;
6
6
  selectable: PropTypes.Requireable<boolean>;
7
+ maxHeightPx: PropTypes.Requireable<number>;
8
+ maxHeightRem: PropTypes.Requireable<number>;
7
9
  children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
8
10
  className: PropTypes.Requireable<string>;
9
11
  "data-testid": PropTypes.Requireable<string>;
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
2
  export declare const usePinnedCellStyle: (isPinned: boolean, elementRef: React.MutableRefObject<HTMLTableHeaderCellElement | HTMLTableCellElement>) => void;
3
3
  export declare const usePinnedTableBackgroundStyle: (containerRef: React.MutableRefObject<HTMLDivElement>) => void;
4
- export declare const usePinnedTableHeadStyle: (containerRef: React.MutableRefObject<HTMLDivElement>) => void;
4
+ export declare const usePinnedTableHeadStyle: (containerRef: React.MutableRefObject<HTMLDivElement>, maxHeight: number) => void;
5
+ export declare const useMaxHeightTableStyle: (containerRef: React.MutableRefObject<HTMLDivElement>, maxHeight: number) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@spscommerce/ds-react",
3
3
  "description": "SPS Design System React components",
4
- "version": "5.22.0",
4
+ "version": "5.23.0",
5
5
  "author": "SPS Commerce",
6
6
  "license": "UNLICENSED",
7
7
  "repository": "https://github.com/spscommerce/design-system/tree/main/packages/@spscommerce/ds-react",
@@ -28,11 +28,11 @@
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@react-stately/collections": "^3.3.3",
31
- "@spscommerce/ds-colors": "5.22.0",
32
- "@spscommerce/ds-illustrations": "5.22.0",
33
- "@spscommerce/ds-shared": "5.22.0",
34
- "@spscommerce/positioning": "5.22.0",
35
- "@spscommerce/utils": "5.22.0",
31
+ "@spscommerce/ds-colors": "5.23.0",
32
+ "@spscommerce/ds-illustrations": "5.23.0",
33
+ "@spscommerce/ds-shared": "5.23.0",
34
+ "@spscommerce/positioning": "5.23.0",
35
+ "@spscommerce/utils": "5.23.0",
36
36
  "moment": "^2.25.3",
37
37
  "moment-timezone": "^0.5.28",
38
38
  "react": "^16.9.0",
@@ -40,11 +40,11 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@react-stately/collections": "^3.3.3",
43
- "@spscommerce/ds-colors": "5.22.0",
44
- "@spscommerce/ds-illustrations": "5.22.0",
45
- "@spscommerce/ds-shared": "5.22.0",
46
- "@spscommerce/positioning": "5.22.0",
47
- "@spscommerce/utils": "5.22.0",
43
+ "@spscommerce/ds-colors": "5.23.0",
44
+ "@spscommerce/ds-illustrations": "5.23.0",
45
+ "@spscommerce/ds-shared": "5.23.0",
46
+ "@spscommerce/positioning": "5.23.0",
47
+ "@spscommerce/utils": "5.23.0",
48
48
  "@testing-library/react": "^9.3.2",
49
49
  "@types/prop-types": "^15.7.1",
50
50
  "@types/react": "^16.9.0",