material-react-table 0.15.0 → 0.16.1

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.
@@ -1,2 +1,3 @@
1
+ /// <reference types="react" />
1
2
  import { MaterialReactTableProps } from '../MaterialReactTable';
2
3
  export declare const MRT_TableRoot: <D extends Record<string, any> = {}>(props: MaterialReactTableProps<D>) => JSX.Element;
package/dist/utils.d.ts CHANGED
@@ -2,12 +2,12 @@ import { ColumnDef, ColumnOrderState, Table, Updater } from '@tanstack/react-tab
2
2
  import { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_FilterFn } from '.';
3
3
  export declare const getAllLeafColumnDefs: (columns: MRT_ColumnDef[]) => MRT_ColumnDef[];
4
4
  export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
5
- [key: string]: import("@tanstack/react-table").FilterFnOption<import("@tanstack/react-table").TableGenerics>;
5
+ [key: string]: import("@tanstack/table-core").FilterFnOption<import("@tanstack/table-core").TableGenerics>;
6
6
  }) => ColumnDef<D>;
7
7
  export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
8
- [key: string]: import("@tanstack/react-table").FilterFnOption<import("@tanstack/react-table").TableGenerics>;
8
+ [key: string]: import("@tanstack/table-core").FilterFnOption<import("@tanstack/table-core").TableGenerics>;
9
9
  }) => ColumnDef<D>;
10
- export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "columns" | "filterFn" | "footer" | "sortingFn" | "id" | "accessorKey" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "AggregatedCell" | "Cell" | "Edit" | "Filter" | "Footer" | "Header" | "enableClickToCopy" | "enableColumnActions" | "enableColumnOrdering" | "enableEditing" | "enableColumnFilterChangeMode" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChanged" | "onColumnFilterValueChanged" | "onColumnFilterValueChangedDebounced"> & {
10
+ export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "columns" | "filterFn" | "footer" | "sortingFn" | "id" | "accessorKey" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "AggregatedCell" | "Cell" | "Edit" | "Filter" | "Footer" | "Header" | "enableClickToCopy" | "enableColumnActions" | "enableColumnFilterChangeMode" | "enableColumnOrdering" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChanged" | "onColumnFilterValueChanged" | "onColumnFilterValueChangedDebounced"> & {
11
11
  header?: string | undefined;
12
12
  }) => ColumnDef<D>;
13
13
  export declare const reorderColumn: (movingColumn: MRT_Column, receivingColumn: MRT_Column, columnOrder: ColumnOrderState, setColumnOrder: (updater: Updater<ColumnOrderState>) => void) => void;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.15.0",
2
+ "version": "0.16.1",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI implementation of TanStack React Table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
@@ -56,12 +56,12 @@
56
56
  }
57
57
  ],
58
58
  "devDependencies": {
59
- "@babel/core": "^7.18.5",
59
+ "@babel/core": "^7.18.6",
60
60
  "@emotion/react": "^11.9.3",
61
61
  "@emotion/styled": "^11.9.3",
62
62
  "@faker-js/faker": "^7.3.0",
63
63
  "@mui/icons-material": "^5.8.4",
64
- "@mui/material": "^5.8.5",
64
+ "@mui/material": "^5.8.6",
65
65
  "@size-limit/preset-small-lib": "^7.0.8",
66
66
  "@storybook/addon-a11y": "^6.5.9",
67
67
  "@storybook/addon-actions": "^6.5.9",
@@ -77,8 +77,8 @@
77
77
  "eslint-plugin-react-hooks": "^4.6.0",
78
78
  "husky": "^8.0.1",
79
79
  "prettier": "^2.7.1",
80
- "react": "^17.0.2",
81
- "react-dom": "^17.0.2",
80
+ "react": "^18.2.0",
81
+ "react-dom": "^18.2.0",
82
82
  "react-is": "^18.2.0",
83
83
  "rollup-plugin-commonjs": "^10.1.0",
84
84
  "rollup-plugin-node-resolve": "^5.2.0",
@@ -97,8 +97,8 @@
97
97
  "react": ">=16.8"
98
98
  },
99
99
  "dependencies": {
100
- "@tanstack/match-sorter-utils": "^8.0.0-alpha.83",
101
- "@tanstack/react-table": "^8.0.0-beta.9",
100
+ "@tanstack/match-sorter-utils": "8.0.13",
101
+ "@tanstack/react-table": "8.0.13",
102
102
  "react-dnd": "^16.0.1",
103
103
  "react-dnd-html5-backend": "^16.0.1",
104
104
  "react-virtual": "^2.10.4"
@@ -205,9 +205,9 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
205
205
  columns?: MRT_ColumnDef<D>[];
206
206
  enableClickToCopy?: boolean;
207
207
  enableColumnActions?: boolean;
208
+ enableColumnFilterChangeMode?: boolean;
208
209
  enableColumnOrdering?: boolean;
209
210
  enableEditing?: boolean;
210
- enableColumnFilterChangeMode?: boolean;
211
211
  enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[] | null;
212
212
  filterFn?: MRT_FilterFn;
213
213
  filterSelectOptions?: (string | { text: string; value: string })[];
@@ -12,7 +12,7 @@ interface Props {
12
12
 
13
13
  export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
14
14
  const {
15
- getPaginationRowModel,
15
+ getRowModel,
16
16
  getPrePaginationRowModel,
17
17
  getState,
18
18
  options: {
@@ -24,15 +24,23 @@ export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
24
24
  },
25
25
  } = instance;
26
26
 
27
- const { density, globalFilter, pagination } = getState();
27
+ const { density, globalFilter, pagination, sorting } = getState();
28
28
 
29
29
  const tableBodyProps =
30
30
  muiTableBodyProps instanceof Function
31
31
  ? muiTableBodyProps({ instance })
32
32
  : muiTableBodyProps;
33
33
 
34
+ const getIsSomeColumnsSorted = () => {
35
+ return Object.values(sorting).some(Boolean);
36
+ };
37
+
34
38
  const rows = useMemo(() => {
35
- if (enableGlobalFilterRankedResults && globalFilter) {
39
+ if (
40
+ enableGlobalFilterRankedResults &&
41
+ globalFilter &&
42
+ !getIsSomeColumnsSorted()
43
+ ) {
36
44
  const rankedRows = getPrePaginationRowModel().rows.sort((a, b) =>
37
45
  rankGlobalFuzzy(a, b),
38
46
  );
@@ -43,13 +51,13 @@ export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
43
51
  }
44
52
 
45
53
  return enablePagination
46
- ? getPaginationRowModel().rows
54
+ ? getRowModel().rows
47
55
  : getPrePaginationRowModel().rows;
48
56
  }, [
49
57
  enableGlobalFilterRankedResults,
50
58
  (enableGlobalFilterRankedResults && globalFilter) || !enablePagination
51
59
  ? getPrePaginationRowModel().rows
52
- : getPaginationRowModel().rows,
60
+ : getRowModel().rows,
53
61
  globalFilter,
54
62
  ]);
55
63
 
@@ -36,7 +36,6 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({
36
36
  touchAction: 'none',
37
37
  transition: column.getIsResizing() ? undefined : 'all 0.2s ease-in-out',
38
38
  userSelect: 'none',
39
- zIndex: 2000,
40
39
  '&:active': {
41
40
  backgroundColor: theme.palette.info.main,
42
41
  opacity: 1,
@@ -9,22 +9,9 @@ interface Props {
9
9
  }
10
10
 
11
11
  export const MRT_FilterRangeFields: FC<Props> = ({ header, instance }) => {
12
- const {
13
- options: { localization },
14
- } = instance;
15
-
16
12
  return (
17
- <Box sx={{ display: 'grid', gridTemplateColumns: '6fr auto 5fr' }}>
13
+ <Box sx={{ display: 'grid', gridTemplateColumns: '6fr 6fr', gap: '1rem' }}>
18
14
  <MRT_FilterTextField header={header} inputIndex={0} instance={instance} />
19
- <Box
20
- sx={{
21
- width: '100%',
22
- minWidth: '5ch',
23
- textAlign: 'center',
24
- }}
25
- >
26
- {localization.to}
27
- </Box>
28
15
  <MRT_FilterTextField header={header} inputIndex={1} instance={instance} />
29
16
  </Box>
30
17
  );
@@ -55,11 +55,11 @@ export interface MRT_Localization {
55
55
  sortedByColumnAsc: string;
56
56
  sortedByColumnDesc: string;
57
57
  thenBy: string;
58
- to: string;
59
58
  toggleDensity: string;
60
59
  toggleFullScreen: string;
61
60
  toggleSelectAll: string;
62
61
  toggleSelectRow: string;
62
+ toggleVisibility: string;
63
63
  ungroupByColumn: string;
64
64
  unpin: string;
65
65
  unpinAll: string;
@@ -124,11 +124,11 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
124
124
  sortedByColumnAsc: 'Sorted by {column} ascending',
125
125
  sortedByColumnDesc: 'Sorted by {column} descending',
126
126
  thenBy: ', then by ',
127
- to: 'to',
128
127
  toggleDensity: 'Toggle density',
129
128
  toggleFullScreen: 'Toggle full screen',
130
129
  toggleSelectAll: 'Toggle select all',
131
130
  toggleSelectRow: 'Toggle select row',
131
+ toggleVisibility: 'Toggle visibility',
132
132
  ungroupByColumn: 'Ungroup by {column}',
133
133
  unpin: 'Unpin',
134
134
  unpinAll: 'Unpin all',
@@ -1,6 +1,13 @@
1
1
  import React, { FC, Ref } from 'react';
2
2
  import { useDrag, useDrop } from 'react-dnd';
3
- import { Box, FormControlLabel, MenuItem, Switch } from '@mui/material';
3
+ import {
4
+ Box,
5
+ FormControlLabel,
6
+ MenuItem,
7
+ Switch,
8
+ Tooltip,
9
+ Typography,
10
+ } from '@mui/material';
4
11
  import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
5
12
  import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
6
13
  import { reorderColumn } from '../utils';
@@ -21,7 +28,13 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
21
28
  }) => {
22
29
  const {
23
30
  getState,
24
- options: { enableColumnOrdering, onColumnVisibilityChanged },
31
+ options: {
32
+ enableColumnOrdering,
33
+ enableHiding,
34
+ enablePinning,
35
+ localization,
36
+ onColumnVisibilityChanged,
37
+ },
25
38
  setColumnOrder,
26
39
  } = instance;
27
40
 
@@ -85,35 +98,56 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
85
98
  >
86
99
  {columnDefType !== 'group' &&
87
100
  enableColumnOrdering &&
88
- columnDef.enableColumnOrdering !== false &&
89
- !allColumns.some((col) => col.columnDefType === 'group') && (
101
+ !allColumns.some((col) => col.columnDefType === 'group') &&
102
+ (columnDef.enableColumnOrdering !== false ? (
90
103
  <MRT_GrabHandleButton
91
104
  ref={dragRef as Ref<HTMLButtonElement>}
92
105
  instance={instance}
93
106
  />
94
- )}
95
- {!isSubMenu && column.getCanPin() && (
96
- <MRT_ColumnPinningButtons column={column} instance={instance} />
97
- )}
98
- <FormControlLabel
99
- componentsProps={{
100
- typography: {
101
- sx: {
102
- mb: 0,
103
- opacity: columnDefType !== 'display' ? 1 : 0.5,
107
+ ) : (
108
+ <Box sx={{ width: '28px' }} />
109
+ ))}
110
+ {enablePinning &&
111
+ !isSubMenu &&
112
+ (column.getCanPin() ? (
113
+ <MRT_ColumnPinningButtons column={column} instance={instance} />
114
+ ) : (
115
+ <Box sx={{ width: '70px' }} />
116
+ ))}
117
+ {enableHiding ? (
118
+ <FormControlLabel
119
+ componentsProps={{
120
+ typography: {
121
+ sx: {
122
+ mb: 0,
123
+ opacity: columnDefType !== 'display' ? 1 : 0.5,
124
+ },
104
125
  },
105
- },
106
- }}
107
- checked={switchChecked}
108
- control={<Switch />}
109
- disabled={
110
- (isSubMenu && switchChecked) ||
111
- !column.getCanHide() ||
112
- column.getIsGrouped()
113
- }
114
- label={columnDef.header}
115
- onChange={() => handleToggleColumnHidden(column)}
116
- />
126
+ }}
127
+ checked={switchChecked}
128
+ control={
129
+ <Tooltip
130
+ arrow
131
+ enterDelay={1000}
132
+ enterNextDelay={1000}
133
+ title={localization.toggleVisibility}
134
+ >
135
+ <Switch />
136
+ </Tooltip>
137
+ }
138
+ disabled={
139
+ (isSubMenu && switchChecked) ||
140
+ !column.getCanHide() ||
141
+ column.getIsGrouped()
142
+ }
143
+ label={columnDef.header}
144
+ onChange={() => handleToggleColumnHidden(column)}
145
+ />
146
+ ) : (
147
+ <Typography sx={{ alignSelf: 'center' }}>
148
+ {columnDef.header}
149
+ </Typography>
150
+ )}
117
151
  </Box>
118
152
  </MenuItem>
119
153
  {column.columns?.map((c: MRT_Column, i) => (
@@ -42,6 +42,9 @@ export const MRT_TablePaper: FC<Props> = ({ instance }) => {
42
42
  sx={{
43
43
  transition: 'all 0.2s ease-in-out',
44
44
  ...tablePaperProps?.sx,
45
+ }}
46
+ style={{
47
+ ...tablePaperProps?.style,
45
48
  height: isFullScreen ? '100vh' : undefined,
46
49
  margin: isFullScreen ? '0' : undefined,
47
50
  maxHeight: isFullScreen ? '100vh' : undefined,
@@ -168,7 +168,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
168
168
  id: 'mrt-expand',
169
169
  muiTableBodyCellProps: props.muiTableBodyCellProps,
170
170
  muiTableHeadCellProps: props.muiTableHeadCellProps,
171
- size: 50,
171
+ size: 60,
172
172
  }),
173
173
  columnOrder.includes('mrt-select') &&
174
174
  createDisplayColumn(table, {
@@ -183,7 +183,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
183
183
  id: 'mrt-select',
184
184
  muiTableBodyCellProps: props.muiTableBodyCellProps,
185
185
  muiTableHeadCellProps: props.muiTableHeadCellProps,
186
- size: 50,
186
+ size: 60,
187
187
  }),
188
188
  columnOrder.includes('mrt-row-numbers') &&
189
189
  createDisplayColumn(table, {
@@ -193,7 +193,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
193
193
  id: 'mrt-row-numbers',
194
194
  muiTableBodyCellProps: props.muiTableBodyCellProps,
195
195
  muiTableHeadCellProps: props.muiTableHeadCellProps,
196
- size: 50,
196
+ size: 60,
197
197
  }),
198
198
  ].filter(Boolean) as MRT_ColumnDef<D>[];
199
199
  }, [
@@ -16,11 +16,13 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ instance }) => {
16
16
  const {
17
17
  options: {
18
18
  enableColumnFilters,
19
+ enableColumnOrdering,
19
20
  enableDensityToggle,
20
21
  enableFilters,
21
22
  enableFullScreenToggle,
22
23
  enableGlobalFilter,
23
24
  enableHiding,
25
+ enablePinning,
24
26
  positionGlobalFilter,
25
27
  renderToolbarInternalActions,
26
28
  },
@@ -52,7 +54,9 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ instance }) => {
52
54
  {enableFilters && enableColumnFilters && (
53
55
  <MRT_ToggleFiltersButton instance={instance} />
54
56
  )}
55
- {enableHiding && <MRT_ShowHideColumnsButton instance={instance} />}
57
+ {(enableHiding || enableColumnOrdering || enablePinning) && (
58
+ <MRT_ShowHideColumnsButton instance={instance} />
59
+ )}
56
60
  {enableDensityToggle && (
57
61
  <MRT_ToggleDensePaddingButton instance={instance} />
58
62
  )}