@homebound/beam 2.343.3 → 2.343.5
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/dist/components/Table/GridTable.js +4 -2
- package/dist/components/Table/components/Row.js +0 -7
- package/dist/components/Table/types.d.ts +1 -1
- package/dist/components/Table/utils/columns.js +41 -6
- package/dist/components/Table/utils/utils.d.ts +3 -0
- package/dist/components/Table/utils/utils.js +7 -1
- package/package.json +1 -1
|
@@ -293,7 +293,7 @@ function GridTable(props) {
|
|
|
293
293
|
// behave semantically the same as `as=div` did for its tests.
|
|
294
294
|
const _as = as === "virtual" && runningInJest ? "div" : as;
|
|
295
295
|
const rowStateContext = (0, react_1.useMemo)(() => ({ tableState: tableState }), [tableState]);
|
|
296
|
-
return ((0, jsx_runtime_1.jsx)(TableState_1.TableStateContext.Provider, { value: rowStateContext, children: (0, jsx_runtime_1.jsxs)(PresentationContext_1.PresentationProvider, { fieldProps: fieldProps, wrap: (_c = style === null || style === void 0 ? void 0 : style.presentationSettings) === null || _c === void 0 ? void 0 : _c.wrap, children: [(0, jsx_runtime_1.jsx)("div", { ref: resizeRef, css:
|
|
296
|
+
return ((0, jsx_runtime_1.jsx)(TableState_1.TableStateContext.Provider, { value: rowStateContext, children: (0, jsx_runtime_1.jsxs)(PresentationContext_1.PresentationProvider, { fieldProps: fieldProps, wrap: (_c = style === null || style === void 0 ? void 0 : style.presentationSettings) === null || _c === void 0 ? void 0 : _c.wrap, children: [(0, jsx_runtime_1.jsx)("div", { ref: resizeRef, css: (0, components_1.getTableRefWidthStyles)(as === "virtual") }), renders[_as](style, id, columns, visibleDataRows, keptSelectedRows, firstRowMessage, stickyHeader, xss, virtuosoRef, tableHeadRows, stickyOffset, infiniteScroll)] }) }));
|
|
297
297
|
}
|
|
298
298
|
exports.GridTable = GridTable;
|
|
299
299
|
// Determine which HTML element to use to build the GridTable
|
|
@@ -391,7 +391,9 @@ function renderVirtual(style, id, columns, visibleDataRows, keptSelectedRows, fi
|
|
|
391
391
|
// Show firstRowMessage as the first `filteredRow`
|
|
392
392
|
if (firstRowMessage) {
|
|
393
393
|
if (index === 0) {
|
|
394
|
-
return (
|
|
394
|
+
return (
|
|
395
|
+
// Ensure the fallback message is the same width as the table
|
|
396
|
+
(0, jsx_runtime_1.jsx)("div", { css: (0, components_1.getTableRefWidthStyles)(true), children: (0, jsx_runtime_1.jsx)("div", { css: { ...style.firstRowMessageCss }, children: firstRowMessage }) }));
|
|
395
397
|
}
|
|
396
398
|
// Shift index -1 when there is a firstRowMessage to not skip the
|
|
397
399
|
// first `filteredRow`
|
|
@@ -98,12 +98,6 @@ function RowImpl(props) {
|
|
|
98
98
|
const isFirstContentColumn = !isAction && !foundFirstContentColumn;
|
|
99
99
|
const applyFirstContentColumnStyles = !isHeader && isFirstContentColumn;
|
|
100
100
|
foundFirstContentColumn || (foundFirstContentColumn = applyFirstContentColumnStyles);
|
|
101
|
-
if (column.mw) {
|
|
102
|
-
// Validate the column's minWidth definition if set.
|
|
103
|
-
if (!column.mw.endsWith("px") && !column.mw.endsWith("%")) {
|
|
104
|
-
throw new Error("Beam Table column min-width definition only supports px or percentage values");
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
101
|
// When using the variation of the table with an EXPANDABLE_HEADER, then our HEADER and TOTAL rows have special border styling
|
|
108
102
|
// Keep track of the when we get to the last expanded column so we can apply this styling properly.
|
|
109
103
|
if (hasExpandableHeader && (isHeader || isTotals)) {
|
|
@@ -219,7 +213,6 @@ function RowImpl(props) {
|
|
|
219
213
|
// Define the width of the column on each cell. Supports col spans.
|
|
220
214
|
// If we have a 'levelIndent' defined, then subtract that amount from the first content column's width to ensure all columns will still line up properly
|
|
221
215
|
width: `calc(${columnSizes.slice(columnIndex, columnIndex + currentColspan).join(" + ")}${applyFirstContentColumnStyles && levelIndent ? ` - ${levelIndent}px` : ""})`,
|
|
222
|
-
...(typeof column.mw === "string" ? Css_1.Css.mw(column.mw).$ : {}),
|
|
223
216
|
};
|
|
224
217
|
const cellClassNames = revealOnRowHover ? revealOnRowHoverClass : undefined;
|
|
225
218
|
const cellOnClick = applyCellHighlight ? () => api.setActiveCellId(cellId) : undefined;
|
|
@@ -54,7 +54,7 @@ export type GridColumn<R extends Kinded> = {
|
|
|
54
54
|
* Example: Collapsed state shows number of books. Expanded state shows titles of books.
|
|
55
55
|
*/
|
|
56
56
|
expandedWidth?: number | string;
|
|
57
|
-
/** The minimum width the column can shrink to */
|
|
57
|
+
/** The minimum width the column can shrink to. This must be defined in pixels */
|
|
58
58
|
mw?: string;
|
|
59
59
|
/** The column's default alignment for each cell. */
|
|
60
60
|
align?: GridCellAlignment;
|
|
@@ -131,34 +131,60 @@ function calcColumnSizes(columns, tableWidth, tableMinWidthPx = 0, expandedColum
|
|
|
131
131
|
throw new Error("Beam Table column width definition only supports px, percentage, or fr units");
|
|
132
132
|
}
|
|
133
133
|
}, { claimedPercentages: 0, claimedPixels: 0, totalFr: 0 });
|
|
134
|
+
// In the event a column defines a fractional unit (fr) as the `w` value and a `mw` value in pixels,
|
|
135
|
+
// it is possible that the min-width value will kick in and throw off our claimedPixel and totalFr calculations.
|
|
136
|
+
// Once a `tableWidth` is defined, then we can adjust the claimedPixels and totalFr based on minWidth being present for any columns
|
|
137
|
+
let adjustedClaimedPixels = claimedPixels;
|
|
138
|
+
let adjustedTotalFr = totalFr;
|
|
139
|
+
if (tableWidth) {
|
|
140
|
+
columns.forEach(({ w, mw }) => {
|
|
141
|
+
const frUnit = parseFr(w);
|
|
142
|
+
if (mw === undefined || frUnit === undefined)
|
|
143
|
+
return;
|
|
144
|
+
const mwPx = Number(mw.replace("px", ""));
|
|
145
|
+
const calcedWidth = (tableWidth - (claimedPercentages / 100) * tableWidth - adjustedClaimedPixels) * (frUnit / adjustedTotalFr);
|
|
146
|
+
// If the calculated width is less than the minWidth, then this column will be sized via pixels instead of `fr` units.
|
|
147
|
+
if (calcedWidth < mwPx) {
|
|
148
|
+
// Adjust the claimedPixels and totalFr accordingly
|
|
149
|
+
adjustedClaimedPixels += mwPx;
|
|
150
|
+
adjustedTotalFr -= frUnit;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
134
154
|
// This is our "fake but for some reason it lines up better" fr calc
|
|
135
|
-
function fr(myFr) {
|
|
155
|
+
function fr(myFr, mw) {
|
|
136
156
|
// If the tableWidth, then return a pixel value
|
|
137
157
|
if (tableWidth) {
|
|
138
158
|
const widthBasis = Math.max(tableWidth, tableMinWidthPx);
|
|
139
|
-
|
|
159
|
+
const calcedWidth = (widthBasis - (claimedPercentages / 100) * widthBasis - adjustedClaimedPixels) * (myFr / adjustedTotalFr);
|
|
160
|
+
return `${Math.max(calcedWidth, mw)}px`;
|
|
140
161
|
}
|
|
141
162
|
// Otherwise return the `calc()` value
|
|
142
163
|
return `((100% - ${claimedPercentages}% - ${claimedPixels}px) * (${myFr} / ${totalFr}))`;
|
|
143
164
|
}
|
|
144
|
-
const sizes = columns.map(({ id, expandedWidth, w: _w }) => {
|
|
165
|
+
const sizes = columns.map(({ id, expandedWidth, w: _w, mw: _mw }) => {
|
|
166
|
+
// Ensure `mw` is a pixel value if defined
|
|
167
|
+
if (_mw !== undefined && !_mw.endsWith("px")) {
|
|
168
|
+
throw new Error("Beam Table column minWidth definition only supports pixel units");
|
|
169
|
+
}
|
|
170
|
+
const mw = _mw ? Number(_mw.replace("px", "")) : 0;
|
|
145
171
|
const w = expandedColumnIds.includes(id) && expandedWidth !== undefined ? expandedWidth : _w;
|
|
146
172
|
if (typeof w === "undefined") {
|
|
147
|
-
return fr(1);
|
|
173
|
+
return fr(1, mw);
|
|
148
174
|
}
|
|
149
175
|
else if (typeof w === "string") {
|
|
150
176
|
if (w.endsWith("%") || w.endsWith("px")) {
|
|
151
177
|
return w;
|
|
152
178
|
}
|
|
153
179
|
else if (w.endsWith("fr")) {
|
|
154
|
-
return fr(Number(w.replace("fr", "")));
|
|
180
|
+
return fr(Number(w.replace("fr", "")), mw);
|
|
155
181
|
}
|
|
156
182
|
else {
|
|
157
183
|
throw new Error("Beam Table column width definition only supports px, percentage, or fr units");
|
|
158
184
|
}
|
|
159
185
|
}
|
|
160
186
|
else {
|
|
161
|
-
return fr(w);
|
|
187
|
+
return fr(w, mw);
|
|
162
188
|
}
|
|
163
189
|
});
|
|
164
190
|
return sizes;
|
|
@@ -226,3 +252,12 @@ function dragHandleColumn(columnDef) {
|
|
|
226
252
|
});
|
|
227
253
|
}
|
|
228
254
|
exports.dragHandleColumn = dragHandleColumn;
|
|
255
|
+
function parseFr(w) {
|
|
256
|
+
return typeof w === "number"
|
|
257
|
+
? w
|
|
258
|
+
: typeof w === "undefined"
|
|
259
|
+
? 1
|
|
260
|
+
: typeof w === "string" && w.endsWith("fr")
|
|
261
|
+
? Number(w.replace("fr", ""))
|
|
262
|
+
: undefined;
|
|
263
|
+
}
|
|
@@ -48,3 +48,6 @@ export declare function recursivelyGetContainingRow<R extends Kinded>(rowId: str
|
|
|
48
48
|
array: GridDataRow<R>[];
|
|
49
49
|
parent: GridDataRow<R> | undefined;
|
|
50
50
|
} | undefined;
|
|
51
|
+
export declare function getTableRefWidthStyles(isVirtual: boolean): {
|
|
52
|
+
width: import("csstype").Property.Width<string | 0> | undefined;
|
|
53
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.recursivelyGetContainingRow = exports.isCursorBelowMidpoint = exports.insertAtIndex = exports.loadArrayOrUndefined = exports.zIndices = exports.reservedRowKinds = exports.KEPT_GROUP = exports.EXPANDABLE_HEADER = exports.TOTALS = exports.HEADER = exports.matchesFilter = exports.maybeApplyFunction = exports.getJustification = exports.getAlignment = exports.getFirstOrLastCellCss = exports.emptyCell = exports.DESC = exports.ASC = exports.applyRowFn = exports.isGridCellContent = exports.toContent = void 0;
|
|
3
|
+
exports.getTableRefWidthStyles = exports.recursivelyGetContainingRow = exports.isCursorBelowMidpoint = exports.insertAtIndex = exports.loadArrayOrUndefined = exports.zIndices = exports.reservedRowKinds = exports.KEPT_GROUP = exports.EXPANDABLE_HEADER = exports.TOTALS = exports.HEADER = exports.matchesFilter = exports.maybeApplyFunction = exports.getJustification = exports.getAlignment = exports.getFirstOrLastCellCss = exports.emptyCell = exports.DESC = exports.ASC = exports.applyRowFn = exports.isGridCellContent = exports.toContent = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const Icon_1 = require("../../Icon");
|
|
6
6
|
const ExpandableHeader_1 = require("../components/ExpandableHeader");
|
|
@@ -200,3 +200,9 @@ function recursivelyGetContainingRow(rowId, rowArray, parent) {
|
|
|
200
200
|
return undefined;
|
|
201
201
|
}
|
|
202
202
|
exports.recursivelyGetContainingRow = recursivelyGetContainingRow;
|
|
203
|
+
function getTableRefWidthStyles(isVirtual) {
|
|
204
|
+
// If virtualized take some pixels off the width to accommodate when virtuoso's scrollbar is introduced.
|
|
205
|
+
// Otherwise a horizontal scrollbar will _always_ appear once the vertical scrollbar is needed
|
|
206
|
+
return Css_1.Css.w100.if(isVirtual).w("calc(100% - 20px)").$;
|
|
207
|
+
}
|
|
208
|
+
exports.getTableRefWidthStyles = getTableRefWidthStyles;
|