material-react-table 0.33.3 → 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;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.33.3",
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;
@@ -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) &&
@@ -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(