material-react-table 1.0.0-beta.5 → 1.0.0-beta.8

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
@@ -1,4 +1,4 @@
1
- import { MutableRefObject, Dispatch, SetStateAction, ReactNode, DragEvent } from 'react';
1
+ import { MutableRefObject, Dispatch, SetStateAction, ReactNode } from 'react';
2
2
  import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, ToolbarProps, LinearProgressProps, CheckboxProps, SkeletonProps, TableBodyProps, TableRowProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, ChipProps, AlertProps } from '@mui/material';
3
3
  import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
4
4
  import { Options, VirtualItem } from 'react-virtual';
@@ -233,6 +233,7 @@ declare type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<Ta
233
233
  filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
234
234
  searchInputRef: MutableRefObject<HTMLInputElement>;
235
235
  tableContainerRef: MutableRefObject<HTMLDivElement>;
236
+ tablePaperRef: MutableRefObject<HTMLDivElement>;
236
237
  topToolbarRef: MutableRefObject<HTMLDivElement>;
237
238
  };
238
239
  setColumnFilterFns: Dispatch<SetStateAction<{
@@ -632,13 +633,6 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
632
633
  muiTopToolbarProps?: ToolbarProps | (({ table }: {
633
634
  table: MRT_TableInstance<TData>;
634
635
  }) => ToolbarProps);
635
- onColumnDrop?: ({ event, draggedColumn, targetColumn, }: {
636
- event: DragEvent<HTMLButtonElement>;
637
- draggedColumn: MRT_Column<TData>;
638
- targetColumn: MRT_Column<TData> | {
639
- id: string;
640
- } | null;
641
- }) => void;
642
636
  onDensityChange?: OnChangeFn<boolean>;
643
637
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
644
638
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
@@ -657,13 +651,6 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
657
651
  onHoveredColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
658
652
  onHoveredRowChange?: OnChangeFn<MRT_Row<TData> | null>;
659
653
  onIsFullScreenChange?: OnChangeFn<boolean>;
660
- onRowDrop?: ({ event, draggedRow, targetRow, }: {
661
- event: DragEvent<HTMLButtonElement>;
662
- draggedRow: MRT_Row<TData>;
663
- targetRow: MRT_Row<TData> | {
664
- id: string;
665
- } | null;
666
- }) => void;
667
654
  onShowAlertBannerChange?: OnChangeFn<boolean>;
668
655
  onShowFiltersChange?: OnChangeFn<boolean>;
669
656
  onShowGlobalFilterChange?: OnChangeFn<boolean>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-beta.5",
2
+ "version": "1.0.0-beta.8",
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.",
@@ -1,6 +1,5 @@
1
1
  import React, {
2
2
  Dispatch,
3
- DragEvent,
4
3
  MutableRefObject,
5
4
  ReactNode,
6
5
  SetStateAction,
@@ -101,6 +100,7 @@ export type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<
101
100
  filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
102
101
  searchInputRef: MutableRefObject<HTMLInputElement>;
103
102
  tableContainerRef: MutableRefObject<HTMLDivElement>;
103
+ tablePaperRef: MutableRefObject<HTMLDivElement>;
104
104
  topToolbarRef: MutableRefObject<HTMLDivElement>;
105
105
  };
106
106
  setColumnFilterFns: Dispatch<
@@ -753,15 +753,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
753
753
  muiTopToolbarProps?:
754
754
  | ToolbarProps
755
755
  | (({ table }: { table: MRT_TableInstance<TData> }) => ToolbarProps);
756
- onColumnDrop?: ({
757
- event,
758
- draggedColumn,
759
- targetColumn,
760
- }: {
761
- event: DragEvent<HTMLButtonElement>;
762
- draggedColumn: MRT_Column<TData>;
763
- targetColumn: MRT_Column<TData> | { id: string } | null;
764
- }) => void;
765
756
  onDensityChange?: OnChangeFn<boolean>;
766
757
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
767
758
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
@@ -783,15 +774,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
783
774
  onHoveredColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
784
775
  onHoveredRowChange?: OnChangeFn<MRT_Row<TData> | null>;
785
776
  onIsFullScreenChange?: OnChangeFn<boolean>;
786
- onRowDrop?: ({
787
- event,
788
- draggedRow,
789
- targetRow,
790
- }: {
791
- event: DragEvent<HTMLButtonElement>;
792
- draggedRow: MRT_Row<TData>;
793
- targetRow: MRT_Row<TData> | { id: string } | null;
794
- }) => void;
795
777
  onShowAlertBannerChange?: OnChangeFn<boolean>;
796
778
  onShowFiltersChange?: OnChangeFn<boolean>;
797
779
  onShowGlobalFilterChange?: OnChangeFn<boolean>;
@@ -1,7 +1,7 @@
1
1
  import React, { FC, useMemo } from 'react';
2
2
  import { useVirtual } from 'react-virtual'; //stuck on v2 for now
3
3
  // import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
4
- import { Box, TableBody, TableCell, TableRow } from '@mui/material';
4
+ import { TableBody, Typography } from '@mui/material';
5
5
  import { MRT_TableBodyRow } from './MRT_TableBodyRow';
6
6
  import { rankGlobalFuzzy } from '../sortingFns';
7
7
  import type { MRT_Row, MRT_TableInstance } from '..';
@@ -26,7 +26,7 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
26
26
  virtualizerInstanceRef,
27
27
  virtualizerProps,
28
28
  },
29
- refs: { tableContainerRef },
29
+ refs: { tableContainerRef, tablePaperRef },
30
30
  } = table;
31
31
  const { columnFilters, globalFilter, pagination, sorting } = getState();
32
32
 
@@ -118,11 +118,13 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
118
118
  return (
119
119
  <TableBody {...tableBodyProps}>
120
120
  {!rows.length ? (
121
- <TableRow>
122
- <TableCell colSpan={table.getVisibleLeafColumns().length}>
123
- <Box
121
+ <tr>
122
+ <td colSpan={table.getVisibleLeafColumns().length}>
123
+ <Typography
124
124
  sx={{
125
- maxWidth: '100vw',
125
+ color: 'text.secondary',
126
+ fontStyle: 'italic',
127
+ maxWidth: `min(100vw, ${tablePaperRef.current?.clientWidth}px)`,
126
128
  py: '2rem',
127
129
  textAlign: 'center',
128
130
  width: '100%',
@@ -131,9 +133,9 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
131
133
  {globalFilter || columnFilters.length
132
134
  ? localization.noResultsFound
133
135
  : localization.noRecordsToDisplay}
134
- </Box>
135
- </TableCell>
136
- </TableRow>
136
+ </Typography>
137
+ </td>
138
+ </tr>
137
139
  ) : (
138
140
  <>
139
141
  {enableRowVirtualization && paddingTop > 0 && (
@@ -14,7 +14,7 @@ export const MRT_TableBodyRowGrabHandle: FC<Props> = ({
14
14
  table,
15
15
  }) => {
16
16
  const {
17
- options: { muiTableBodyRowDragHandleProps, onRowDrop },
17
+ options: { muiTableBodyRowDragHandleProps },
18
18
  } = table;
19
19
  const { row } = cell;
20
20
 
@@ -23,17 +23,14 @@ export const MRT_TableBodyRowGrabHandle: FC<Props> = ({
23
23
  ? muiTableBodyRowDragHandleProps({ row, table })
24
24
  : muiTableBodyRowDragHandleProps;
25
25
 
26
- const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
27
- e.dataTransfer.setDragImage(rowRef.current as HTMLElement, 0, 0);
26
+ const handleDragStart = (event: DragEvent<HTMLButtonElement>) => {
27
+ iconButtonProps?.onDragStart?.(event);
28
+ event.dataTransfer.setDragImage(rowRef.current as HTMLElement, 0, 0);
28
29
  table.setDraggingRow(row as any);
29
30
  };
30
31
 
31
32
  const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
32
- onRowDrop?.({
33
- event,
34
- draggedRow: table.getState().draggingRow as any,
35
- targetRow: table.getState().hoveredRow as any,
36
- });
33
+ iconButtonProps?.onDragEnd?.(event);
37
34
  table.setDraggingRow(null);
38
35
  table.setHoveredRow(null);
39
36
  };
@@ -33,14 +33,14 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any> = {}>({
33
33
  <IconButton
34
34
  disableRipple
35
35
  draggable="true"
36
- onDragStart={onDragStart}
37
- onDragEnd={onDragEnd}
38
36
  size="small"
39
37
  {...iconButtonProps}
40
38
  onClick={(e) => {
41
39
  e.stopPropagation();
42
40
  iconButtonProps?.onClick?.(e);
43
41
  }}
42
+ onDragStart={onDragStart}
43
+ onDragEnd={onDragEnd}
44
44
  sx={(theme) => ({
45
45
  cursor: 'grab',
46
46
  m: 0,
@@ -1,5 +1,5 @@
1
1
  import React, { FC } from 'react';
2
- import { TableFooter } from '@mui/material';
2
+ import { lighten, TableFooter } from '@mui/material';
3
3
  import { MRT_TableFooterRow } from './MRT_TableFooterRow';
4
4
  import type { MRT_TableInstance } from '..';
5
5
 
@@ -27,7 +27,7 @@ export const MRT_TableFooter: FC<Props> = ({ table }) => {
27
27
  <TableFooter
28
28
  {...tableFooterProps}
29
29
  sx={(theme) => ({
30
- position: stickFooter ? 'sticky' : undefined,
30
+ backgroundColor: lighten(theme.palette.background.default, 0.06),
31
31
  bottom: stickFooter ? 0 : undefined,
32
32
  opacity: stickFooter ? 0.95 : undefined,
33
33
  outline: stickFooter
@@ -35,6 +35,7 @@ export const MRT_TableFooter: FC<Props> = ({ table }) => {
35
35
  ? `1px solid ${theme.palette.grey[300]}`
36
36
  : `1px solid ${theme.palette.grey[700]}`
37
37
  : undefined,
38
+ position: stickFooter ? 'sticky' : undefined,
38
39
  ...(tableFooterProps?.sx instanceof Function
39
40
  ? tableFooterProps?.sx(theme)
40
41
  : (tableFooterProps?.sx as any)),
@@ -17,11 +17,11 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
17
17
  const { column } = header;
18
18
  const { columnDef } = column;
19
19
 
20
- const isRangeFilter = [
21
- 'between',
22
- 'betweenInclusive',
23
- 'inNumberRange',
24
- ].includes(columnDef._filterFn);
20
+ const isRangeFilter =
21
+ columnDef.filterVariant === 'range' ||
22
+ ['between', 'betweenInclusive', 'inNumberRange'].includes(
23
+ columnDef._filterFn,
24
+ );
25
25
  const currentFilterOption = columnDef._filterFn;
26
26
  const filterTooltip = localization.filteringByColumn
27
27
  .replace('{column}', String(columnDef.header))
@@ -51,8 +51,8 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
51
51
  <Grow
52
52
  unmountOnExit
53
53
  in={
54
- (!!column.getFilterValue() && isRangeFilter) ||
55
- (!isRangeFilter && // @ts-ignore
54
+ (!!column.getFilterValue() && !isRangeFilter) ||
55
+ (isRangeFilter && // @ts-ignore
56
56
  (!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
57
57
  }
58
58
  >
@@ -16,11 +16,7 @@ export const MRT_TableHeadCellGrabHandle: FC<Props> = ({
16
16
  }) => {
17
17
  const {
18
18
  getState,
19
- options: {
20
- enableColumnOrdering,
21
- muiTableHeadCellDragHandleProps,
22
- onColumnDrop,
23
- },
19
+ options: { enableColumnOrdering, muiTableHeadCellDragHandleProps },
24
20
  setColumnOrder,
25
21
  setDraggingColumn,
26
22
  setHoveredColumn,
@@ -43,17 +39,14 @@ export const MRT_TableHeadCellGrabHandle: FC<Props> = ({
43
39
  ...mcIconButtonProps,
44
40
  };
45
41
 
46
- const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
42
+ const handleDragStart = (event: DragEvent<HTMLButtonElement>) => {
43
+ iconButtonProps?.onDragStart?.(event);
47
44
  setDraggingColumn(column);
48
- e.dataTransfer.setDragImage(tableHeadCellRef.current as HTMLElement, 0, 0);
45
+ event.dataTransfer.setDragImage(tableHeadCellRef.current as HTMLElement, 0, 0);
49
46
  };
50
47
 
51
48
  const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
52
- onColumnDrop?.({
53
- event,
54
- draggedColumn: column,
55
- targetColumn: hoveredColumn,
56
- });
49
+ iconButtonProps?.onDragEnd?.(event);
57
50
  if (hoveredColumn?.id === 'drop-zone') {
58
51
  column.toggleGrouping();
59
52
  } else if (
@@ -1,4 +1,4 @@
1
- import React, { FC, useEffect } from 'react';
1
+ import React, { FC } from 'react';
2
2
  import { Paper } from '@mui/material';
3
3
  import { MRT_TopToolbar } from '../toolbar/MRT_TopToolbar';
4
4
  import { MRT_BottomToolbar } from '../toolbar/MRT_BottomToolbar';
@@ -13,19 +13,10 @@ export const MRT_TablePaper: FC<Props> = ({ table }) => {
13
13
  const {
14
14
  getState,
15
15
  options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps },
16
+ refs: { tablePaperRef },
16
17
  } = table;
17
18
  const { isFullScreen } = getState();
18
19
 
19
- useEffect(() => {
20
- if (typeof window !== 'undefined') {
21
- if (isFullScreen) {
22
- document.body.style.height = '100vh';
23
- } else {
24
- document.body.style.height = 'auto';
25
- }
26
- }
27
- }, [isFullScreen]);
28
-
29
20
  const tablePaperProps =
30
21
  muiTablePaperProps instanceof Function
31
22
  ? muiTablePaperProps({ table })
@@ -35,6 +26,13 @@ export const MRT_TablePaper: FC<Props> = ({ table }) => {
35
26
  <Paper
36
27
  elevation={2}
37
28
  {...tablePaperProps}
29
+ ref={(ref: HTMLDivElement) => {
30
+ tablePaperRef.current = ref;
31
+ if (tablePaperProps?.ref) {
32
+ //@ts-ignore
33
+ tablePaperProps.ref.current = ref;
34
+ }
35
+ }}
38
36
  sx={(theme) => ({
39
37
  transition: 'all 0.2s ease-in-out',
40
38
  ...(tablePaperProps?.sx instanceof Function
@@ -43,12 +41,16 @@ export const MRT_TablePaper: FC<Props> = ({ table }) => {
43
41
  })}
44
42
  style={{
45
43
  ...tablePaperProps?.style,
46
- height: isFullScreen ? '100vh' : undefined,
47
- margin: isFullScreen ? '0' : undefined,
48
- maxHeight: isFullScreen ? '100vh' : undefined,
49
- maxWidth: isFullScreen ? '100vw' : undefined,
50
- padding: isFullScreen ? '0' : undefined,
51
- width: isFullScreen ? '100vw' : undefined,
44
+ ...(isFullScreen
45
+ ? {
46
+ height: '100vh',
47
+ margin: 0,
48
+ maxHeight: '100vh',
49
+ maxWidth: '100vw',
50
+ padding: 0,
51
+ width: '100vw',
52
+ }
53
+ : {}),
52
54
  }}
53
55
  >
54
56
  {enableTopToolbar && <MRT_TopToolbar table={table} />}
@@ -1,4 +1,4 @@
1
- import React, { useMemo, useRef, useState } from 'react';
1
+ import React, { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import {
3
3
  TableState,
4
4
  getCoreRowModel,
@@ -45,6 +45,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
45
45
  const filterInputRefs = useRef<Record<string, HTMLInputElement>>({});
46
46
  const searchInputRef = useRef<HTMLInputElement>(null);
47
47
  const tableContainerRef = useRef<HTMLDivElement>(null);
48
+ const tablePaperRef = useRef<HTMLDivElement>(null);
48
49
  const topToolbarRef = useRef<HTMLDivElement>(null);
49
50
 
50
51
  const initialState: Partial<MRT_TableState<TData>> = useMemo(() => {
@@ -292,6 +293,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
292
293
  filterInputRefs,
293
294
  searchInputRef,
294
295
  tableContainerRef,
296
+ tablePaperRef,
295
297
  topToolbarRef,
296
298
  },
297
299
  setColumnFilterFns: props.onFilterFnsChange ?? setColumnFilterFns,
@@ -313,6 +315,24 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
313
315
  props.tableInstanceRef.current = table;
314
316
  }
315
317
 
318
+ const initialBodyHeight = useRef<string>();
319
+
320
+ useEffect(() => {
321
+ if (typeof window !== 'undefined') {
322
+ initialBodyHeight.current = document.body.style.height;
323
+ }
324
+ }, []);
325
+
326
+ useEffect(() => {
327
+ if (typeof window !== 'undefined') {
328
+ if (table.getState().isFullScreen) {
329
+ document.body.style.height = '100vh';
330
+ } else {
331
+ document.body.style.height = initialBodyHeight.current as string;
332
+ }
333
+ }
334
+ }, [table.getState().isFullScreen]);
335
+
316
336
  return (
317
337
  <>
318
338
  <Dialog
@@ -102,7 +102,13 @@ export const MRT_TopToolbar: FC<Props> = ({ table }) => {
102
102
  )}
103
103
  {renderTopToolbarCustomActions?.({ table }) ?? <span />}
104
104
  {enableToolbarInternalActions ? (
105
- <Box sx={{ display: 'flex', flexWrap: 'wrap' }}>
105
+ <Box
106
+ sx={{
107
+ display: 'flex',
108
+ flexWrap: 'wrap-reverse',
109
+ justifyContent: 'flex-end',
110
+ }}
111
+ >
106
112
  {enableGlobalFilter && positionGlobalFilter === 'right' && (
107
113
  <MRT_GlobalFilterTextField table={table} />
108
114
  )}