@bmsuisse/datagrid 0.31.2 → 0.32.1
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.d.ts +11 -1
- package/dist/index.js +102 -52
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1848,6 +1848,16 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
|
|
|
1848
1848
|
estimatedRowHeight?: number;
|
|
1849
1849
|
/** Max height of the scrollable table body in pixels. Required for virtualization to have a viewport to scroll within. Defaults to 480. */
|
|
1850
1850
|
maxBodyHeight?: number;
|
|
1851
|
+
/**
|
|
1852
|
+
* `data-testid` for the tree's own scrollable container — the element
|
|
1853
|
+
* `maxBodyHeight` actually applies to once virtualized. Omit for no
|
|
1854
|
+
* attribute at all. Useful for an e2e test that needs to scroll this
|
|
1855
|
+
* specific tree or assert on its scroll position; the outer
|
|
1856
|
+
* `data-testid="tree-datagrid"` wrapper isn't it, and isn't unique per
|
|
1857
|
+
* tree on a page with more than one — same convention as `<DataGrid>`'s
|
|
1858
|
+
* own `testId`.
|
|
1859
|
+
*/
|
|
1860
|
+
testId?: string;
|
|
1851
1861
|
/**
|
|
1852
1862
|
* Controlled row selection — same convention as `<DataGrid>`'s own
|
|
1853
1863
|
* `selectedIds`/`onSelectedIdsChange`. Both must be supplied together to
|
|
@@ -1949,7 +1959,7 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
|
|
|
1949
1959
|
* column's cell matches `treeColumnId` (defaults to `columns[0]`); every
|
|
1950
1960
|
* other column renders exactly like it would in `<DataGrid>`.
|
|
1951
1961
|
*/
|
|
1952
|
-
declare function TreeDataGrid<TRow>({ columns, data, treeColumnId, columnVisibility, getRowId, getChildren, hasChildren, onLoadChildren, initialExpandedLevel, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, indentSize, getRowProps, getRowTestId, rowActions, virtualizeThreshold, estimatedRowHeight, maxBodyHeight, selectedIds: controlledSelectedIds, onSelectedIdsChange, getRowSelectionState, isRowSelectionDisabled, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, zebra, editing, }: TreeDataGridProps<TRow>): ReactElement;
|
|
1962
|
+
declare function TreeDataGrid<TRow>({ columns, data, treeColumnId, columnVisibility, getRowId, getChildren, hasChildren, onLoadChildren, initialExpandedLevel, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, indentSize, getRowProps, getRowTestId, rowActions, virtualizeThreshold, estimatedRowHeight, maxBodyHeight, testId, selectedIds: controlledSelectedIds, onSelectedIdsChange, getRowSelectionState, isRowSelectionDisabled, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, zebra, editing, }: TreeDataGridProps<TRow>): ReactElement;
|
|
1953
1963
|
|
|
1954
1964
|
interface FlatTreeRow<TRow> {
|
|
1955
1965
|
row: TRow;
|
package/dist/index.js
CHANGED
|
@@ -3155,6 +3155,12 @@ function useGridState(dataSource, initialState, externalState, showPagination =
|
|
|
3155
3155
|
import { Fragment as Fragment4, jsx as jsx33, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
3156
3156
|
var gridTableFeatures = tableFeatures({ columnSizingFeature, columnResizingFeature });
|
|
3157
3157
|
var DEFAULT_COLUMN_SIZE = 150;
|
|
3158
|
+
var MIN_COLUMN_SIZE = 40;
|
|
3159
|
+
function sortDirToAriaSort(dir) {
|
|
3160
|
+
if (dir === "asc") return "ascending";
|
|
3161
|
+
if (dir === "desc") return "descending";
|
|
3162
|
+
return "none";
|
|
3163
|
+
}
|
|
3158
3164
|
var DETAIL_COLUMN_WIDTH = 44;
|
|
3159
3165
|
var ROW_ACTIONS_COLUMN_WIDTH = 44;
|
|
3160
3166
|
var EMPTY_ID_ARRAY = [];
|
|
@@ -3928,52 +3934,84 @@ function DataGrid({
|
|
|
3928
3934
|
const filterable = isFilterable(column) && column.filterDisplay !== "row";
|
|
3929
3935
|
const cellProps = leafHeaderCellPropsByColumn.get(column.id);
|
|
3930
3936
|
const headerContent = column.renderHeader ? column.renderHeader(column) : column.header;
|
|
3931
|
-
return /* @__PURE__ */ jsxs20(
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3937
|
+
return /* @__PURE__ */ jsxs20(
|
|
3938
|
+
"th",
|
|
3939
|
+
{
|
|
3940
|
+
rowSpan,
|
|
3941
|
+
style: cellProps?.style,
|
|
3942
|
+
className: cellProps?.className,
|
|
3943
|
+
"aria-sort": sortable ? sortDirToAriaSort(sortEntry?.dir) : void 0,
|
|
3944
|
+
"aria-label": column.header,
|
|
3945
|
+
children: [
|
|
3946
|
+
/* @__PURE__ */ jsxs20("div", { className: "flex items-center gap-1", children: [
|
|
3947
|
+
sortable ? /* @__PURE__ */ jsxs20(
|
|
3948
|
+
"button",
|
|
3949
|
+
{
|
|
3950
|
+
type: "button",
|
|
3951
|
+
"data-testid": `sort-button-${column.id}`,
|
|
3952
|
+
className: "flex items-center gap-1 rounded-sm px-1 hover:bg-accent hover:text-accent-foreground",
|
|
3953
|
+
onClick: (event) => toggleSort(column.id, enableMultiSort && event.shiftKey, column.sortDescFirst === true),
|
|
3954
|
+
children: [
|
|
3955
|
+
headerContent,
|
|
3956
|
+
sortEntry?.dir === "asc" && /* @__PURE__ */ jsx33(BarsArrowUpIcon, { className: "h-3 w-3", "aria-hidden": true }),
|
|
3957
|
+
sortEntry?.dir === "desc" && /* @__PURE__ */ jsx33(BarsArrowDownIcon, { className: "h-3 w-3", "aria-hidden": true })
|
|
3958
|
+
]
|
|
3959
|
+
}
|
|
3960
|
+
) : (
|
|
3961
|
+
// Not wrapped in a `<button>` (unlike the sortable branch above): a
|
|
3962
|
+
// disabled `<button>` swallows pointer events for its entire subtree,
|
|
3963
|
+
// silently breaking any interactive content a column's own `renderHeader`
|
|
3964
|
+
// embeds directly (bare filter inputs, "select/reject all" buttons) —
|
|
3965
|
+
// clicks never reach them at all, even though nothing looks wrong visually.
|
|
3966
|
+
/* @__PURE__ */ jsx33("div", { className: "flex items-center gap-1 px-1", children: headerContent })
|
|
3967
|
+
),
|
|
3968
|
+
filterable && /* @__PURE__ */ jsxs20(Popover, { children: [
|
|
3969
|
+
/* @__PURE__ */ jsx33(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx33(
|
|
3970
|
+
Button,
|
|
3971
|
+
{
|
|
3972
|
+
variant: "ghost",
|
|
3973
|
+
size: "icon",
|
|
3974
|
+
"data-testid": `filter-trigger-${column.id}`,
|
|
3975
|
+
"aria-label": `Filter ${column.header}`,
|
|
3976
|
+
children: /* @__PURE__ */ jsx33(
|
|
3977
|
+
FunnelIcon7,
|
|
3978
|
+
{
|
|
3979
|
+
className: cn(
|
|
3980
|
+
"h-3 w-3",
|
|
3981
|
+
filtersByColumn.get(column.id) !== void 0 ? "opacity-100 text-primary" : "opacity-40"
|
|
3982
|
+
),
|
|
3983
|
+
"aria-hidden": true
|
|
3984
|
+
}
|
|
3985
|
+
)
|
|
3986
|
+
}
|
|
3987
|
+
) }),
|
|
3988
|
+
/* @__PURE__ */ jsx33(PopoverContent, { children: renderFilterWidget(column) })
|
|
3989
|
+
] })
|
|
3990
|
+
] }),
|
|
3991
|
+
enableColumnResizing && /* @__PURE__ */ jsx33(
|
|
3992
|
+
"div",
|
|
3956
3993
|
{
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3994
|
+
"data-testid": `resize-handle-${column.id}`,
|
|
3995
|
+
role: "separator",
|
|
3996
|
+
"aria-orientation": "vertical",
|
|
3997
|
+
"aria-label": `Resize ${column.header} column`,
|
|
3998
|
+
tabIndex: 0,
|
|
3999
|
+
onMouseDown: header.getResizeHandler(),
|
|
4000
|
+
onTouchStart: header.getResizeHandler(),
|
|
4001
|
+
onKeyDown: (event) => {
|
|
4002
|
+
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
|
|
4003
|
+
event.preventDefault();
|
|
4004
|
+
const delta = event.key === "ArrowRight" ? 10 : -10;
|
|
4005
|
+
const nextSize = Math.max(MIN_COLUMN_SIZE, columnSize(column.id) + delta);
|
|
4006
|
+
updateColumnSizing({ ...columnSizing, [column.id]: nextSize });
|
|
4007
|
+
},
|
|
4008
|
+
className: "absolute right-0 top-0 h-full w-1 cursor-col-resize touch-none select-none hover:bg-accent focus-visible:bg-accent focus-visible:outline-none"
|
|
3962
4009
|
}
|
|
3963
|
-
)
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
"div",
|
|
3969
|
-
{
|
|
3970
|
-
"data-testid": `resize-handle-${column.id}`,
|
|
3971
|
-
onMouseDown: header.getResizeHandler(),
|
|
3972
|
-
onTouchStart: header.getResizeHandler(),
|
|
3973
|
-
className: "absolute right-0 top-0 h-full w-1 cursor-col-resize touch-none select-none hover:bg-accent"
|
|
3974
|
-
}
|
|
3975
|
-
)
|
|
3976
|
-
] }, header.id);
|
|
4010
|
+
)
|
|
4011
|
+
]
|
|
4012
|
+
},
|
|
4013
|
+
header.id
|
|
4014
|
+
);
|
|
3977
4015
|
}
|
|
3978
4016
|
return /* @__PURE__ */ jsxs20(Fragment3, { children: [
|
|
3979
4017
|
hasHeaderGroups && /* @__PURE__ */ jsxs20("tr", { "data-testid": "header-group-row", className: "divide-x divide-border", children: [
|
|
@@ -4377,6 +4415,7 @@ function TreeDataGrid({
|
|
|
4377
4415
|
virtualizeThreshold = 100,
|
|
4378
4416
|
estimatedRowHeight = 40,
|
|
4379
4417
|
maxBodyHeight = 480,
|
|
4418
|
+
testId,
|
|
4380
4419
|
selectedIds: controlledSelectedIds,
|
|
4381
4420
|
onSelectedIdsChange,
|
|
4382
4421
|
getRowSelectionState,
|
|
@@ -4565,28 +4604,39 @@ function TreeDataGrid({
|
|
|
4565
4604
|
"div",
|
|
4566
4605
|
{
|
|
4567
4606
|
ref: scrollRef,
|
|
4607
|
+
"data-testid": testId,
|
|
4568
4608
|
className: shouldVirtualize ? "overflow-y-auto" : void 0,
|
|
4569
4609
|
style: shouldVirtualize ? { maxHeight: maxBodyHeight } : void 0,
|
|
4570
4610
|
children: /* @__PURE__ */ jsxs21("table", { className: "w-full border-collapse text-sm", children: [
|
|
4571
4611
|
/* @__PURE__ */ jsx34("thead", { ref: theadRef, children: /* @__PURE__ */ jsxs21("tr", { className: "divide-x divide-border", children: [
|
|
4572
|
-
showSelectionColumn && /* @__PURE__ */ jsx34(
|
|
4573
|
-
|
|
4612
|
+
showSelectionColumn && /* @__PURE__ */ jsx34(
|
|
4613
|
+
"th",
|
|
4574
4614
|
{
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4615
|
+
className: "sticky top-0 z-20 border-b border-border bg-muted p-1",
|
|
4616
|
+
style: { width: SELECTION_COLUMN_WIDTH },
|
|
4617
|
+
children: /* @__PURE__ */ jsx34(
|
|
4618
|
+
Checkbox,
|
|
4619
|
+
{
|
|
4620
|
+
"aria-label": "Select all visible rows",
|
|
4621
|
+
checked: allVisibleSelected,
|
|
4622
|
+
onCheckedChange: toggleAllVisibleSelected
|
|
4623
|
+
}
|
|
4624
|
+
)
|
|
4578
4625
|
}
|
|
4579
|
-
)
|
|
4626
|
+
),
|
|
4580
4627
|
visibleColumns.map((column) => /* @__PURE__ */ jsx34(
|
|
4581
4628
|
"th",
|
|
4582
4629
|
{
|
|
4583
4630
|
style: column.width ? { width: column.width } : void 0,
|
|
4584
|
-
className:
|
|
4631
|
+
className: cn(
|
|
4632
|
+
"sticky top-0 z-20 border-b border-border bg-muted p-2 font-medium",
|
|
4633
|
+
alignClassName(column)
|
|
4634
|
+
),
|
|
4585
4635
|
children: column.header
|
|
4586
4636
|
},
|
|
4587
4637
|
column.id
|
|
4588
4638
|
)),
|
|
4589
|
-
showRowActionsColumn && /* @__PURE__ */ jsx34("th", { className: "border-b border-border p-2", "aria-label": "Row actions" })
|
|
4639
|
+
showRowActionsColumn && /* @__PURE__ */ jsx34("th", { className: "sticky top-0 z-20 border-b border-border bg-muted p-2", "aria-label": "Row actions" })
|
|
4590
4640
|
] }) }),
|
|
4591
4641
|
/* @__PURE__ */ jsx34("tbody", { children: data.length === 0 ? /* @__PURE__ */ jsx34("tr", { children: /* @__PURE__ */ jsx34("td", { colSpan: totalColumnCount, className: "p-4 text-center text-muted-foreground", children: "No results." }) }) : groupedBuckets ? groupedBuckets.map((bucket) => {
|
|
4592
4642
|
const groupExpanded = isGroupExpanded(bucket.key);
|