@hyddenlabs/hydn-ui 0.3.0-alpha.211 → 0.3.0-alpha.213
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/index.cjs +58 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +58 -4
- package/dist/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5138,12 +5138,66 @@ function DataTable({
|
|
|
5138
5138
|
onSearchChange(value);
|
|
5139
5139
|
}
|
|
5140
5140
|
};
|
|
5141
|
+
const tableContainerRef = React.useRef(null);
|
|
5142
|
+
const [visibleColumns, setVisibleColumns] = React.useState(() => columns);
|
|
5143
|
+
React.useEffect(() => {
|
|
5144
|
+
const container = tableContainerRef.current;
|
|
5145
|
+
if (!container) return;
|
|
5146
|
+
const hasHideableColumns = columns.some((col) => col.hidePriority !== void 0);
|
|
5147
|
+
const updateVisibleColumns = () => {
|
|
5148
|
+
if (!hasHideableColumns) {
|
|
5149
|
+
setVisibleColumns(columns);
|
|
5150
|
+
return;
|
|
5151
|
+
}
|
|
5152
|
+
const containerWidth2 = container.offsetWidth;
|
|
5153
|
+
const hideableColumns = columns.map((col, index) => ({ col, originalIndex: index })).filter(({ col }) => col.hidePriority !== void 0).sort((a, b) => {
|
|
5154
|
+
if (a.col.hidePriority !== b.col.hidePriority) {
|
|
5155
|
+
return (a.col.hidePriority ?? 0) - (b.col.hidePriority ?? 0);
|
|
5156
|
+
}
|
|
5157
|
+
return a.originalIndex - b.originalIndex;
|
|
5158
|
+
});
|
|
5159
|
+
const nonHideableColumns = columns.filter((col) => col.hidePriority === void 0);
|
|
5160
|
+
const estimateColumnWidth = (col) => {
|
|
5161
|
+
if (col.width) {
|
|
5162
|
+
const match = col.width.match(/(\d+)/);
|
|
5163
|
+
if (match) {
|
|
5164
|
+
const num = parseInt(match[1], 10);
|
|
5165
|
+
if (col.width.includes("px")) return num;
|
|
5166
|
+
return num * 4;
|
|
5167
|
+
}
|
|
5168
|
+
}
|
|
5169
|
+
return 150;
|
|
5170
|
+
};
|
|
5171
|
+
let currentWidth = nonHideableColumns.reduce((sum, col) => sum + estimateColumnWidth(col), 0);
|
|
5172
|
+
if (selectable) currentWidth += 48;
|
|
5173
|
+
if (actions) currentWidth += 128;
|
|
5174
|
+
const columnsToShow = [...nonHideableColumns];
|
|
5175
|
+
for (const { col } of hideableColumns) {
|
|
5176
|
+
const colWidth = estimateColumnWidth(col);
|
|
5177
|
+
if (currentWidth + colWidth <= containerWidth2 - 32) {
|
|
5178
|
+
columnsToShow.push(col);
|
|
5179
|
+
currentWidth += colWidth;
|
|
5180
|
+
}
|
|
5181
|
+
}
|
|
5182
|
+
const orderedVisibleColumns = columns.filter((col) => columnsToShow.includes(col));
|
|
5183
|
+
setVisibleColumns(orderedVisibleColumns);
|
|
5184
|
+
};
|
|
5185
|
+
updateVisibleColumns();
|
|
5186
|
+
const observer = new ResizeObserver(() => {
|
|
5187
|
+
updateVisibleColumns();
|
|
5188
|
+
});
|
|
5189
|
+
observer.observe(container);
|
|
5190
|
+
return () => {
|
|
5191
|
+
observer.disconnect();
|
|
5192
|
+
};
|
|
5193
|
+
}, [columns, selectable, actions]);
|
|
5194
|
+
const effectiveSearchKeys = searchKeys || visibleColumns.map((col) => col.key);
|
|
5141
5195
|
const tableOptions = {
|
|
5142
5196
|
data,
|
|
5143
5197
|
initialSort,
|
|
5144
5198
|
pageSize,
|
|
5145
5199
|
searchQuery,
|
|
5146
|
-
searchKeys
|
|
5200
|
+
searchKeys: effectiveSearchKeys
|
|
5147
5201
|
};
|
|
5148
5202
|
const {
|
|
5149
5203
|
currentData,
|
|
@@ -5316,10 +5370,10 @@ function DataTable({
|
|
|
5316
5370
|
description: `No items match "${searchQuery}". Try adjusting your search.`
|
|
5317
5371
|
}
|
|
5318
5372
|
) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5319
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `${stickyHeader ? "overflow-auto max-h-150" : ""} overflow-x-auto`, children: /* @__PURE__ */ jsxRuntime.jsxs(Table, { striped, bordered, hoverable, compact, children: [
|
|
5373
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { ref: tableContainerRef, className: `${stickyHeader ? "overflow-auto max-h-150" : ""} overflow-x-auto`, children: /* @__PURE__ */ jsxRuntime.jsxs(Table, { striped, bordered, hoverable, compact, children: [
|
|
5320
5374
|
/* @__PURE__ */ jsxRuntime.jsx(TableHeader, { className: stickyHeader ? "sticky top-0 z-10 bg-background shadow-sm" : "", children: /* @__PURE__ */ jsxRuntime.jsxs(TableRow, { children: [
|
|
5321
5375
|
selectable && /* @__PURE__ */ jsxRuntime.jsx(TableHeadCell, { className: "w-12", children: /* @__PURE__ */ jsxRuntime.jsx(checkbox_default, { checked: isAllSelected, onChange: handleToggleAll, ariaLabel: "Select all rows" }) }),
|
|
5322
|
-
|
|
5376
|
+
visibleColumns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
5323
5377
|
TableHeadCell,
|
|
5324
5378
|
{
|
|
5325
5379
|
align: column.align,
|
|
@@ -5359,7 +5413,7 @@ function DataTable({
|
|
|
5359
5413
|
ariaLabel: `Select row ${actualIndex + 1}`
|
|
5360
5414
|
}
|
|
5361
5415
|
) }),
|
|
5362
|
-
|
|
5416
|
+
visibleColumns.map((column) => {
|
|
5363
5417
|
const value = row[column.key];
|
|
5364
5418
|
const content = renderCellContent(value, column, row, actualIndex);
|
|
5365
5419
|
return /* @__PURE__ */ jsxRuntime.jsx(TableCell, { align: column.align, wrapText: column.wrapText, children: content }, String(column.key));
|