@homebound/beam 2.105.10 → 2.106.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.
@@ -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 {
@@ -136,7 +136,7 @@ function GridTable(props) {
136
136
  let [headerRows, filteredRows] = (0, react_1.useMemo)(() => {
137
137
  // Break up "foo bar" into `[foo, bar]` and a row must match both `foo` and `bar`
138
138
  const filters = (filter && filter.split(/ +/)) || [];
139
- function makeRowComponent(row) {
139
+ function makeRowComponent(row, level) {
140
140
  // We only pass sortState to header rows, b/c non-headers rows shouldn't have to re-render on sorting
141
141
  // changes, and so by not passing the sortProps, it means the data rows' React.memo will still cache them.
142
142
  const sortProps = row.kind === "header" ? { sorting, sortState, setSortKey } : { sorting };
@@ -151,6 +151,7 @@ function GridTable(props) {
151
151
  stickyOffset,
152
152
  openCards: nestedCards ? nestedCards.currentOpenCards() : undefined,
153
153
  columnSizes,
154
+ level,
154
155
  ...sortProps,
155
156
  }), void 0) }), `${row.kind}-${row.id}`));
156
157
  }
@@ -160,7 +161,7 @@ function GridTable(props) {
160
161
  // Misc state to track our nested card-ification, i.e. interleaved actual rows + chrome rows
161
162
  const nestedCards = !!style.nestedCards && new nestedCards_1.NestedCards(columns, filteredRows, style.nestedCards);
162
163
  // Depth-first to filter
163
- function visit(row) {
164
+ function visit(row, level) {
164
165
  var _a;
165
166
  const matches = filters.length === 0 ||
166
167
  row.pin ||
@@ -169,28 +170,28 @@ function GridTable(props) {
169
170
  let isCard = false;
170
171
  if (matches) {
171
172
  isCard = nestedCards && nestedCards.maybeOpenCard(row);
172
- filteredRows.push([row, makeRowComponent(row)]);
173
+ filteredRows.push([row, makeRowComponent(row, level)]);
173
174
  }
174
175
  const isCollapsed = collapsedIds.includes(row.id);
175
176
  if (!isCollapsed && !!((_a = row.children) === null || _a === void 0 ? void 0 : _a.length)) {
176
177
  nestedCards && matches && nestedCards.addSpacer();
177
- visitRows(row.children, isCard);
178
+ visitRows(row.children, isCard, level + 1);
178
179
  }
179
180
  !(0, nestedCards_1.isLeafRow)(row) && isCard && nestedCards && nestedCards.closeCard();
180
181
  }
181
- function visitRows(rows, addSpacer) {
182
+ function visitRows(rows, addSpacer, level) {
182
183
  const length = rows.length;
183
184
  rows.forEach((row, i) => {
184
185
  if (row.kind === "header") {
185
- headerRows.push([row, makeRowComponent(row)]);
186
+ headerRows.push([row, makeRowComponent(row, level)]);
186
187
  return;
187
188
  }
188
- visit(row);
189
+ visit(row, level);
189
190
  addSpacer && nestedCards && i !== length - 1 && nestedCards.addSpacer();
190
191
  });
191
192
  }
192
193
  // If nestedCards is set, we assume the top-level kind is a card, and so should add spacers between them
193
- visitRows(maybeSorted, !!nestedCards);
194
+ visitRows(maybeSorted, !!nestedCards, 0);
194
195
  nestedCards && nestedCards.done();
195
196
  return [headerRows, filteredRows];
196
197
  }, [
@@ -443,6 +444,9 @@ exports.calcColumnSizes = calcColumnSizes;
443
444
  function getIndentationCss(style, rowStyle, columnIndex, maybeContent) {
444
445
  // Look for cell-specific indent or row-specific indent (row-specific is only one the first column)
445
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
+ }
446
450
  return indent === 1 ? style.indentOneCss || {} : indent === 2 ? style.indentTwoCss || {} : {};
447
451
  }
448
452
  function getFirstOrLastCellCss(style, columnIndex, columns) {
@@ -453,7 +457,7 @@ function getFirstOrLastCellCss(style, columnIndex, columns) {
453
457
  }
454
458
  // We extract GridRow to its own mini-component primarily so we can React.memo'ize it.
455
459
  function GridRow(props) {
456
- 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;
457
461
  // We treat the "header" kind as special for "good defaults" styling
458
462
  const isHeader = row.kind === "header";
459
463
  const rowStyle = rowStyles === null || rowStyles === void 0 ? void 0 : rowStyles[row.kind];
@@ -480,7 +484,7 @@ function GridRow(props) {
480
484
  };
481
485
  let currentColspan = 1;
482
486
  const rowNode = ((0, jsx_runtime_1.jsx)(Row, Object.assign({ css: rowCss }, others, { "data-gridrow": true }, { children: columns.map((column, columnIndex) => {
483
- var _a;
487
+ var _a, _b;
484
488
  if (column.mw) {
485
489
  // Validate the column's minWidth definition if set.
486
490
  if (!column.mw.endsWith("px") && !column.mw.endsWith("%")) {
@@ -522,6 +526,8 @@ function GridRow(props) {
522
526
  ...getIndentationCss(style, rowStyle, columnIndex, maybeContent),
523
527
  // Then apply any header-specific override
524
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)),
525
531
  // The specific cell's css (if any from GridCellContent)
526
532
  ...rowStyleCellCss,
527
533
  // Add any cell specific style overrides
@@ -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.10",
3
+ "version": "2.106.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",