material-react-table 1.0.0-beta.3 → 1.0.0-beta.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.
@@ -1,7 +1,7 @@
1
1
  import { FC } from 'react';
2
2
  import { MRT_TableInstance } from '..';
3
3
  interface Props {
4
- stackAlertBanner?: boolean;
4
+ stackAlertBanner: boolean;
5
5
  table: MRT_TableInstance;
6
6
  }
7
7
  export declare const MRT_ToolbarAlertBanner: FC<Props>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-beta.3",
2
+ "version": "1.0.0-beta.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.",
@@ -6,19 +6,13 @@ import React, {
6
6
  useEffect,
7
7
  useState,
8
8
  } from 'react';
9
- import {
10
- alpha,
11
- darken,
12
- lighten,
13
- Skeleton,
14
- TableCell,
15
- useTheme,
16
- } from '@mui/material';
9
+ import { darken, lighten, Skeleton, TableCell, useTheme } from '@mui/material';
17
10
  import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
18
11
  import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
19
- import type { MRT_Cell, MRT_TableInstance } from '..';
20
12
  import { MRT_TableBodyRowGrabHandle } from './MRT_TableBodyRowGrabHandle';
21
13
  import { MRT_TableBodyCellValue } from './MRT_TableBodyCellValue';
14
+ import { getCommonCellStyles } from '../column.utils';
15
+ import type { MRT_Cell, MRT_TableInstance } from '..';
22
16
 
23
17
  interface Props {
24
18
  cell: MRT_Cell;
@@ -132,23 +126,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
132
126
  }
133
127
  };
134
128
 
135
- const getIsLastLeftPinnedColumn = () => {
136
- return (
137
- column.getIsPinned() === 'left' &&
138
- table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
139
- );
140
- };
141
-
142
- const getIsFirstRightPinnedColumn = () => {
143
- return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
144
- };
145
-
146
- const getTotalRight = () => {
147
- return (
148
- (table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160
149
- );
150
- };
151
-
152
129
  const handleDragEnter = (e: DragEvent<HTMLTableCellElement>) => {
153
130
  tableCellProps?.onDragEnter?.(e);
154
131
  if (enableGrouping && hoveredColumn?.id === 'drop-zone') {
@@ -190,23 +167,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
190
167
  onDragEnter={handleDragEnter}
191
168
  onDoubleClick={handleDoubleClick}
192
169
  sx={(theme) => ({
193
- backgroundColor: column.getIsPinned()
194
- ? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
195
- : undefined,
196
- boxShadow: getIsLastLeftPinnedColumn()
197
- ? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
198
- : getIsFirstRightPinnedColumn()
199
- ? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
200
- : undefined,
201
170
  cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text',
202
- left:
203
- column.getIsPinned() === 'left'
204
- ? `${column.getStart('left')}px`
205
- : undefined,
206
- opacity:
207
- draggingColumn?.id === column.id || hoveredColumn?.id === column.id
208
- ? 0.5
209
- : 1,
210
171
  overflow: 'hidden',
211
172
  p:
212
173
  density === 'compact'
@@ -231,11 +192,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
231
192
  : 1.25)
232
193
  }rem`
233
194
  : undefined,
234
- position: column.getIsPinned() ? 'sticky' : 'relative',
235
- right:
236
- column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
237
195
  textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined,
238
- transition: 'all 0.2s ease-in-out',
239
196
  whiteSpace: density === 'compact' ? 'nowrap' : 'normal',
240
197
  zIndex:
241
198
  draggingColumn?.id === column.id ? 2 : column.getIsPinned() ? 1 : 0,
@@ -250,13 +207,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
250
207
  : `${darken(theme.palette.background.default, 0.1)} !important`
251
208
  : undefined,
252
209
  },
253
- ...(tableCellProps?.sx instanceof Function
254
- ? tableCellProps.sx(theme)
255
- : (tableCellProps?.sx as any)),
210
+ ...getCommonCellStyles({ column, table, theme, tableCellProps }),
256
211
  ...draggingBorders,
257
- maxWidth: `min(${column.getSize()}px, fit-content)`,
258
- minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
259
- width: column.getSize(),
260
212
  })}
261
213
  >
262
214
  <>
@@ -1,4 +1,5 @@
1
1
  import { ColumnOrderState, GroupingState } from '@tanstack/react-table';
2
+ import { alpha, lighten, TableCellProps, Theme } from '@mui/material';
2
3
  import {
3
4
  MaterialReactTableProps,
4
5
  MRT_Column,
@@ -6,6 +7,8 @@ import {
6
7
  MRT_DefinedColumnDef,
7
8
  MRT_DisplayColumnIds,
8
9
  MRT_FilterOption,
10
+ MRT_Header,
11
+ MRT_TableInstance,
9
12
  } from '.';
10
13
  import { MRT_FilterFns } from './filterFns';
11
14
  import { MRT_SortingFns } from './sortingFns';
@@ -165,3 +168,72 @@ export const getDefaultColumnFilterFn = <
165
168
  if (columnDef.filterVariant === 'range') return 'betweenInclusive';
166
169
  return 'fuzzy';
167
170
  };
171
+
172
+ export const getIsLastLeftPinnedColumn = (
173
+ table: MRT_TableInstance,
174
+ column: MRT_Column,
175
+ ) => {
176
+ return (
177
+ column.getIsPinned() === 'left' &&
178
+ table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
179
+ );
180
+ };
181
+
182
+ export const getIsFirstRightPinnedColumn = (column: MRT_Column) => {
183
+ return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
184
+ };
185
+
186
+ export const getTotalRight = (table: MRT_TableInstance, column: MRT_Column) => {
187
+ return (
188
+ (table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160
189
+ );
190
+ };
191
+
192
+ export const getCommonCellStyles = ({
193
+ column,
194
+ header,
195
+ table,
196
+ tableCellProps,
197
+ theme,
198
+ }: {
199
+ column: MRT_Column;
200
+ header?: MRT_Header;
201
+ table: MRT_TableInstance;
202
+ tableCellProps: TableCellProps;
203
+ theme: Theme;
204
+ }) => ({
205
+ backgroundColor:
206
+ column.getIsPinned() && column.columnDef.columnDefType !== 'group'
207
+ ? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
208
+ : 'inherit',
209
+ backgroundImage: 'inherit',
210
+ boxShadow: getIsLastLeftPinnedColumn(table, column)
211
+ ? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
212
+ : getIsFirstRightPinnedColumn(column)
213
+ ? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
214
+ : undefined,
215
+ left:
216
+ column.getIsPinned() === 'left'
217
+ ? `${column.getStart('left')}px`
218
+ : undefined,
219
+ opacity:
220
+ table.getState().draggingColumn?.id === column.id ||
221
+ table.getState().hoveredColumn?.id === column.id
222
+ ? 0.5
223
+ : 1,
224
+ position:
225
+ column.getIsPinned() && column.columnDef.columnDefType !== 'group'
226
+ ? 'sticky'
227
+ : undefined,
228
+ right:
229
+ column.getIsPinned() === 'right'
230
+ ? `${getTotalRight(table, column)}px`
231
+ : undefined,
232
+ transition: `all ${column.getIsResizing() ? 0 : '0.2s'} ease-in-out`,
233
+ ...(tableCellProps?.sx instanceof Function
234
+ ? tableCellProps.sx(theme)
235
+ : (tableCellProps?.sx as any)),
236
+ maxWidth: `min(${column.getSize()}px, fit-content)`,
237
+ minWidth: `max(${column.getSize()}px, ${column.columnDef.minSize ?? 30}px)`,
238
+ width: header?.getSize() ?? column.getSize(),
239
+ });
@@ -1,5 +1,6 @@
1
1
  import React, { FC } from 'react';
2
- import { alpha, TableCell } from '@mui/material';
2
+ import { TableCell } from '@mui/material';
3
+ import { getCommonCellStyles } from '../column.utils';
3
4
  import type { MRT_Header, MRT_TableInstance } from '..';
4
5
 
5
6
  interface Props {
@@ -10,7 +11,7 @@ interface Props {
10
11
  export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
11
12
  const {
12
13
  getState,
13
- options: { muiTableFooterCellProps, enableColumnResizing },
14
+ options: { muiTableFooterCellProps },
14
15
  } = table;
15
16
  const { density } = getState();
16
17
  const { column } = footer;
@@ -39,26 +40,15 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
39
40
  variant="head"
40
41
  {...tableCellProps}
41
42
  sx={(theme) => ({
42
- backgroundColor: theme.palette.background.default,
43
- backgroundImage: `linear-gradient(${alpha(
44
- theme.palette.common.white,
45
- 0.05,
46
- )},${alpha(theme.palette.common.white, 0.05)})`,
47
43
  fontWeight: 'bold',
48
- maxWidth: `${column.getSize()}px`,
49
- minWidth: `${column.getSize()}px`,
50
44
  p:
51
45
  density === 'compact'
52
46
  ? '0.5rem'
53
47
  : density === 'comfortable'
54
48
  ? '1rem'
55
49
  : '1.5rem',
56
- transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
57
- width: column.getSize(),
58
- verticalAlign: 'text-top',
59
- ...(tableCellProps?.sx instanceof Function
60
- ? tableCellProps.sx(theme)
61
- : (tableCellProps?.sx as any)),
50
+ verticalAlign: 'top',
51
+ ...getCommonCellStyles({ column, table, theme, tableCellProps }),
62
52
  })}
63
53
  >
64
54
  <>
@@ -1,11 +1,12 @@
1
1
  import React, { DragEvent, FC, ReactNode } from 'react';
2
- import { Box, TableCell, Theme, alpha, lighten, useTheme } from '@mui/material';
2
+ import { Box, TableCell, Theme, useTheme } from '@mui/material';
3
3
  import { MRT_TableHeadCellColumnActionsButton } from './MRT_TableHeadCellColumnActionsButton';
4
4
  import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
5
5
  import { MRT_TableHeadCellFilterLabel } from './MRT_TableHeadCellFilterLabel';
6
6
  import { MRT_TableHeadCellGrabHandle } from './MRT_TableHeadCellGrabHandle';
7
7
  import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
8
8
  import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
9
+ import { getCommonCellStyles } from '../column.utils';
9
10
  import type { MRT_Header, MRT_TableInstance } from '..';
10
11
 
11
12
  interface Props {
@@ -21,7 +22,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
21
22
  enableColumnActions,
22
23
  enableColumnDragging,
23
24
  enableColumnOrdering,
24
- enableColumnResizing,
25
25
  enableGrouping,
26
26
  enableMultiSort,
27
27
  muiTableHeadCellProps,
@@ -54,23 +54,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
54
54
  ...mcTableHeadCellProps,
55
55
  };
56
56
 
57
- const getIsLastLeftPinnedColumn = () => {
58
- return (
59
- column.getIsPinned() === 'left' &&
60
- table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
61
- );
62
- };
63
-
64
- const getIsFirstRightPinnedColumn = () => {
65
- return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
66
- };
67
-
68
- const getTotalRight = () => {
69
- return (
70
- (table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160
71
- );
72
- };
73
-
74
57
  const handleDragEnter = (_e: DragEvent) => {
75
58
  if (enableGrouping && hoveredColumn?.id === 'drop-zone') {
76
59
  setHoveredColumn(null);
@@ -115,26 +98,8 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
115
98
  ref={tableHeadCellRef}
116
99
  {...tableCellProps}
117
100
  sx={(theme: Theme) => ({
118
- backgroundColor:
119
- column.getIsPinned() && columnDefType !== 'group'
120
- ? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
121
- : 'inherit',
122
- backgroundImage: 'inherit',
123
- boxShadow: getIsLastLeftPinnedColumn()
124
- ? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
125
- : getIsFirstRightPinnedColumn()
126
- ? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
127
- : undefined,
128
101
  fontWeight: 'bold',
129
- left:
130
- column.getIsPinned() === 'left'
131
- ? `${column.getStart('left')}px`
132
- : undefined,
133
102
  overflow: 'visible',
134
- opacity:
135
- draggingColumn?.id === column.id || hoveredColumn?.id === column.id
136
- ? 0.5
137
- : 1,
138
103
  p:
139
104
  density === 'compact'
140
105
  ? '0.5rem'
@@ -151,19 +116,12 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
151
116
  : showColumnFilters || density === 'compact'
152
117
  ? '0.4rem'
153
118
  : '0.6rem',
154
- position:
155
- column.getIsPinned() && columnDefType !== 'group'
156
- ? 'sticky'
157
- : undefined,
158
119
  pt:
159
120
  columnDefType === 'group' || density === 'compact'
160
121
  ? '0.25rem'
161
122
  : density === 'comfortable'
162
123
  ? '.75rem'
163
124
  : '1.25rem',
164
- right:
165
- column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
166
- transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
167
125
  userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined,
168
126
  verticalAlign: 'top',
169
127
  zIndex:
@@ -172,13 +130,14 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
172
130
  : column.getIsPinned() && columnDefType !== 'group'
173
131
  ? 2
174
132
  : 1,
175
- ...(tableCellProps?.sx instanceof Function
176
- ? tableCellProps.sx(theme)
177
- : (tableCellProps?.sx as any)),
133
+ ...getCommonCellStyles({
134
+ column,
135
+ header,
136
+ table,
137
+ tableCellProps,
138
+ theme,
139
+ }),
178
140
  ...draggingBorders,
179
- maxWidth: `min(${column.getSize()}px, fit-content)`,
180
- minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
181
- width: header.getSize(),
182
141
  })}
183
142
  >
184
143
  {header.isPlaceholder ? null : (
@@ -62,14 +62,17 @@ export const MRT_BottomToolbar: FC<Props> = ({ table }) => {
62
62
  >
63
63
  <MRT_LinearProgressBar isTopToolbar={false} table={table} />
64
64
  {positionToolbarAlertBanner === 'bottom' && (
65
- <MRT_ToolbarAlertBanner table={table} />
65
+ <MRT_ToolbarAlertBanner
66
+ stackAlertBanner={stackAlertBanner}
67
+ table={table}
68
+ />
66
69
  )}
67
70
  {['both', 'bottom'].includes(positionToolbarDropZone ?? '') && (
68
71
  <MRT_ToolbarDropZone table={table} />
69
72
  )}
70
73
  <Box
71
74
  sx={{
72
- alignItems: 'flex-start',
75
+ alignItems: 'center',
73
76
  boxSizing: 'border-box',
74
77
  display: 'flex',
75
78
  justifyContent: 'space-between',
@@ -3,7 +3,7 @@ import { Alert, AlertTitle, Box, Chip, Collapse } from '@mui/material';
3
3
  import { MRT_TableInstance } from '..';
4
4
 
5
5
  interface Props {
6
- stackAlertBanner?: boolean;
6
+ stackAlertBanner: boolean;
7
7
  table: MRT_TableInstance;
8
8
  }
9
9
 
@@ -19,6 +19,7 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
19
19
  localization,
20
20
  muiToolbarAlertBannerProps,
21
21
  muiToolbarAlertBannerChipProps,
22
+ positionToolbarAlertBanner,
22
23
  },
23
24
  } = table;
24
25
  const { grouping, showAlertBanner } = getState();
@@ -78,6 +79,11 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
78
79
  left: 0,
79
80
  p: 0,
80
81
  position: 'relative',
82
+ mb: stackAlertBanner
83
+ ? 0
84
+ : positionToolbarAlertBanner === 'bottom'
85
+ ? '-1rem'
86
+ : undefined,
81
87
  right: 0,
82
88
  top: 0,
83
89
  width: '100%',