@bmsuisse/datagrid 0.25.2 → 0.25.3
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.js +42 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1632,7 +1632,7 @@ import { BarsArrowDownIcon, BarsArrowUpIcon, FunnelIcon as FunnelIcon7 } from "@
|
|
|
1632
1632
|
import { columnResizingFeature, columnSizingFeature, flexRender, tableFeatures, useTable } from "@tanstack/react-table";
|
|
1633
1633
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
1634
1634
|
import { ChevronRight, Loader2 } from "lucide-react";
|
|
1635
|
-
import { Fragment as Fragment2, useEffect as useEffect7, useMemo as useMemo6, useRef as useRef5, useState as useState6 } from "react";
|
|
1635
|
+
import { Fragment as Fragment2, useEffect as useEffect7, useLayoutEffect, useMemo as useMemo6, useRef as useRef5, useState as useState6 } from "react";
|
|
1636
1636
|
|
|
1637
1637
|
// src/lib/structuralColumns.ts
|
|
1638
1638
|
var SELECTION_COLUMN_WIDTH = 44;
|
|
@@ -2065,6 +2065,18 @@ function DataGrid({
|
|
|
2065
2065
|
() => groupBy ? groupRows(tableRows, (row) => groupBy(row.original)) : void 0,
|
|
2066
2066
|
[tableRows, groupBy]
|
|
2067
2067
|
);
|
|
2068
|
+
const theadRef = useRef5(null);
|
|
2069
|
+
const [groupHeaderTop, setGroupHeaderTop] = useState6(0);
|
|
2070
|
+
useLayoutEffect(() => {
|
|
2071
|
+
if (!groupBy) return;
|
|
2072
|
+
const theadEl = theadRef.current;
|
|
2073
|
+
if (!theadEl) return;
|
|
2074
|
+
const updateHeight = () => setGroupHeaderTop(theadEl.getBoundingClientRect().height);
|
|
2075
|
+
updateHeight();
|
|
2076
|
+
const observer = new ResizeObserver(updateHeight);
|
|
2077
|
+
observer.observe(theadEl);
|
|
2078
|
+
return () => observer.disconnect();
|
|
2079
|
+
}, [groupBy]);
|
|
2068
2080
|
const scrollRef = useRef5(null);
|
|
2069
2081
|
const virtualizer = useVirtualizer({
|
|
2070
2082
|
count: tableRows.length,
|
|
@@ -2166,25 +2178,36 @@ function DataGrid({
|
|
|
2166
2178
|
const expanded = isGroupExpanded(bucket.key);
|
|
2167
2179
|
const originalRows = bucket.items.map((row) => row.original);
|
|
2168
2180
|
return /* @__PURE__ */ jsxs12(Fragment2, { children: [
|
|
2169
|
-
/* @__PURE__ */ jsx19("tbody", { children: /* @__PURE__ */ jsx19("tr", { "data-testid": `group-header-${bucket.key}`, children: /* @__PURE__ */ jsx19(
|
|
2170
|
-
"
|
|
2181
|
+
/* @__PURE__ */ jsx19("tbody", { children: /* @__PURE__ */ jsx19("tr", { "data-testid": `group-header-${bucket.key}`, children: /* @__PURE__ */ jsx19(
|
|
2182
|
+
"td",
|
|
2171
2183
|
{
|
|
2172
|
-
|
|
2173
|
-
className:
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2184
|
+
colSpan: totalColumnCount,
|
|
2185
|
+
className: cn(
|
|
2186
|
+
"sticky z-20 border-b p-2 font-medium",
|
|
2187
|
+
zebra ? "bg-muted" : "bg-background"
|
|
2188
|
+
),
|
|
2189
|
+
style: { top: groupHeaderTop },
|
|
2190
|
+
children: /* @__PURE__ */ jsxs12(
|
|
2191
|
+
"button",
|
|
2192
|
+
{
|
|
2193
|
+
type: "button",
|
|
2194
|
+
className: "flex w-full items-center gap-1 text-left",
|
|
2195
|
+
onClick: () => toggleGroupExpanded(bucket.key),
|
|
2196
|
+
"aria-expanded": expanded,
|
|
2197
|
+
children: [
|
|
2198
|
+
/* @__PURE__ */ jsx19(
|
|
2199
|
+
ChevronRight,
|
|
2200
|
+
{
|
|
2201
|
+
className: `h-4 w-4 shrink-0 transition-transform${expanded ? " rotate-90" : ""}`,
|
|
2202
|
+
"aria-hidden": true
|
|
2203
|
+
}
|
|
2204
|
+
),
|
|
2205
|
+
renderGroupHeader ? renderGroupHeader(bucket.key, originalRows, expanded) : `${bucket.key} (${originalRows.length})`
|
|
2206
|
+
]
|
|
2207
|
+
}
|
|
2208
|
+
)
|
|
2186
2209
|
}
|
|
2187
|
-
) }) })
|
|
2210
|
+
) }) }),
|
|
2188
2211
|
expanded && bucket.items.map((row) => renderRow(row))
|
|
2189
2212
|
] }, `group-${bucket.key}`);
|
|
2190
2213
|
}
|
|
@@ -2226,7 +2249,7 @@ function DataGrid({
|
|
|
2226
2249
|
className: "h-full overflow-auto rounded-md border",
|
|
2227
2250
|
style: shouldVirtualize ? { maxHeight: virtualize?.maxBodyHeight ?? 480 } : void 0,
|
|
2228
2251
|
children: /* @__PURE__ */ jsxs12("table", { className: cn("w-full border-collapse text-sm", enableColumnResizing && "table-fixed"), children: [
|
|
2229
|
-
/* @__PURE__ */ jsxs12("thead", { className: "bg-muted", children: [
|
|
2252
|
+
/* @__PURE__ */ jsxs12("thead", { ref: theadRef, className: "bg-muted", children: [
|
|
2230
2253
|
table.getHeaderGroups().map((headerGroup) => {
|
|
2231
2254
|
const headerById = new Map(headerGroup.headers.map((header) => [header.id, header]));
|
|
2232
2255
|
function renderLeafHeaderCell(column, rowSpan) {
|