@homebound/beam 2.97.5 → 2.98.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.
|
@@ -188,7 +188,7 @@ export declare function GridTable<R extends Kinded, S = {}, X extends Only<GridT
|
|
|
188
188
|
*
|
|
189
189
|
* When we're as=virtual, we change our default + enforce only fixed-sized units (% and px)
|
|
190
190
|
*/
|
|
191
|
-
export declare function calcVirtualGridColumns(columns: GridColumn<any>[], firstLastColumnWidth: number | undefined): string;
|
|
191
|
+
export declare function calcVirtualGridColumns(columns: GridColumn<any>[], firstLastColumnWidth: number | undefined): string[];
|
|
192
192
|
export declare function calcDivGridColumns(columns: GridColumn<any>[], firstLastColumnWidth: number | undefined): string;
|
|
193
193
|
/**
|
|
194
194
|
* Given an ADT of type T, performs a look up and returns the type of kind K.
|
|
@@ -103,8 +103,10 @@ function GridTable(props) {
|
|
|
103
103
|
}, [columns, rows, sorting, sortState]);
|
|
104
104
|
// Filter + flatten + component-ize the sorted rows.
|
|
105
105
|
let [headerRows, filteredRows] = (0, react_1.useMemo)(() => {
|
|
106
|
+
var _a;
|
|
106
107
|
// Break up "foo bar" into `[foo, bar]` and a row must match both `foo` and `bar`
|
|
107
108
|
const filters = (filter && filter.split(/ +/)) || [];
|
|
109
|
+
const columnSizes = as === "virtual" ? calcVirtualGridColumns(columns, (_a = style.nestedCards) === null || _a === void 0 ? void 0 : _a.firstLastColumnWidth) : undefined;
|
|
108
110
|
function makeRowComponent(row) {
|
|
109
111
|
// We only pass sortState to header rows, b/c non-headers rows shouldn't have to re-render on sorting
|
|
110
112
|
// changes, and so by not passing the sortProps, it means the data rows' React.memo will still cache them.
|
|
@@ -119,6 +121,7 @@ function GridTable(props) {
|
|
|
119
121
|
stickyHeader,
|
|
120
122
|
stickyOffset,
|
|
121
123
|
openCards: nestedCards ? nestedCards.currentOpenCards() : undefined,
|
|
124
|
+
columnSizes,
|
|
122
125
|
...sortProps,
|
|
123
126
|
}), `${row.kind}-${row.id}`) }), `${row.kind}-${row.id}`));
|
|
124
127
|
}
|
|
@@ -303,11 +306,8 @@ const VirtualRoot = (0, memoize_one_1.default)((gs, columns, id, firstLastColumn
|
|
|
303
306
|
return react_1.default.forwardRef(function VirtualRoot({ style, children }, ref) {
|
|
304
307
|
// This re-renders each time we have new children in the view port
|
|
305
308
|
return ((0, jsx_runtime_1.jsx)("div", Object.assign({ ref: ref, style: style, css: {
|
|
306
|
-
...Css_1.Css.dg.gtc(calcVirtualGridColumns(columns, firstLastColumnWidth)).$,
|
|
307
309
|
// Add an extra `> div` due to Item + itemContent both having divs
|
|
308
|
-
...Css_1.Css.addIn("& > div + div > div
|
|
309
|
-
// Add `display:contents` to Item to flatten it like we do GridRow
|
|
310
|
-
...Css_1.Css.addIn("& > div", Css_1.Css.display("contents").$).$,
|
|
310
|
+
...Css_1.Css.addIn("& > div + div > div", gs.betweenRowsCss || {}).$,
|
|
311
311
|
...gs.rootCss,
|
|
312
312
|
...xss,
|
|
313
313
|
}, "data-testid": id }, { children: children }), void 0));
|
|
@@ -355,7 +355,7 @@ function calcVirtualGridColumns(columns, firstLastColumnWidth) {
|
|
|
355
355
|
}, { claimedPercentages: 0, claimedPixels: firstLastColumnWidth ? firstLastColumnWidth * 2 : 0, totalFr: 0 });
|
|
356
356
|
// This is our "fake but for some reason it lines up better" fr calc
|
|
357
357
|
function fr(myFr) {
|
|
358
|
-
return `
|
|
358
|
+
return `((100% - ${claimedPercentages}% - ${claimedPixels}px) * (${myFr} / ${totalFr}))`;
|
|
359
359
|
}
|
|
360
360
|
let sizes = columns.map(({ w }) => {
|
|
361
361
|
if (typeof w === "undefined") {
|
|
@@ -394,12 +394,12 @@ function calcDivGridColumns(columns, firstLastColumnWidth) {
|
|
|
394
394
|
return `${w}fr`;
|
|
395
395
|
}
|
|
396
396
|
});
|
|
397
|
-
return maybeAddCardColumns(sizes, firstLastColumnWidth);
|
|
397
|
+
return maybeAddCardColumns(sizes, firstLastColumnWidth).join(" ");
|
|
398
398
|
}
|
|
399
399
|
exports.calcDivGridColumns = calcDivGridColumns;
|
|
400
400
|
// If we're doing nested cards, we add extra 1st/last cells...
|
|
401
401
|
function maybeAddCardColumns(sizes, firstLastColumnWidth) {
|
|
402
|
-
return
|
|
402
|
+
return !firstLastColumnWidth ? sizes : [`${firstLastColumnWidth}px`, ...sizes, `${firstLastColumnWidth}px`];
|
|
403
403
|
}
|
|
404
404
|
function getIndentationCss(style, rowStyle, columnIndex, maybeContent) {
|
|
405
405
|
// Look for cell-specific indent or row-specific indent (row-specific is only one the first column)
|
|
@@ -414,7 +414,7 @@ function getFirstOrLastCellCss(style, columnIndex, columns) {
|
|
|
414
414
|
}
|
|
415
415
|
// We extract GridRow to its own mini-component primarily so we can React.memo'ize it.
|
|
416
416
|
function GridRow(props) {
|
|
417
|
-
const { as, columns, row, style, rowStyles, stickyHeader, stickyOffset, sorting, sortState, setSortKey, openCards, ...others } = props;
|
|
417
|
+
const { as, columns, row, style, rowStyles, stickyHeader, stickyOffset, sorting, sortState, setSortKey, openCards, columnSizes, ...others } = props;
|
|
418
418
|
// We treat the "header" kind as special for "good defaults" styling
|
|
419
419
|
const isHeader = row.kind === "header";
|
|
420
420
|
const rowStyle = rowStyles === null || rowStyles === void 0 ? void 0 : rowStyles[row.kind];
|
|
@@ -425,7 +425,7 @@ function GridRow(props) {
|
|
|
425
425
|
// root-element > row-element > cell-elements, so that we can have a hook for
|
|
426
426
|
// hovers and styling. In theory this would change with subgrids.
|
|
427
427
|
// Only enable when using div as elements
|
|
428
|
-
...(as === "table" ? {} : Css_1.Css.display("contents").$),
|
|
428
|
+
...(as === "table" ? {} : as === "virtual" ? Css_1.Css.df.$ : Css_1.Css.display("contents").$),
|
|
429
429
|
...(((rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.rowLink) || (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.onClick)) &&
|
|
430
430
|
style.rowHoverColor && {
|
|
431
431
|
// Even though backgroundColor is set on the cellCss (due to display: content), the hover target is the row.
|
|
@@ -443,7 +443,11 @@ function GridRow(props) {
|
|
|
443
443
|
const currentCard = openCardStyles && openCardStyles[openCardStyles.length - 1];
|
|
444
444
|
let currentColspan = 1;
|
|
445
445
|
const maybeStickyHeaderStyles = isHeader && stickyHeader ? Css_1.Css.sticky.top(stickyOffset).z1.$ : undefined;
|
|
446
|
-
return ((0, jsx_runtime_1.jsxs)(Row, Object.assign({ css: rowCss }, others, { children: [openCardStyles &&
|
|
446
|
+
return ((0, jsx_runtime_1.jsxs)(Row, Object.assign({ css: rowCss }, others, { children: [openCardStyles &&
|
|
447
|
+
(0, nestedCards_1.maybeAddCardPadding)(openCardStyles, "first", {
|
|
448
|
+
...maybeStickyHeaderStyles,
|
|
449
|
+
...(columnSizes ? Css_1.Css.w(columnSizes[0]).$ : {}),
|
|
450
|
+
}), columns.map((column, columnIndex) => {
|
|
447
451
|
var _a;
|
|
448
452
|
// Decrement colspan count and skip if greater than 1.
|
|
449
453
|
if (currentColspan > 1) {
|
|
@@ -456,6 +460,7 @@ function GridRow(props) {
|
|
|
456
460
|
((sorting === null || sorting === void 0 ? void 0 : sorting.on) === "server" && !!column.serverSideSortKey);
|
|
457
461
|
const content = toContent(maybeContent, isHeader, canSortColumn, (sorting === null || sorting === void 0 ? void 0 : sorting.on) === "client", style, as);
|
|
458
462
|
(0, sortRows_1.ensureClientSideSortValueIsSortable)(sorting, isHeader, column, columnIndex, maybeContent);
|
|
463
|
+
const maybeNestedCardColumnIndex = columnIndex + (style.nestedCards ? 1 : 0);
|
|
459
464
|
// Note that it seems expensive to calc a per-cell class name/CSS-in-JS output,
|
|
460
465
|
// vs. setting global/table-wide CSS like `style.cellCss` on the root grid div with
|
|
461
466
|
// a few descendent selectors. However, that approach means the root grid-applied
|
|
@@ -477,6 +482,10 @@ function GridRow(props) {
|
|
|
477
482
|
...getIndentationCss(style, rowStyle, columnIndex, maybeContent),
|
|
478
483
|
// Then apply any header-specific override
|
|
479
484
|
...(isHeader && style.headerCellCss),
|
|
485
|
+
// Non-virtualized tables use h100 so that all cells are the same height across the row.
|
|
486
|
+
// Virtualized table rows use `display: flex;`, so the flex children are set to `align-self: stretch` by default, which achieves the same goal.
|
|
487
|
+
// Though, we need to omit setting `h100` on the flex children, as a flex container needs a defined height set for `h100` to work on flex children
|
|
488
|
+
...(isHeader && as !== "virtual" ? Css_1.Css.h100.$ : undefined),
|
|
480
489
|
...maybeStickyHeaderStyles,
|
|
481
490
|
// If we're within a card, use its background color
|
|
482
491
|
...(currentCard && Css_1.Css.bgColor(currentCard.bgColor).$),
|
|
@@ -484,6 +493,12 @@ function GridRow(props) {
|
|
|
484
493
|
...(currentColspan > 1 ? Css_1.Css.gc(`span ${currentColspan}`).$ : {}),
|
|
485
494
|
// And finally the specific cell's css (if any from GridCellContent)
|
|
486
495
|
...rowStyleCellCss,
|
|
496
|
+
// For virtual tables we define the width of the column on each cell. Supports col spans.
|
|
497
|
+
...(columnSizes && {
|
|
498
|
+
width: `calc(${columnSizes
|
|
499
|
+
.slice(maybeNestedCardColumnIndex, maybeNestedCardColumnIndex + currentColspan)
|
|
500
|
+
.join(" + ")})`,
|
|
501
|
+
}),
|
|
487
502
|
};
|
|
488
503
|
const renderFn = (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.renderCell) || (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.rowLink)
|
|
489
504
|
? rowLinkRenderFn(as)
|
|
@@ -493,7 +508,11 @@ function GridRow(props) {
|
|
|
493
508
|
? rowClickRenderFn(as)
|
|
494
509
|
: defaultRenderFn(as);
|
|
495
510
|
return renderFn(columnIndex, cellCss, content, row, rowStyle);
|
|
496
|
-
}), openCardStyles &&
|
|
511
|
+
}), openCardStyles &&
|
|
512
|
+
(0, nestedCards_1.maybeAddCardPadding)(openCardStyles, "final", {
|
|
513
|
+
...maybeStickyHeaderStyles,
|
|
514
|
+
...(columnSizes ? Css_1.Css.w(columnSizes[columnSizes.length - 1]).$ : {}),
|
|
515
|
+
})] }), void 0));
|
|
497
516
|
}
|
|
498
517
|
// Fix to work with generics, see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/37087#issuecomment-656596623
|
|
499
518
|
const MemoizedGridRow = react_1.default.memo(GridRow);
|
|
@@ -12,8 +12,7 @@ exports.defaultStyle = {
|
|
|
12
12
|
lastCellCss: Css_1.Css.$,
|
|
13
13
|
indentOneCss: Css_1.Css.pl4.$,
|
|
14
14
|
indentTwoCss: Css_1.Css.pl7.$,
|
|
15
|
-
|
|
16
|
-
headerCellCss: Css_1.Css.asfe.nowrap.py1.bgGray100.h100.aife.$,
|
|
15
|
+
headerCellCss: Css_1.Css.asfe.nowrap.py1.bgGray100.aife.$,
|
|
17
16
|
firstRowMessageCss: Css_1.Css.px1.py2.$,
|
|
18
17
|
rowHoverColor: Css_1.Palette.Gray200,
|
|
19
18
|
};
|