@bmsuisse/datagrid 0.24.1 → 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 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, row.index % 2 === 1 && "bg-foreground/5") : `divide-x divide-border${row.index % 2 === 1 ? " bg-foreground/5" : ""}`,
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: row.index % 2 === 1 ? detailCellProps.classNameOdd : detailCellProps.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: row.index % 2 === 1 ? selectionCellProps.classNameOdd : selectionCellProps.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: row.index % 2 === 1 ? rowActionsCellProps.classNameOdd : rowActionsCellProps.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
  }
@@ -2635,7 +2637,8 @@ function TreeDataGrid({
2635
2637
  selectedIds: controlledSelectedIds,
2636
2638
  onSelectedIdsChange,
2637
2639
  getRowSelectionState,
2638
- isRowSelectionDisabled
2640
+ isRowSelectionDisabled,
2641
+ zebra = true
2639
2642
  }) {
2640
2643
  const accessors = useMemo8(
2641
2644
  () => ({ getRowId, getChildren, hasChildren }),
@@ -2711,6 +2714,7 @@ function TreeDataGrid({
2711
2714
  function renderRow(flatRow, index, measureRef) {
2712
2715
  const rowProps = getRowProps?.(flatRow.row, flatRow.depth, index);
2713
2716
  const rowTestId = getRowTestId?.(flatRow.row) ?? `tree-row-${flatRow.id}`;
2717
+ const isOddRow = zebra && index % 2 === 1;
2714
2718
  return /* @__PURE__ */ jsxs13(
2715
2719
  "tr",
2716
2720
  {
@@ -2720,8 +2724,8 @@ function TreeDataGrid({
2720
2724
  className: rowProps?.className ? cn(
2721
2725
  "border-b border-border divide-x divide-border",
2722
2726
  rowProps.className,
2723
- index % 2 === 1 && "bg-foreground/5"
2724
- ) : `border-b border-border divide-x divide-border${index % 2 === 1 ? " bg-foreground/5" : ""}`,
2727
+ isOddRow && "bg-foreground/5"
2728
+ ) : `border-b border-border divide-x divide-border${isOddRow ? " bg-foreground/5" : ""}`,
2725
2729
  children: [
2726
2730
  showSelectionColumn && /* @__PURE__ */ jsx20("td", { className: "p-1", style: { width: SELECTION_COLUMN_WIDTH }, children: (() => {
2727
2731
  const state = resolveSelectionState(flatRow.row, flatRow.id);