@homebound/beam 2.209.3 → 2.209.4

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.
@@ -118,7 +118,8 @@ function GridTable(props) {
118
118
  // (or us) is resetting component state more than necessary, so we track render counts from
119
119
  // here instead.
120
120
  const { getCount } = (0, useRenderCount_1.useRenderCount)();
121
- const columnSizes = (0, useSetupColumnSizes_1.useSetupColumnSizes)(style, columns, resizeTarget !== null && resizeTarget !== void 0 ? resizeTarget : resizeRef);
121
+ const expandedColumnIds = (0, hooks_1.useComputed)(() => tableState.expandedColumnIds, [tableState]);
122
+ const columnSizes = (0, useSetupColumnSizes_1.useSetupColumnSizes)(style, columns, resizeTarget !== null && resizeTarget !== void 0 ? resizeTarget : resizeRef, expandedColumnIds);
122
123
  // Make a single copy of our current collapsed state, so we'll have a single observer.
123
124
  const collapsedIds = (0, hooks_1.useComputed)(() => tableState.collapsedIds, [tableState]);
124
125
  const sortState = (0, hooks_1.useComputed)(() => (0, mobx_1.toJS)(tableState.sortState), [tableState]);
@@ -365,7 +366,11 @@ function renderVirtual(style, id, columns, headerRows, totalsRows, expandableHea
365
366
  }
366
367
  // Lastly render `filteredRow`
367
368
  return visibleDataRows[index][1];
368
- }, totalCount: (headerRows.length || 0) + (totalsRows.length || 0) + (firstRowMessage ? 1 : 0) + (visibleDataRows.length || 0) }, void 0));
369
+ }, totalCount: headerRows.length +
370
+ totalsRows.length +
371
+ expandableHeaderRows.length +
372
+ (firstRowMessage ? 1 : 0) +
373
+ visibleDataRows.length }, void 0));
369
374
  }
370
375
  /**
371
376
  * A table might render two of these components to represent two virtual lists.
@@ -72,9 +72,10 @@ function RowImpl(props) {
72
72
  let firstContentColumnStylesApplied = false;
73
73
  let minStickyLeftOffset = 0;
74
74
  return ((0, jsx_runtime_1.jsx)(RowTag, Object.assign({ css: rowCss }, others, { "data-gridrow": true }, getCount(row.id), { children: columns.map((column, columnIndex) => {
75
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
75
+ var _a, _b, _c, _d, _e, _f;
76
76
  // Need to keep track of the expanded columns so we can add borders as expected for the header rows
77
77
  const isExpanded = tableState.expandedColumnIds.includes(column.id);
78
+ const numExpandedColumns = isExpanded ? (_b = (_a = column.expandColumns) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
78
79
  const { wrapAction = true, isAction = false } = column;
79
80
  const applyFirstContentColumnStyles = !isHeader && !isAction && !firstContentColumnStylesApplied;
80
81
  firstContentColumnStylesApplied || (firstContentColumnStylesApplied = applyFirstContentColumnStyles);
@@ -84,12 +85,13 @@ function RowImpl(props) {
84
85
  throw new Error("Beam Table column min-width definition only supports px or percentage values");
85
86
  }
86
87
  }
87
- // When using the variation of the table with an EXPANDABLE_HEADER, then our HEADER row required special border styling
88
+ // When using the variation of the table with an EXPANDABLE_HEADER, then our HEADER and TOTAL rows have special border styling
89
+ // Keep track of the when we get to the last expanded column so we can apply this styling properly.
88
90
  if (hasExpandableHeader && (isHeader || isTotals)) {
89
91
  // When the value of `currentExpandedColumnCount` is 0, then we have started over.
90
92
  // If the current column `isExpanded`, then store the number of expandable columns.
91
93
  if (currentExpandedColumnCount === 0 && isExpanded) {
92
- currentExpandedColumnCount = (_b = (_a = column.expandColumns) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
94
+ currentExpandedColumnCount = numExpandedColumns;
93
95
  }
94
96
  else if (currentExpandedColumnCount > 0) {
95
97
  // If value is great than 0, then decrement. Once the value equals 0, then the special styling will be applied below.
@@ -102,19 +104,22 @@ function RowImpl(props) {
102
104
  return null;
103
105
  }
104
106
  const maybeContent = (0, utils_1.applyRowFn)(column, row, api, level, isExpanded);
105
- const numExpandedColumns = isExpandableHeader && isExpanded ? (_d = (_c = column.expandColumns) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0 : 0;
106
- currentColspan = (0, utils_1.isGridCellContent)(maybeContent)
107
- ? (_e = maybeContent.colspan) !== null && _e !== void 0 ? _e : numExpandedColumns + 1
108
- : numExpandedColumns + 1;
107
+ // Only use the `numExpandedColumns` as the `colspan` when rendering the "Expandable Header"
108
+ currentColspan =
109
+ (0, utils_1.isGridCellContent)(maybeContent) && typeof maybeContent.colspan === "number"
110
+ ? maybeContent.colspan
111
+ : isExpandableHeader
112
+ ? numExpandedColumns + 1
113
+ : 1;
109
114
  const revealOnRowHover = (0, utils_1.isGridCellContent)(maybeContent) ? maybeContent.revealOnRowHover : false;
110
115
  const canSortColumn = (sortOn === "client" && column.clientSideSort !== false) ||
111
116
  (sortOn === "server" && !!column.serverSideSortKey);
112
117
  const alignment = (0, utils_1.getAlignment)(column, maybeContent);
113
118
  const justificationCss = (0, utils_1.getJustification)(column, maybeContent, as, alignment);
114
- const isExpandable = column.expandColumns !== undefined && column.expandColumns.length > 0;
119
+ const isExpandable = (column.expandColumns && column.expandColumns.length > 0) || column.expandedWidth !== undefined;
115
120
  const content = (0, utils_1.toContent)(maybeContent, isHeader, canSortColumn, sortOn === "client", style, as, alignment, column, isExpandableHeader, isExpandable, minStickyLeftOffset);
116
121
  (0, sortRows_1.ensureClientSideSortValueIsSortable)(sortOn, isHeader || isTotals || isExpandableHeader, column, columnIndex, maybeContent);
117
- const maybeSticky = (_f = (((0, utils_1.isGridCellContent)(maybeContent) && maybeContent.sticky) || column.sticky)) !== null && _f !== void 0 ? _f : undefined;
122
+ const maybeSticky = (_c = (((0, utils_1.isGridCellContent)(maybeContent) && maybeContent.sticky) || column.sticky)) !== null && _c !== void 0 ? _c : undefined;
118
123
  const maybeStickyColumnStyles = maybeSticky && columnSizes
119
124
  ? {
120
125
  ...Css_1.Css.sticky.z(utils_1.zIndices.stickyColumns).bgWhite.$,
@@ -167,13 +172,13 @@ function RowImpl(props) {
167
172
  currentExpandedColumnCount === 0 &&
168
173
  Css_1.Css.boxShadow(`inset -1px -1px 0 ${Css_1.Palette.Gray200}`).$),
169
174
  // Or level-specific styling
170
- ...(!isHeader && !isTotals && !isExpandableHeader && !!style.levels && ((_g = style.levels[level]) === null || _g === void 0 ? void 0 : _g.cellCss)),
175
+ ...(!isHeader && !isTotals && !isExpandableHeader && !!style.levels && ((_d = style.levels[level]) === null || _d === void 0 ? void 0 : _d.cellCss)),
171
176
  // Level specific styling for the first content column
172
- ...(applyFirstContentColumnStyles && !!style.levels && ((_h = style.levels[level]) === null || _h === void 0 ? void 0 : _h.firstContentColumn)),
177
+ ...(applyFirstContentColumnStyles && !!style.levels && ((_e = style.levels[level]) === null || _e === void 0 ? void 0 : _e.firstContentColumn)),
173
178
  // The specific cell's css (if any from GridCellContent)
174
179
  ...rowStyleCellCss,
175
180
  // Apply active row styling for non-nested card styles.
176
- ...(isActive ? Css_1.Css.bgColor((_j = style.activeBgColor) !== null && _j !== void 0 ? _j : Css_1.Palette.LightBlue50).$ : {}),
181
+ ...(isActive ? Css_1.Css.bgColor((_f = style.activeBgColor) !== null && _f !== void 0 ? _f : Css_1.Palette.LightBlue50).$ : {}),
177
182
  // Add any cell specific style overrides
178
183
  ...((0, utils_1.isGridCellContent)(maybeContent) && maybeContent.typeScale ? Css_1.Css[maybeContent.typeScale].$ : {}),
179
184
  // And any cell specific css
@@ -186,12 +191,10 @@ function RowImpl(props) {
186
191
  };
187
192
  const cellClassNames = revealOnRowHover ? revealOnRowHoverClass : undefined;
188
193
  const cellOnClick = applyCellHighlight ? () => api.setActiveCellId(cellId) : undefined;
189
- // If the expandable header is expanded, then we need to set a colspan on it which includes all expanded columns + this column.
190
- const expandableHeaderColSpan = (isExpandableHeader && isExpanded ? (_l = (_k = column.expandColumns) === null || _k === void 0 ? void 0 : _k.length) !== null && _l !== void 0 ? _l : 0 : 0) + 1;
191
194
  const renderFn = ((rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.renderCell) || (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.rowLink)) && wrapAction
192
195
  ? (0, cell_1.rowLinkRenderFn)(as)
193
196
  : isHeader || isTotals || isExpandableHeader
194
- ? (0, cell_1.headerRenderFn)(column, as, expandableHeaderColSpan)
197
+ ? (0, cell_1.headerRenderFn)(column, as, currentColspan)
195
198
  : (rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle.onClick) && wrapAction
196
199
  ? (0, cell_1.rowClickRenderFn)(as, api)
197
200
  : (0, cell_1.defaultRenderFn)(as);
@@ -1,6 +1,6 @@
1
1
  import { MutableRefObject } from "react";
2
2
  import { GridStyle } from "../TableStyles";
3
- import { GridColumn } from "../types";
3
+ import { GridColumnWithId } from "../types";
4
4
  /**
5
5
  * Calculates an array of sizes for each of our columns.
6
6
  *
@@ -20,4 +20,4 @@ import { GridColumn } from "../types";
20
20
  *
21
21
  * Disclaimer that we roll our own `fr` b/c we're not in CSS grid anymore.
22
22
  */
23
- export declare function useSetupColumnSizes(style: GridStyle, columns: GridColumn<any>[], resizeRef: MutableRefObject<HTMLElement | null>): string[];
23
+ export declare function useSetupColumnSizes(style: GridStyle, columns: GridColumnWithId<any>[], resizeRef: MutableRefObject<HTMLElement | null>, expandedColumnIds: string[]): string[];
@@ -24,17 +24,17 @@ const use_debounce_1 = require("use-debounce");
24
24
  *
25
25
  * Disclaimer that we roll our own `fr` b/c we're not in CSS grid anymore.
26
26
  */
27
- function useSetupColumnSizes(style, columns, resizeRef) {
27
+ function useSetupColumnSizes(style, columns, resizeRef, expandedColumnIds) {
28
28
  // Calculate the column sizes immediately rather than via the `debounce` method.
29
29
  // We do this for Storybook integrations that may use MockDate. MockDate changes the behavior of `new Date()`,
30
30
  // which is used internally by `useDebounce`, so the frozen clock means the callback is never called.
31
31
  const calculateImmediately = (0, react_1.useRef)(true);
32
32
  const [tableWidth, setTableWidth] = (0, react_1.useState)();
33
33
  // Calc our initial/first render sizes where we won't have a width yet
34
- const [columnSizes, setColumnSizes] = (0, react_1.useState)((0, columns_1.calcColumnSizes)(columns, tableWidth, style.minWidthPx));
34
+ const [columnSizes, setColumnSizes] = (0, react_1.useState)((0, columns_1.calcColumnSizes)(columns, tableWidth, style.minWidthPx, expandedColumnIds));
35
35
  const setTableAndColumnWidths = (0, react_1.useCallback)((width) => {
36
36
  setTableWidth(width);
37
- setColumnSizes((0, columns_1.calcColumnSizes)(columns, width, style.minWidthPx));
37
+ setColumnSizes((0, columns_1.calcColumnSizes)(columns, width, style.minWidthPx, expandedColumnIds));
38
38
  }, [setTableWidth, setColumnSizes, columns, style]);
39
39
  // Used to recalculate our columns sizes when columns change
40
40
  (0, react_1.useEffect)(() => {
@@ -52,6 +52,10 @@ export declare type GridColumn<R extends Kinded> = {
52
52
  * - The default value is `1fr`
53
53
  */
54
54
  w?: number | string;
55
+ /** Represents the width the column will get when expanded. This prop is treated the same as the `GridColumn.w` prop.
56
+ * Example: Collapsed state shows number of books. Expanded state shows titles of books.
57
+ */
58
+ expandedWidth?: number | string;
55
59
  /** The minimum width the column can shrink to */
56
60
  mw?: string;
57
61
  /** The column's default alignment for each cell. */
@@ -28,7 +28,7 @@ export declare function collapseColumn<T extends Kinded>(columnDef?: Partial<Gri
28
28
  * Calculates column widths using a flexible `calc()` definition that allows for consistent column alignment without the use of `<table />`, CSS Grid, etc layouts.
29
29
  * Enforces only fixed-sized units (% and px)
30
30
  */
31
- export declare function calcColumnSizes(columns: GridColumn<any>[], tableWidth: number | undefined, tableMinWidthPx?: number): string[];
31
+ export declare function calcColumnSizes(columns: GridColumnWithId<any>[], tableWidth: number | undefined, tableMinWidthPx: number | undefined, expandedColumnIds: string[]): string[];
32
32
  /** Assign column ids if missing */
33
33
  export declare function assignDefaultColumnIds<T extends Kinded>(columns: GridColumn<T>[]): GridColumnWithId<T>[];
34
34
  export declare const generateColumnId: (columnIndex: number) => string;
@@ -97,7 +97,7 @@ function nonKindDefaults() {
97
97
  * Calculates column widths using a flexible `calc()` definition that allows for consistent column alignment without the use of `<table />`, CSS Grid, etc layouts.
98
98
  * Enforces only fixed-sized units (% and px)
99
99
  */
100
- function calcColumnSizes(columns, tableWidth, tableMinWidthPx = 0) {
100
+ function calcColumnSizes(columns, tableWidth, tableMinWidthPx = 0, expandedColumnIds) {
101
101
  // For both default columns (1fr) as well as `w: 4fr` columns, we translate the width into an expression that looks like:
102
102
  // calc((100% - allOtherPercent - allOtherPx) * ((myFr / totalFr))`
103
103
  //
@@ -106,7 +106,8 @@ function calcColumnSizes(columns, tableWidth, tableMinWidthPx = 0) {
106
106
  // Unfortunately, something about having our header & body rows in separate divs (which is controlled
107
107
  // by react-virtuoso), even if they have the same width, for some reason `fr` units between the two
108
108
  // will resolve every slightly differently, where as this approach they will match exactly.
109
- const { claimedPercentages, claimedPixels, totalFr } = columns.reduce((acc, { w }) => {
109
+ const { claimedPercentages, claimedPixels, totalFr } = columns.reduce((acc, { id, w: _w, expandedWidth }) => {
110
+ const w = expandedColumnIds.includes(id) && expandedWidth !== undefined ? expandedWidth : _w;
110
111
  if (typeof w === "undefined") {
111
112
  return { ...acc, totalFr: acc.totalFr + 1 };
112
113
  }
@@ -136,7 +137,8 @@ function calcColumnSizes(columns, tableWidth, tableMinWidthPx = 0) {
136
137
  // Otherwise return the `calc()` value
137
138
  return `((100% - ${claimedPercentages}% - ${claimedPixels}px) * (${myFr} / ${totalFr}))`;
138
139
  }
139
- let sizes = columns.map(({ w }) => {
140
+ let sizes = columns.map(({ id, expandedWidth, w: _w }) => {
141
+ const w = expandedColumnIds.includes(id) && expandedWidth !== undefined ? expandedWidth : _w;
140
142
  if (typeof w === "undefined") {
141
143
  return fr(1);
142
144
  }
@@ -164,8 +166,8 @@ function assignDefaultColumnIds(columns) {
164
166
  // exists as part of `selectColumn` and `collapseColumn`.
165
167
  return columns.map((c, idx) => {
166
168
  var _a;
167
- const { expandColumns = [] } = c;
168
- const expandColumnsWithId = expandColumns.map((ec, ecIdx) => {
169
+ const { expandColumns } = c;
170
+ const expandColumnsWithId = expandColumns === null || expandColumns === void 0 ? void 0 : expandColumns.map((ec, ecIdx) => {
169
171
  var _a;
170
172
  return ({
171
173
  ...ec,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.209.3",
3
+ "version": "2.209.4",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",