@homebound/beam 2.105.9 → 2.106.1

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.
@@ -50,6 +50,10 @@ export interface GridStyle {
50
50
  presentationSettings?: Pick<PresentationFieldProps, "borderless" | "typeScale"> & Pick<PresentationContextProps, "wrap">;
51
51
  /** Minimum table width in pixels. Used when calculating columns sizes */
52
52
  minWidthPx?: number;
53
+ /** Css to apply at each level of a parent/child nested table. */
54
+ levels?: Record<number, {
55
+ cellCss: Properties;
56
+ }>;
53
57
  }
54
58
  export declare type NestedCardStyleByKind = Record<string, NestedCardStyle>;
55
59
  export interface NestedCardsStyle {
@@ -101,26 +101,42 @@ function GridTable(props) {
101
101
  }
102
102
  return rows;
103
103
  }, [columns, rows, sorting, sortState]);
104
+ // Calculate the column sizes immediately rather than via the `debounce` method.
105
+ // We do this for Storybook integrations that may use MockDate. MockDate changes the behavior of `new Date()`, which is used by `useDebounce` and essentially turns off the callback.
106
+ const calculateImmediately = (0, react_1.useRef)(true);
104
107
  const [tableWidth, setTableWidth] = (0, react_1.useState)();
105
108
  // Calc our initial/first render sizes where we won't have a width yet
106
109
  const [columnSizes, setColumnSizes] = (0, react_1.useState)(calcColumnSizes(columns, (_a = style.nestedCards) === null || _a === void 0 ? void 0 : _a.firstLastColumnWidth, tableWidth, style.minWidthPx));
107
- const setTableWidthDebounced = (0, use_debounce_1.useDebouncedCallback)((width) => {
110
+ const setTableAndColumnWidths = (0, react_1.useCallback)((width) => {
108
111
  var _a;
109
112
  setTableWidth(width);
110
113
  setColumnSizes(calcColumnSizes(columns, (_a = style.nestedCards) === null || _a === void 0 ? void 0 : _a.firstLastColumnWidth, width, style.minWidthPx));
111
- }, 100);
114
+ }, [setTableWidth, setColumnSizes, columns, style]);
115
+ const setTableAndColumnWidthsDebounced = (0, use_debounce_1.useDebouncedCallback)(setTableAndColumnWidths, 100);
112
116
  const onResize = (0, react_1.useCallback)(() => {
113
117
  const target = (resizeTarget === null || resizeTarget === void 0 ? void 0 : resizeTarget.current) ? resizeTarget.current : tableRef.current;
114
118
  if (target && target.clientWidth !== tableWidth) {
115
- setTableWidthDebounced(target.clientWidth);
119
+ if (calculateImmediately.current) {
120
+ calculateImmediately.current = false;
121
+ setTableAndColumnWidths(target.clientWidth);
122
+ }
123
+ else {
124
+ setTableAndColumnWidthsDebounced(target.clientWidth);
125
+ }
116
126
  }
117
- }, [resizeTarget === null || resizeTarget === void 0 ? void 0 : resizeTarget.current, tableRef.current, setTableWidthDebounced]);
127
+ }, [
128
+ resizeTarget === null || resizeTarget === void 0 ? void 0 : resizeTarget.current,
129
+ tableRef.current,
130
+ setTableAndColumnWidths,
131
+ calculateImmediately,
132
+ setTableAndColumnWidthsDebounced,
133
+ ]);
118
134
  (0, utils_1.useResizeObserver)({ ref: resizeTarget !== null && resizeTarget !== void 0 ? resizeTarget : tableRef, onResize });
119
135
  // Filter + flatten + component-ize the sorted rows.
120
136
  let [headerRows, filteredRows] = (0, react_1.useMemo)(() => {
121
137
  // Break up "foo bar" into `[foo, bar]` and a row must match both `foo` and `bar`
122
138
  const filters = (filter && filter.split(/ +/)) || [];
123
- function makeRowComponent(row) {
139
+ function makeRowComponent(row, level) {
124
140
  // We only pass sortState to header rows, b/c non-headers rows shouldn't have to re-render on sorting
125
141
  // changes, and so by not passing the sortProps, it means the data rows' React.memo will still cache them.
126
142
  const sortProps = row.kind === "header" ? { sorting, sortState, setSortKey } : { sorting };
@@ -135,6 +151,7 @@ function GridTable(props) {
135
151
  stickyOffset,
136
152
  openCards: nestedCards ? nestedCards.currentOpenCards() : undefined,
137
153
  columnSizes,
154
+ level,
138
155
  ...sortProps,
139
156
  }), void 0) }), `${row.kind}-${row.id}`));
140
157
  }
@@ -144,7 +161,7 @@ function GridTable(props) {
144
161
  // Misc state to track our nested card-ification, i.e. interleaved actual rows + chrome rows
145
162
  const nestedCards = !!style.nestedCards && new nestedCards_1.NestedCards(columns, filteredRows, style.nestedCards);
146
163
  // Depth-first to filter
147
- function visit(row) {
164
+ function visit(row, level) {
148
165
  var _a;
149
166
  const matches = filters.length === 0 ||
150
167
  row.pin ||
@@ -153,28 +170,28 @@ function GridTable(props) {
153
170
  let isCard = false;
154
171
  if (matches) {
155
172
  isCard = nestedCards && nestedCards.maybeOpenCard(row);
156
- filteredRows.push([row, makeRowComponent(row)]);
173
+ filteredRows.push([row, makeRowComponent(row, level)]);
157
174
  }
158
175
  const isCollapsed = collapsedIds.includes(row.id);
159
176
  if (!isCollapsed && !!((_a = row.children) === null || _a === void 0 ? void 0 : _a.length)) {
160
177
  nestedCards && matches && nestedCards.addSpacer();
161
- visitRows(row.children, isCard);
178
+ visitRows(row.children, isCard, level + 1);
162
179
  }
163
180
  !(0, nestedCards_1.isLeafRow)(row) && isCard && nestedCards && nestedCards.closeCard();
164
181
  }
165
- function visitRows(rows, addSpacer) {
182
+ function visitRows(rows, addSpacer, level) {
166
183
  const length = rows.length;
167
184
  rows.forEach((row, i) => {
168
185
  if (row.kind === "header") {
169
- headerRows.push([row, makeRowComponent(row)]);
186
+ headerRows.push([row, makeRowComponent(row, level)]);
170
187
  return;
171
188
  }
172
- visit(row);
189
+ visit(row, level);
173
190
  addSpacer && nestedCards && i !== length - 1 && nestedCards.addSpacer();
174
191
  });
175
192
  }
176
193
  // If nestedCards is set, we assume the top-level kind is a card, and so should add spacers between them
177
- visitRows(maybeSorted, !!nestedCards);
194
+ visitRows(maybeSorted, !!nestedCards, 0);
178
195
  nestedCards && nestedCards.done();
179
196
  return [headerRows, filteredRows];
180
197
  }, [
@@ -427,6 +444,9 @@ exports.calcColumnSizes = calcColumnSizes;
427
444
  function getIndentationCss(style, rowStyle, columnIndex, maybeContent) {
428
445
  // Look for cell-specific indent or row-specific indent (row-specific is only one the first column)
429
446
  const indent = (isGridCellContent(maybeContent) && maybeContent.indent) || (columnIndex === 0 && (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.indent));
447
+ if (typeof indent === "number" && style.levels !== undefined) {
448
+ throw new Error("The indent param is deprecated for new beam fixed & flexible styles, use beamNestedFixedStyle or beamNestedFlexibleStyle");
449
+ }
430
450
  return indent === 1 ? style.indentOneCss || {} : indent === 2 ? style.indentTwoCss || {} : {};
431
451
  }
432
452
  function getFirstOrLastCellCss(style, columnIndex, columns) {
@@ -437,7 +457,7 @@ function getFirstOrLastCellCss(style, columnIndex, columns) {
437
457
  }
438
458
  // We extract GridRow to its own mini-component primarily so we can React.memo'ize it.
439
459
  function GridRow(props) {
440
- const { as, columns, row, style, rowStyles, stickyHeader, stickyOffset, sorting, sortState, setSortKey, openCards, columnSizes, ...others } = props;
460
+ const { as, columns, row, style, rowStyles, stickyHeader, stickyOffset, sorting, sortState, setSortKey, openCards, columnSizes, level, ...others } = props;
441
461
  // We treat the "header" kind as special for "good defaults" styling
442
462
  const isHeader = row.kind === "header";
443
463
  const rowStyle = rowStyles === null || rowStyles === void 0 ? void 0 : rowStyles[row.kind];
@@ -464,7 +484,7 @@ function GridRow(props) {
464
484
  };
465
485
  let currentColspan = 1;
466
486
  const rowNode = ((0, jsx_runtime_1.jsx)(Row, Object.assign({ css: rowCss }, others, { "data-gridrow": true }, { children: columns.map((column, columnIndex) => {
467
- var _a;
487
+ var _a, _b;
468
488
  if (column.mw) {
469
489
  // Validate the column's minWidth definition if set.
470
490
  if (!column.mw.endsWith("px") && !column.mw.endsWith("%")) {
@@ -506,6 +526,8 @@ function GridRow(props) {
506
526
  ...getIndentationCss(style, rowStyle, columnIndex, maybeContent),
507
527
  // Then apply any header-specific override
508
528
  ...(isHeader && style.headerCellCss),
529
+ // Or level-specific styling
530
+ ...(!isHeader && !!style.levels && ((_b = style.levels[level]) === null || _b === void 0 ? void 0 : _b.cellCss)),
509
531
  // The specific cell's css (if any from GridCellContent)
510
532
  ...rowStyleCellCss,
511
533
  // Add any cell specific style overrides
@@ -7,4 +7,4 @@ export type { Direction, GridCellAlignment, GridCellContent, GridCollapseContext
7
7
  export { simpleDataRows, simpleHeader, simpleRows } from "./simpleHelpers";
8
8
  export type { SimpleHeaderAndDataOf, SimpleHeaderAndDataWith } from "./simpleHelpers";
9
9
  export { SortHeader } from "./SortHeader";
10
- export { cardStyle, condensedStyle, defaultStyle } from "./styles";
10
+ export { beamFixedStyle, beamFlexibleStyle, beamNestedFixedStyle, beamNestedFlexibleStyle, cardStyle, condensedStyle, defaultStyle, } from "./styles";
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.defaultStyle = exports.condensedStyle = exports.cardStyle = exports.SortHeader = exports.simpleRows = exports.simpleHeader = exports.simpleDataRows = exports.setGridTableDefaults = exports.setDefaultStyle = exports.GridTable = exports.DESC = exports.ASC = exports.GridSortContext = void 0;
13
+ exports.defaultStyle = exports.condensedStyle = exports.cardStyle = exports.beamNestedFlexibleStyle = exports.beamNestedFixedStyle = exports.beamFlexibleStyle = exports.beamFixedStyle = exports.SortHeader = exports.simpleRows = exports.simpleHeader = exports.simpleDataRows = exports.setGridTableDefaults = exports.setDefaultStyle = exports.GridTable = exports.DESC = exports.ASC = exports.GridSortContext = void 0;
14
14
  __exportStar(require("./CollapseToggle"), exports);
15
15
  __exportStar(require("./columns"), exports);
16
16
  var GridSortContext_1 = require("./GridSortContext");
@@ -28,6 +28,10 @@ Object.defineProperty(exports, "simpleRows", { enumerable: true, get: function (
28
28
  var SortHeader_1 = require("./SortHeader");
29
29
  Object.defineProperty(exports, "SortHeader", { enumerable: true, get: function () { return SortHeader_1.SortHeader; } });
30
30
  var styles_1 = require("./styles");
31
+ Object.defineProperty(exports, "beamFixedStyle", { enumerable: true, get: function () { return styles_1.beamFixedStyle; } });
32
+ Object.defineProperty(exports, "beamFlexibleStyle", { enumerable: true, get: function () { return styles_1.beamFlexibleStyle; } });
33
+ Object.defineProperty(exports, "beamNestedFixedStyle", { enumerable: true, get: function () { return styles_1.beamNestedFixedStyle; } });
34
+ Object.defineProperty(exports, "beamNestedFlexibleStyle", { enumerable: true, get: function () { return styles_1.beamNestedFlexibleStyle; } });
31
35
  Object.defineProperty(exports, "cardStyle", { enumerable: true, get: function () { return styles_1.cardStyle; } });
32
36
  Object.defineProperty(exports, "condensedStyle", { enumerable: true, get: function () { return styles_1.condensedStyle; } });
33
37
  Object.defineProperty(exports, "defaultStyle", { enumerable: true, get: function () { return styles_1.defaultStyle; } });
@@ -7,6 +7,10 @@ export declare const condensedStyle: GridStyle;
7
7
  /** Renders each row as a card. */
8
8
  export declare const cardStyle: GridStyle;
9
9
  export declare const beamFixedStyle: GridStyle;
10
- export declare const beamFlexibleStyle: GridStyle;
11
10
  export declare const beamGroupRowStyle: Properties;
12
11
  export declare const beamTotalsRowStyle: Properties;
12
+ export declare const beamNestedFixedStyle: GridStyle;
13
+ export declare const beamTotalsFixedStyle: GridStyle;
14
+ export declare const beamFlexibleStyle: GridStyle;
15
+ export declare const beamNestedFlexibleStyle: GridStyle;
16
+ export declare const beamTotalsFlexibleStyle: GridStyle;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.beamTotalsRowStyle = exports.beamGroupRowStyle = exports.beamFlexibleStyle = exports.beamFixedStyle = exports.cardStyle = exports.condensedStyle = exports.defaultStyle = void 0;
3
+ exports.beamTotalsFlexibleStyle = exports.beamNestedFlexibleStyle = exports.beamFlexibleStyle = exports.beamTotalsFixedStyle = exports.beamNestedFixedStyle = exports.beamTotalsRowStyle = exports.beamGroupRowStyle = exports.beamFixedStyle = exports.cardStyle = exports.condensedStyle = exports.defaultStyle = void 0;
4
4
  const Css_1 = require("../../Css");
5
5
  /** Our original table look & feel/style. */
6
6
  exports.defaultStyle = {
@@ -46,13 +46,33 @@ exports.beamFixedStyle = {
46
46
  emptyCell: "-",
47
47
  presentationSettings: { borderless: true, typeScale: "xs", wrap: false },
48
48
  rowHoverColor: Css_1.Palette.Gray200,
49
+ // Included as a hacky "treat indent as deprecated for this table" hint to GridTable
50
+ levels: {},
51
+ };
52
+ // The look & feel for parent rows' cells in a nested parent/child table.
53
+ exports.beamGroupRowStyle = Css_1.Css.xsEm
54
+ .mhPx(56)
55
+ .gray700.bgGray100.boxShadow(`inset 0 -1px 0 ${Css_1.Palette.Gray200}`).$;
56
+ // The look & feel for a totals row's cells.
57
+ exports.beamTotalsRowStyle = Css_1.Css.gray700.smEm.hPx(40).mb1.bgWhite.boxShadow("none").$;
58
+ exports.beamNestedFixedStyle = {
59
+ ...exports.beamFixedStyle,
60
+ levels: { 0: { cellCss: exports.beamGroupRowStyle } },
61
+ };
62
+ exports.beamTotalsFixedStyle = {
63
+ ...exports.beamFixedStyle,
64
+ cellCss: { ...exports.beamFixedStyle.cellCss, ...exports.beamTotalsRowStyle },
49
65
  };
50
66
  exports.beamFlexibleStyle = {
51
67
  ...exports.beamFixedStyle,
52
68
  cellCss: Css_1.Css.xs.bgWhite.aic.p2.boxShadow(`inset 0 -1px 0 ${Css_1.Palette.Gray100}`).$,
53
69
  presentationSettings: { borderless: false, typeScale: "xs", wrap: true },
54
70
  };
55
- exports.beamGroupRowStyle = Css_1.Css.xsEm
56
- .mhPx(56)
57
- .gray700.bgGray100.boxShadow(`inset 0 -1px 0 ${Css_1.Palette.Gray200}`).$;
58
- exports.beamTotalsRowStyle = Css_1.Css.gray700.smEm.hPx(40).mb1.bgWhite.boxShadow("none").$;
71
+ exports.beamNestedFlexibleStyle = {
72
+ ...exports.beamFlexibleStyle,
73
+ levels: { 0: { cellCss: exports.beamGroupRowStyle } },
74
+ };
75
+ exports.beamTotalsFlexibleStyle = {
76
+ ...exports.beamFlexibleStyle,
77
+ cellCss: { ...exports.beamFlexibleStyle.cellCss, ...exports.beamTotalsRowStyle },
78
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.105.9",
3
+ "version": "2.106.1",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",