@homebound/beam 2.343.2 → 2.343.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.
@@ -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
- return `(${(widthBasis - (claimedPercentages / 100) * widthBasis - claimedPixels) * (myFr / totalFr)}px)`;
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
+ }
@@ -59,7 +59,7 @@ function ComboBoxBase(props) {
59
59
  // Though, it is possible that the `options` prop has changed, which is a dependency on this `useMemo`.
60
60
  // That could trigger an unnecessary new reference for `selectedOptions`, and cause additional renders or unexpected state changes.
61
61
  // We should avoid updating `selectedOptions` unless `values` has actually changed.
62
- if (!(0, fast_deep_equal_1.default)(values.sort(), selectedOptionsRef.current.map(getOptionValue).sort())) {
62
+ if (!(0, fast_deep_equal_1.default)([...values].sort(), selectedOptionsRef.current.map(getOptionValue).sort())) {
63
63
  selectedOptionsRef.current = options.filter((o) => values.includes(getOptionValue(o)));
64
64
  }
65
65
  return selectedOptionsRef.current;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.343.2",
3
+ "version": "2.343.4",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",