material-react-table 0.33.1 → 0.33.4

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
@@ -443,12 +443,12 @@ declare type MRT_DisplayColumnIds = 'mrt-row-drag' | 'mrt-row-actions' | 'mrt-ro
443
443
  * @link https://www.material-react-table.com/docs/api/props
444
444
  */
445
445
  declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = Omit<Partial<TableOptions<TData>>, 'columns' | 'data' | 'expandRowsFn' | 'initialState' | 'onStateChange' | 'state'> & {
446
- displayColumnDefOptions?: Partial<{
447
- [key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
448
- }>;
449
446
  columnFilterModeOptions?: (MRT_FilterOption | string)[] | null;
450
447
  columns: MRT_ColumnDef<TData>[];
451
448
  data: TData[];
449
+ displayColumnDefOptions?: Partial<{
450
+ [key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
451
+ }>;
452
452
  editingMode?: 'table' | 'row' | 'cell';
453
453
  enableBottomToolbar?: boolean;
454
454
  enableClickToCopy?: boolean;
@@ -678,9 +678,9 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
678
678
  selectAllMode?: 'all' | 'page';
679
679
  state?: Partial<MRT_TableState<TData>>;
680
680
  tableId?: string;
681
- virtualizerProps?: ({ table, }: {
681
+ virtualizerProps?: Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>> | (({ table, }: {
682
682
  table: MRT_TableInstance<TData>;
683
- }) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>> | Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>;
683
+ }) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>);
684
684
  };
685
685
  declare const _default: <TData extends Record<string, any> = {}>({ aggregationFns, autoResetExpanded, columnResizeMode, defaultColumn, editingMode, enableBottomToolbar, enableColumnActions, enableColumnFilterChangeMode, enableColumnFilters, enableColumnOrdering, enableColumnResizing, enableDensityToggle, enableExpandAll, enableFilters, enableFullScreenToggle, enableGlobalFilter, enableGlobalFilterChangeMode, enableGlobalFilterRankedResults, enableGrouping, enableHiding, enableMultiRowSelection, enableMultiSort, enablePagination, enablePinning, enableRowSelection, enableSelectAll, enableSorting, enableStickyHeader, enableTableFooter, enableTableHead, enableToolbarInternalActions, enableTopToolbar, filterFns, icons, localization, positionActionsColumn, positionExpandColumn, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, rowNumberMode, selectAllMode, sortingFns, ...rest }: MaterialReactTableProps<TData>) => JSX.Element;
686
686
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.33.1",
2
+ "version": "0.33.4",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
@@ -450,12 +450,12 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
450
450
  | 'onStateChange'
451
451
  | 'state'
452
452
  > & {
453
- displayColumnDefOptions?: Partial<{
454
- [key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
455
- }>;
456
453
  columnFilterModeOptions?: (MRT_FilterOption | string)[] | null;
457
454
  columns: MRT_ColumnDef<TData>[];
458
455
  data: TData[];
456
+ displayColumnDefOptions?: Partial<{
457
+ [key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
458
+ }>;
459
459
  editingMode?: 'table' | 'row' | 'cell';
460
460
  enableBottomToolbar?: boolean;
461
461
  enableClickToCopy?: boolean;
@@ -812,13 +812,13 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
812
812
  selectAllMode?: 'all' | 'page';
813
813
  state?: Partial<MRT_TableState<TData>>;
814
814
  tableId?: string;
815
- virtualizerProps?: ({
816
- table,
817
- }: {
818
- table: MRT_TableInstance<TData>;
819
- }) =>
815
+ virtualizerProps?:
820
816
  | Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>
821
- | Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>;
817
+ | (({
818
+ table,
819
+ }: {
820
+ table: MRT_TableInstance<TData>;
821
+ }) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>);
822
822
  };
823
823
 
824
824
  export default <TData extends Record<string, any> = {}>({
@@ -66,7 +66,7 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
66
66
  count: rows.length,
67
67
  estimateSize: () => (density === 'compact' ? 25 : 50),
68
68
  getScrollElement: () => tableContainerRef.current as HTMLDivElement,
69
- overscan: density === 'compact' ? 30 : 10,
69
+ overscan: 10,
70
70
  ...vProps,
71
71
  })
72
72
  : ({} as any);
@@ -1,4 +1,11 @@
1
- import React, { DragEvent, FC, MouseEvent, RefObject, useMemo } from 'react';
1
+ import React, {
2
+ DragEvent,
3
+ FC,
4
+ MouseEvent,
5
+ RefObject,
6
+ useEffect,
7
+ useState,
8
+ } from 'react';
2
9
  import {
3
10
  alpha,
4
11
  darken,
@@ -74,15 +81,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
74
81
  ...mcTableCellBodyProps,
75
82
  };
76
83
 
77
- const skeletonWidth = useMemo(
78
- () =>
79
- columnDefType === 'display'
80
- ? column.getSize() / 2
81
- : Math.random() * (column.getSize() - column.getSize() / 3) +
82
- column.getSize() / 3,
83
- [],
84
- );
85
-
86
84
  const isEditable =
87
85
  (enableEditing || columnDef.enableEditing) &&
88
86
  columnDef.enableEditing !== false;
@@ -93,6 +91,22 @@ export const MRT_TableBodyCell: FC<Props> = ({
93
91
  currentEditingRow?.id === row.id ||
94
92
  currentEditingCell?.id === cell.id);
95
93
 
94
+ const [skeletonWidth, setSkeletonWidth] = useState(0);
95
+ useEffect(
96
+ () =>
97
+ setSkeletonWidth(
98
+ isLoading || showSkeletons
99
+ ? columnDefType === 'display'
100
+ ? column.getSize() / 2
101
+ : Math.round(
102
+ Math.random() * (column.getSize() - column.getSize() / 3) +
103
+ column.getSize() / 3,
104
+ )
105
+ : 100,
106
+ ),
107
+ [isLoading, showSkeletons],
108
+ );
109
+
96
110
  const handleDoubleClick = (_event: MouseEvent<HTMLTableCellElement>) => {
97
111
  if (
98
112
  (enableEditing || columnDef.enableEditing) &&
@@ -85,8 +85,8 @@ export const prepareColumns = <TData extends Record<string, any> = {}>(
85
85
  }
86
86
  } else if (columnDef.columnDefType === 'display') {
87
87
  columnDef = {
88
- ...columnDef,
89
88
  ...(defaultDisplayColumnDefOptions as MRT_ColumnDef<TData>),
89
+ ...columnDef,
90
90
  };
91
91
  }
92
92
  return columnDef;
@@ -1,4 +1,4 @@
1
- import React, { FC, useEffect, useLayoutEffect, useState } from 'react';
1
+ import React, { FC, useEffect, useLayoutEffect, useRef, useState } from 'react';
2
2
  import { TableContainer } from '@mui/material';
3
3
  import { MRT_Table } from './MRT_Table';
4
4
  import type { MRT_TableInstance } from '..';
@@ -45,7 +45,7 @@ export const MRT_TableContainer: FC<Props> = ({ table }) => {
45
45
  setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
46
46
  });
47
47
 
48
- const tableContainerRef = React.useRef<HTMLDivElement>(null);
48
+ const tableContainerRef = useRef<HTMLDivElement>(null);
49
49
 
50
50
  return (
51
51
  <TableContainer
@@ -211,7 +211,13 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
211
211
  () =>
212
212
  (props.state?.isLoading || props.state?.showSkeletons) &&
213
213
  !props.data.length
214
- ? [...Array(5).fill(null)].map(() =>
214
+ ? [
215
+ ...Array(
216
+ props.state?.pagination?.pageSize ||
217
+ initialState?.pagination?.pageSize ||
218
+ 10,
219
+ ).fill(null),
220
+ ].map(() =>
215
221
  Object.assign(
216
222
  {},
217
223
  ...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map(