@bmsuisse/datagrid 0.24.0 → 0.25.0
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 +6 -2
- package/dist/index.js +26 -18
- 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;
|
|
@@ -1027,6 +1029,8 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
|
|
|
1027
1029
|
} | undefined;
|
|
1028
1030
|
/** Disables just the checkbox for a specific row. Defaults to `() => false`. */
|
|
1029
1031
|
isRowSelectionDisabled?: (row: TRow) => boolean;
|
|
1032
|
+
/** Alternates body row backgrounds for readability on wide/dense tables. Defaults to true. */
|
|
1033
|
+
zebra?: boolean;
|
|
1030
1034
|
}
|
|
1031
1035
|
|
|
1032
1036
|
/**
|
|
@@ -1043,7 +1047,7 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
|
|
|
1043
1047
|
* column's cell matches `treeColumnId` (defaults to `columns[0]`); every
|
|
1044
1048
|
* other column renders exactly like it would in `<DataGrid>`.
|
|
1045
1049
|
*/
|
|
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;
|
|
1050
|
+
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, zebra, }: TreeDataGridProps<TRow>): ReactElement;
|
|
1047
1051
|
|
|
1048
1052
|
interface FlatTreeRow<TRow> {
|
|
1049
1053
|
row: TRow;
|
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
|
}
|
|
@@ -2213,24 +2215,28 @@ function DataGrid({
|
|
|
2213
2215
|
const sortable = isSortable(column);
|
|
2214
2216
|
const filterable = isFilterable(column) && column.filterDisplay !== "row";
|
|
2215
2217
|
const cellProps = leafHeaderCellPropsByColumn.get(column.id);
|
|
2218
|
+
const headerContent = column.renderHeader ? column.renderHeader(column) : column.header;
|
|
2216
2219
|
return /* @__PURE__ */ jsxs12("th", { rowSpan, style: cellProps?.style, className: cellProps?.className, children: [
|
|
2217
2220
|
/* @__PURE__ */ jsxs12("div", { className: "flex items-center gap-1", children: [
|
|
2218
|
-
/* @__PURE__ */ jsxs12(
|
|
2221
|
+
sortable ? /* @__PURE__ */ jsxs12(
|
|
2219
2222
|
"button",
|
|
2220
2223
|
{
|
|
2221
2224
|
type: "button",
|
|
2222
|
-
className:
|
|
2223
|
-
|
|
2224
|
-
sortable && "hover:bg-accent hover:text-accent-foreground"
|
|
2225
|
-
),
|
|
2226
|
-
disabled: !sortable,
|
|
2227
|
-
onClick: (event) => sortable && toggleSort(column.id, enableMultiSort && event.shiftKey, column.sortDescFirst === true),
|
|
2225
|
+
className: "flex items-center gap-1 rounded-sm px-1 hover:bg-accent hover:text-accent-foreground",
|
|
2226
|
+
onClick: (event) => toggleSort(column.id, enableMultiSort && event.shiftKey, column.sortDescFirst === true),
|
|
2228
2227
|
children: [
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2228
|
+
headerContent,
|
|
2229
|
+
sortEntry?.dir === "asc" && /* @__PURE__ */ jsx19(BarsArrowUpIcon, { className: "h-3 w-3", "aria-hidden": true }),
|
|
2230
|
+
sortEntry?.dir === "desc" && /* @__PURE__ */ jsx19(BarsArrowDownIcon, { className: "h-3 w-3", "aria-hidden": true })
|
|
2232
2231
|
]
|
|
2233
2232
|
}
|
|
2233
|
+
) : (
|
|
2234
|
+
// Not wrapped in a `<button>` (unlike the sortable branch above): a
|
|
2235
|
+
// disabled `<button>` swallows pointer events for its entire subtree,
|
|
2236
|
+
// silently breaking any interactive content a column's own `renderHeader`
|
|
2237
|
+
// embeds directly (bare filter inputs, "select/reject all" buttons) —
|
|
2238
|
+
// clicks never reach them at all, even though nothing looks wrong visually.
|
|
2239
|
+
/* @__PURE__ */ jsx19("div", { className: "flex items-center gap-1 px-1", children: headerContent })
|
|
2234
2240
|
),
|
|
2235
2241
|
filterable && /* @__PURE__ */ jsxs12(Popover, { children: [
|
|
2236
2242
|
/* @__PURE__ */ jsx19(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx19(Button, { variant: "ghost", size: "icon", "aria-label": `Filter ${column.header}`, children: /* @__PURE__ */ jsx19(
|
|
@@ -2631,7 +2637,8 @@ function TreeDataGrid({
|
|
|
2631
2637
|
selectedIds: controlledSelectedIds,
|
|
2632
2638
|
onSelectedIdsChange,
|
|
2633
2639
|
getRowSelectionState,
|
|
2634
|
-
isRowSelectionDisabled
|
|
2640
|
+
isRowSelectionDisabled,
|
|
2641
|
+
zebra = true
|
|
2635
2642
|
}) {
|
|
2636
2643
|
const accessors = useMemo8(
|
|
2637
2644
|
() => ({ getRowId, getChildren, hasChildren }),
|
|
@@ -2707,6 +2714,7 @@ function TreeDataGrid({
|
|
|
2707
2714
|
function renderRow(flatRow, index, measureRef) {
|
|
2708
2715
|
const rowProps = getRowProps?.(flatRow.row, flatRow.depth, index);
|
|
2709
2716
|
const rowTestId = getRowTestId?.(flatRow.row) ?? `tree-row-${flatRow.id}`;
|
|
2717
|
+
const isOddRow = zebra && index % 2 === 1;
|
|
2710
2718
|
return /* @__PURE__ */ jsxs13(
|
|
2711
2719
|
"tr",
|
|
2712
2720
|
{
|
|
@@ -2716,8 +2724,8 @@ function TreeDataGrid({
|
|
|
2716
2724
|
className: rowProps?.className ? cn(
|
|
2717
2725
|
"border-b border-border divide-x divide-border",
|
|
2718
2726
|
rowProps.className,
|
|
2719
|
-
|
|
2720
|
-
) : `border-b border-border divide-x divide-border${
|
|
2727
|
+
isOddRow && "bg-foreground/5"
|
|
2728
|
+
) : `border-b border-border divide-x divide-border${isOddRow ? " bg-foreground/5" : ""}`,
|
|
2721
2729
|
children: [
|
|
2722
2730
|
showSelectionColumn && /* @__PURE__ */ jsx20("td", { className: "p-1", style: { width: SELECTION_COLUMN_WIDTH }, children: (() => {
|
|
2723
2731
|
const state = resolveSelectionState(flatRow.row, flatRow.id);
|