@bmsuisse/datagrid 0.24.1 → 0.25.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 +32 -3
- package/dist/index.js +34 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -793,6 +793,8 @@ interface DataGridProps<TRow> {
|
|
|
793
793
|
*/
|
|
794
794
|
expandedGroups?: Record<string, boolean>;
|
|
795
795
|
onExpandedGroupsChange?: (expanded: Record<string, boolean>) => void;
|
|
796
|
+
/** Alternates body row backgrounds for readability on wide/dense tables. Defaults to true. */
|
|
797
|
+
zebra?: boolean;
|
|
796
798
|
}
|
|
797
799
|
|
|
798
800
|
/**
|
|
@@ -803,7 +805,7 @@ interface DataGridProps<TRow> {
|
|
|
803
805
|
* (`"server"`). Column filter UI defaults to the type-appropriate widget
|
|
804
806
|
* from `src/filter` unless a column supplies its own `cell` renderer.
|
|
805
807
|
*/
|
|
806
|
-
declare function DataGrid<TRow extends RowData>({ columns, dataSource, getRowId, rowActions, headerActions, enableMultiSort, initialState, columnVisibility, renderDetail, enableColumnResizing, columnResizeMode, columnSizing: controlledColumnSizing, onColumnSizingChange, virtualize, showPagination, getRowProps, getRowTestId, gridState, selectedIds: controlledSelectedIds, onSelectedIdsChange, testId, loading: loadingProp, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, }: DataGridProps<TRow>): ReactElement;
|
|
808
|
+
declare function DataGrid<TRow extends RowData>({ columns, dataSource, getRowId, rowActions, headerActions, enableMultiSort, initialState, columnVisibility, renderDetail, enableColumnResizing, columnResizeMode, columnSizing: controlledColumnSizing, onColumnSizingChange, virtualize, showPagination, getRowProps, getRowTestId, gridState, selectedIds: controlledSelectedIds, onSelectedIdsChange, testId, loading: loadingProp, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, zebra, }: DataGridProps<TRow>): ReactElement;
|
|
807
809
|
|
|
808
810
|
interface GridStateController {
|
|
809
811
|
state: GridState;
|
|
@@ -933,6 +935,29 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
|
|
|
933
935
|
/** Controlled expanded state, keyed by node id. Omit for the grid to own this itself. */
|
|
934
936
|
expanded?: Record<string, boolean>;
|
|
935
937
|
onExpandedChange?: (expanded: Record<string, boolean>) => void;
|
|
938
|
+
/**
|
|
939
|
+
* Controlled lazy-children cache, keyed by node id — same
|
|
940
|
+
* controlled/uncontrolled convention as `expanded` above. Omit for the
|
|
941
|
+
* grid to own this itself (the common case, and the only way earlier
|
|
942
|
+
* versions of this component worked).
|
|
943
|
+
*
|
|
944
|
+
* Supply this when a caller needs to force a specific node's cached batch
|
|
945
|
+
* to be replaced with fresher data fetched *outside* the normal
|
|
946
|
+
* expand/collapse flow above (`onLoadChildren` only ever runs once per
|
|
947
|
+
* node id per the doc on it) — e.g. after an edit made to one of that
|
|
948
|
+
* node's children was saved, and the caller re-fetched that batch via its
|
|
949
|
+
* own `onLoadChildren` function to pick up the server's new state. Setting
|
|
950
|
+
* `childrenMap` to a new map containing that node's id (typically via
|
|
951
|
+
* `onChildrenMapChange`'s own setter, called by the caller's re-fetch
|
|
952
|
+
* logic) makes this component's flattened rows use the fresh batch on the
|
|
953
|
+
* very next render — without this, a caller's own separate copy of that
|
|
954
|
+
* data has nowhere to feed back into what actually gets rendered, no
|
|
955
|
+
* matter how it's refreshed, since only this component's internal cache
|
|
956
|
+
* (or an eager `getChildren(row)`) is ever consulted for a lazily-loaded
|
|
957
|
+
* node's children.
|
|
958
|
+
*/
|
|
959
|
+
childrenMap?: ReadonlyMap<string, TRow[]>;
|
|
960
|
+
onChildrenMapChange?: (childrenMap: ReadonlyMap<string, TRow[]>) => void;
|
|
936
961
|
/** Pixels of left padding added per depth level to the tree column's cell. Defaults to 20. */
|
|
937
962
|
indentSize?: number;
|
|
938
963
|
/**
|
|
@@ -1027,6 +1052,8 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
|
|
|
1027
1052
|
} | undefined;
|
|
1028
1053
|
/** Disables just the checkbox for a specific row. Defaults to `() => false`. */
|
|
1029
1054
|
isRowSelectionDisabled?: (row: TRow) => boolean;
|
|
1055
|
+
/** Alternates body row backgrounds for readability on wide/dense tables. Defaults to true. */
|
|
1056
|
+
zebra?: boolean;
|
|
1030
1057
|
}
|
|
1031
1058
|
|
|
1032
1059
|
/**
|
|
@@ -1043,7 +1070,7 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
|
|
|
1043
1070
|
* column's cell matches `treeColumnId` (defaults to `columns[0]`); every
|
|
1044
1071
|
* other column renders exactly like it would in `<DataGrid>`.
|
|
1045
1072
|
*/
|
|
1046
|
-
declare function TreeDataGrid<TRow>({ columns, data, treeColumnId, getRowId, getChildren, hasChildren, onLoadChildren, initialExpandedLevel, expanded: controlledExpanded, onExpandedChange, indentSize, getRowProps, getRowTestId, rowActions, virtualizeThreshold, estimatedRowHeight, maxBodyHeight, selectedIds: controlledSelectedIds, onSelectedIdsChange, getRowSelectionState, isRowSelectionDisabled, }: TreeDataGridProps<TRow>): ReactElement;
|
|
1073
|
+
declare function TreeDataGrid<TRow>({ columns, data, treeColumnId, getRowId, getChildren, hasChildren, onLoadChildren, initialExpandedLevel, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, indentSize, getRowProps, getRowTestId, rowActions, virtualizeThreshold, estimatedRowHeight, maxBodyHeight, selectedIds: controlledSelectedIds, onSelectedIdsChange, getRowSelectionState, isRowSelectionDisabled, zebra, }: TreeDataGridProps<TRow>): ReactElement;
|
|
1047
1074
|
|
|
1048
1075
|
interface FlatTreeRow<TRow> {
|
|
1049
1076
|
row: TRow;
|
|
@@ -1081,6 +1108,8 @@ interface UseTreeStateOptions<TRow> extends TreeAccessors<TRow> {
|
|
|
1081
1108
|
onLoadChildren?: (row: TRow) => Promise<TRow[]>;
|
|
1082
1109
|
expanded?: Record<string, boolean>;
|
|
1083
1110
|
onExpandedChange?: (expanded: Record<string, boolean>) => void;
|
|
1111
|
+
childrenMap?: ReadonlyMap<string, TRow[]>;
|
|
1112
|
+
onChildrenMapChange?: (childrenMap: ReadonlyMap<string, TRow[]>) => void;
|
|
1084
1113
|
}
|
|
1085
1114
|
/**
|
|
1086
1115
|
* Owns everything `<TreeDataGrid>` needs beyond plain rendering: expand
|
|
@@ -1095,6 +1124,6 @@ interface UseTreeStateOptions<TRow> extends TreeAccessors<TRow> {
|
|
|
1095
1124
|
* reset (e.g. switching to a different root entity entirely) should remount
|
|
1096
1125
|
* `<TreeDataGrid>` via a `key` prop rather than rely on implicit magic here.
|
|
1097
1126
|
*/
|
|
1098
|
-
declare function useTreeState<TRow>({ data, getRowId, getChildren, hasChildren, onLoadChildren, expanded: controlledExpanded, onExpandedChange, }: UseTreeStateOptions<TRow>): TreeStateController<TRow>;
|
|
1127
|
+
declare function useTreeState<TRow>({ data, getRowId, getChildren, hasChildren, onLoadChildren, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, }: UseTreeStateOptions<TRow>): TreeStateController<TRow>;
|
|
1099
1128
|
|
|
1100
1129
|
export { ActionsMenu, type BaseColumn, type BooleanColumn, BooleanFilter, type ClientProcessingResult, type ColumnAlign, type ColumnDef, type ColumnGroup, ColumnSelector, type ColumnSelectorProps, type ColumnVisibility, type CompositeFilterDescriptor, DataGrid, type DataGridProps, type DataSource, type DateColumn, DateRangeFilter, type DebouncedCallback, type EnumColumn, EnumFilter, type EnumOption, type FilterDescriptor, type FilterOperator, type FilterWidgetProps, type FlatTreeRow, type GridState, type GridStateController, type MenuItem, type MenuItemContext, type NumberColumn, NumberComparisonFilter, NumberHistogramFilter, type NumberHistogramFilterProps, NumberRangeFilter, type ResolvedMenuItem, type SortDescriptor, type StringColumn, StringFilter, type TreeAccessors, TreeDataGrid, type TreeDataGridProps, type TreeStateController, UNARY_OPERATORS, type UseTreeStateOptions, alignClassName, canHideColumn, canHideGroup, countVisible, defaultAlign, defaultFormat, evaluateFilter, facetedNumberValues, fieldKey, flattenTree, getColumnValue, groupColumns, isColumnVisible, isCompositeFilterDescriptor, isFilterDescriptor, isFilterable, isSortable, processClientData, renderDefaultFilterWidget, resolveMenuItems, storageKeyFor, useDebouncedCallback, useGridState, useTreeState };
|
package/dist/index.js
CHANGED
|
@@ -1869,7 +1869,8 @@ function DataGrid({
|
|
|
1869
1869
|
renderGroupHeader,
|
|
1870
1870
|
defaultGroupsExpanded = true,
|
|
1871
1871
|
expandedGroups: controlledExpandedGroups,
|
|
1872
|
-
onExpandedGroupsChange
|
|
1872
|
+
onExpandedGroupsChange,
|
|
1873
|
+
zebra = true
|
|
1873
1874
|
}) {
|
|
1874
1875
|
const { state, filtersByColumn, setColumnFilter, toggleSort, setPage } = useGridState(
|
|
1875
1876
|
dataSource,
|
|
@@ -2081,18 +2082,19 @@ function DataGrid({
|
|
|
2081
2082
|
const isExpanded = expandedIds.has(row.id);
|
|
2082
2083
|
const rowProps = getRowProps?.(row.original);
|
|
2083
2084
|
const rowTestId = getRowTestId?.(row.original) ?? `row-${row.id}`;
|
|
2085
|
+
const isOddRow = zebra && row.index % 2 === 1;
|
|
2084
2086
|
return /* @__PURE__ */ jsxs12("tbody", { ref: measureRef, "data-index": row.index, children: [
|
|
2085
2087
|
/* @__PURE__ */ jsxs12(
|
|
2086
2088
|
"tr",
|
|
2087
2089
|
{
|
|
2088
2090
|
...rowProps,
|
|
2089
2091
|
"data-testid": rowTestId,
|
|
2090
|
-
className: rowProps?.className ? cn("divide-x divide-border", rowProps.className,
|
|
2092
|
+
className: rowProps?.className ? cn("divide-x divide-border", rowProps.className, isOddRow && "bg-foreground/5") : `divide-x divide-border${isOddRow ? " bg-foreground/5" : ""}`,
|
|
2091
2093
|
children: [
|
|
2092
2094
|
showDetailColumn && /* @__PURE__ */ jsx19(
|
|
2093
2095
|
"td",
|
|
2094
2096
|
{
|
|
2095
|
-
className:
|
|
2097
|
+
className: isOddRow ? detailCellProps.classNameOdd : detailCellProps.className,
|
|
2096
2098
|
style: detailCellProps.style,
|
|
2097
2099
|
children: /* @__PURE__ */ jsx19(
|
|
2098
2100
|
Button,
|
|
@@ -2120,7 +2122,7 @@ function DataGrid({
|
|
|
2120
2122
|
showSelectionColumn && /* @__PURE__ */ jsx19(
|
|
2121
2123
|
"td",
|
|
2122
2124
|
{
|
|
2123
|
-
className:
|
|
2125
|
+
className: isOddRow ? selectionCellProps.classNameOdd : selectionCellProps.className,
|
|
2124
2126
|
style: selectionCellProps.style,
|
|
2125
2127
|
children: /* @__PURE__ */ jsx19(
|
|
2126
2128
|
"input",
|
|
@@ -2141,7 +2143,7 @@ function DataGrid({
|
|
|
2141
2143
|
showRowActionsColumn && rowActions && /* @__PURE__ */ jsx19(
|
|
2142
2144
|
"td",
|
|
2143
2145
|
{
|
|
2144
|
-
className:
|
|
2146
|
+
className: isOddRow ? rowActionsCellProps.classNameOdd : rowActionsCellProps.className,
|
|
2145
2147
|
style: rowActionsCellProps.style,
|
|
2146
2148
|
children: /* @__PURE__ */ jsx19(ActionsMenu, { items: rowActions, ctx: { row: row.original }, triggerLabel: `Row actions for ${row.id}` })
|
|
2147
2149
|
}
|
|
@@ -2478,7 +2480,9 @@ function useTreeState({
|
|
|
2478
2480
|
hasChildren,
|
|
2479
2481
|
onLoadChildren,
|
|
2480
2482
|
expanded: controlledExpanded,
|
|
2481
|
-
onExpandedChange
|
|
2483
|
+
onExpandedChange,
|
|
2484
|
+
childrenMap: controlledChildrenMap,
|
|
2485
|
+
onChildrenMapChange
|
|
2482
2486
|
}) {
|
|
2483
2487
|
const [internalExpanded, setInternalExpanded] = useState7({});
|
|
2484
2488
|
const expanded = controlledExpanded ?? internalExpanded;
|
|
@@ -2492,7 +2496,18 @@ function useTreeState({
|
|
|
2492
2496
|
},
|
|
2493
2497
|
[controlledExpanded, onExpandedChange]
|
|
2494
2498
|
);
|
|
2495
|
-
const [
|
|
2499
|
+
const [internalChildrenMap, setInternalChildrenMap] = useState7(/* @__PURE__ */ new Map());
|
|
2500
|
+
const childrenMap = controlledChildrenMap ?? internalChildrenMap;
|
|
2501
|
+
const setChildrenMap = useCallback3(
|
|
2502
|
+
(updater) => {
|
|
2503
|
+
if (controlledChildrenMap) {
|
|
2504
|
+
onChildrenMapChange?.(updater(controlledChildrenMap));
|
|
2505
|
+
} else {
|
|
2506
|
+
setInternalChildrenMap((prev) => new Map(updater(prev)));
|
|
2507
|
+
}
|
|
2508
|
+
},
|
|
2509
|
+
[controlledChildrenMap, onChildrenMapChange]
|
|
2510
|
+
);
|
|
2496
2511
|
const [loadingIds, setLoadingIds] = useState7(/* @__PURE__ */ new Set());
|
|
2497
2512
|
const [errorIds, setErrorIds] = useState7(/* @__PURE__ */ new Map());
|
|
2498
2513
|
const resolveHasChildren = useMemo7(
|
|
@@ -2530,7 +2545,7 @@ function useTreeState({
|
|
|
2530
2545
|
});
|
|
2531
2546
|
}
|
|
2532
2547
|
},
|
|
2533
|
-
[childrenMap, getChildren, getRowId, onLoadChildren]
|
|
2548
|
+
[childrenMap, getChildren, getRowId, onLoadChildren, setChildrenMap]
|
|
2534
2549
|
);
|
|
2535
2550
|
const toggleExpand = useCallback3(
|
|
2536
2551
|
(row) => {
|
|
@@ -2625,6 +2640,8 @@ function TreeDataGrid({
|
|
|
2625
2640
|
initialExpandedLevel = 0,
|
|
2626
2641
|
expanded: controlledExpanded,
|
|
2627
2642
|
onExpandedChange,
|
|
2643
|
+
childrenMap: controlledChildrenMap,
|
|
2644
|
+
onChildrenMapChange,
|
|
2628
2645
|
indentSize = 20,
|
|
2629
2646
|
getRowProps,
|
|
2630
2647
|
getRowTestId,
|
|
@@ -2635,7 +2652,8 @@ function TreeDataGrid({
|
|
|
2635
2652
|
selectedIds: controlledSelectedIds,
|
|
2636
2653
|
onSelectedIdsChange,
|
|
2637
2654
|
getRowSelectionState,
|
|
2638
|
-
isRowSelectionDisabled
|
|
2655
|
+
isRowSelectionDisabled,
|
|
2656
|
+
zebra = true
|
|
2639
2657
|
}) {
|
|
2640
2658
|
const accessors = useMemo8(
|
|
2641
2659
|
() => ({ getRowId, getChildren, hasChildren }),
|
|
@@ -2648,7 +2666,9 @@ function TreeDataGrid({
|
|
|
2648
2666
|
hasChildren,
|
|
2649
2667
|
onLoadChildren,
|
|
2650
2668
|
expanded: controlledExpanded,
|
|
2651
|
-
onExpandedChange
|
|
2669
|
+
onExpandedChange,
|
|
2670
|
+
childrenMap: controlledChildrenMap,
|
|
2671
|
+
onChildrenMapChange
|
|
2652
2672
|
});
|
|
2653
2673
|
const didAutoExpand = useRef6(false);
|
|
2654
2674
|
useEffect8(() => {
|
|
@@ -2711,17 +2731,19 @@ function TreeDataGrid({
|
|
|
2711
2731
|
function renderRow(flatRow, index, measureRef) {
|
|
2712
2732
|
const rowProps = getRowProps?.(flatRow.row, flatRow.depth, index);
|
|
2713
2733
|
const rowTestId = getRowTestId?.(flatRow.row) ?? `tree-row-${flatRow.id}`;
|
|
2734
|
+
const isOddRow = zebra && index % 2 === 1;
|
|
2714
2735
|
return /* @__PURE__ */ jsxs13(
|
|
2715
2736
|
"tr",
|
|
2716
2737
|
{
|
|
2717
2738
|
ref: measureRef,
|
|
2718
2739
|
...rowProps,
|
|
2740
|
+
"data-index": index,
|
|
2719
2741
|
"data-testid": rowTestId,
|
|
2720
2742
|
className: rowProps?.className ? cn(
|
|
2721
2743
|
"border-b border-border divide-x divide-border",
|
|
2722
2744
|
rowProps.className,
|
|
2723
|
-
|
|
2724
|
-
) : `border-b border-border divide-x divide-border${
|
|
2745
|
+
isOddRow && "bg-foreground/5"
|
|
2746
|
+
) : `border-b border-border divide-x divide-border${isOddRow ? " bg-foreground/5" : ""}`,
|
|
2725
2747
|
children: [
|
|
2726
2748
|
showSelectionColumn && /* @__PURE__ */ jsx20("td", { className: "p-1", style: { width: SELECTION_COLUMN_WIDTH }, children: (() => {
|
|
2727
2749
|
const state = resolveSelectionState(flatRow.row, flatRow.id);
|