material-react-table 0.8.0-alpha.2 → 0.8.2

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.
Files changed (46) hide show
  1. package/README.md +2 -2
  2. package/dist/MaterialReactTable.d.ts +5 -2
  3. package/dist/head/MRT_DraggableTableHeadCell.d.ts +8 -0
  4. package/dist/head/MRT_TableHeadCell.d.ts +5 -1
  5. package/dist/head/MRT_TableHeadCellFilterContainer.d.ts +8 -0
  6. package/dist/head/MRT_TableHeadCellFilterLabel.d.ts +8 -0
  7. package/dist/head/MRT_TableHeadCellGrabHandle.d.ts +9 -0
  8. package/dist/head/MRT_TableHeadCellResizeHandle.d.ts +8 -0
  9. package/dist/head/MRT_TableHeadCellSortLabel.d.ts +8 -0
  10. package/dist/icons.d.ts +1 -0
  11. package/dist/inputs/MRT_FilterRangeFields.d.ts +2 -2
  12. package/dist/localization.d.ts +1 -0
  13. package/dist/material-react-table.cjs.development.js +498 -294
  14. package/dist/material-react-table.cjs.development.js.map +1 -1
  15. package/dist/material-react-table.cjs.production.min.js +1 -1
  16. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  17. package/dist/material-react-table.esm.js +500 -296
  18. package/dist/material-react-table.esm.js.map +1 -1
  19. package/dist/table/MRT_TableContainer.d.ts +1 -1
  20. package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -0
  21. package/dist/toolbar/MRT_ToolbarTop.d.ts +2 -0
  22. package/dist/utils.d.ts +1 -1
  23. package/package.json +9 -6
  24. package/src/MaterialReactTable.tsx +10 -0
  25. package/src/body/MRT_TableBodyCell.tsx +7 -4
  26. package/src/buttons/MRT_CopyButton.tsx +2 -1
  27. package/src/buttons/MRT_ExpandAllButton.tsx +3 -0
  28. package/src/footer/MRT_TableFooterCell.tsx +1 -0
  29. package/src/head/MRT_DraggableTableHeadCell.tsx +52 -0
  30. package/src/head/MRT_TableHeadCell.tsx +66 -155
  31. package/src/head/MRT_TableHeadCellFilterContainer.tsx +32 -0
  32. package/src/head/MRT_TableHeadCellFilterLabel.tsx +82 -0
  33. package/src/head/MRT_TableHeadCellGrabHandle.tsx +52 -0
  34. package/src/head/MRT_TableHeadCellResizeHandle.tsx +52 -0
  35. package/src/head/MRT_TableHeadCellSortLabel.tsx +45 -0
  36. package/src/head/MRT_TableHeadRow.tsx +17 -8
  37. package/src/icons.ts +3 -0
  38. package/src/inputs/MRT_FilterRangeFields.tsx +1 -3
  39. package/src/localization.ts +2 -0
  40. package/src/table/MRT_TableContainer.tsx +1 -1
  41. package/src/table/MRT_TablePaper.tsx +26 -22
  42. package/src/table/MRT_TableRoot.tsx +8 -0
  43. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +11 -27
  44. package/src/toolbar/MRT_ToolbarBottom.tsx +23 -5
  45. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +30 -29
  46. package/src/toolbar/MRT_ToolbarTop.tsx +21 -20
@@ -1,5 +1,5 @@
1
1
  import { FC } from 'react';
2
- import { MRT_TableInstance } from '..';
2
+ import type { MRT_TableInstance } from '..';
3
3
  interface Props {
4
4
  tableInstance: MRT_TableInstance;
5
5
  }
@@ -1,6 +1,7 @@
1
1
  import { FC } from 'react';
2
2
  import { MRT_TableInstance } from '..';
3
3
  interface Props {
4
+ stackAlertBanner?: boolean;
4
5
  tableInstance: MRT_TableInstance;
5
6
  }
6
7
  export declare const MRT_ToolbarAlertBanner: FC<Props>;
@@ -7,6 +7,8 @@ export declare const commonToolbarStyles: ({ theme }: {
7
7
  backgroundColor: string;
8
8
  backgroundImage: string;
9
9
  display: string;
10
+ minHeight: string;
11
+ overflow: string;
10
12
  p: string;
11
13
  transition: string;
12
14
  width: string;
package/dist/utils.d.ts CHANGED
@@ -7,6 +7,6 @@ export declare const createGroup: <D extends Record<string, any> = {}>(table: Ta
7
7
  export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
8
8
  [key: string]: MRT_FilterFn<{}>;
9
9
  }) => ColumnDef<D>;
10
- export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregatedCell" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
10
+ export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregatedCell" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableColumnOrdering" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
11
11
  header?: string | undefined;
12
12
  }) => ColumnDef<D>;
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
- "version": "0.8.0-alpha.2",
2
+ "version": "0.8.2",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
- "description": "A fully featured Material UI implementation of react-table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
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.",
6
6
  "author": "Kevin Vandy",
7
7
  "keywords": [
8
8
  "react-table",
9
9
  "material-ui",
10
- "material-table"
10
+ "material-table",
11
+ "tanstack table"
11
12
  ],
12
13
  "repository": {
13
14
  "type": "git",
@@ -47,11 +48,11 @@
47
48
  "size-limit": [
48
49
  {
49
50
  "path": "dist/material-react-table.cjs.production.min.js",
50
- "limit": "40 KB"
51
+ "limit": "50 KB"
51
52
  },
52
53
  {
53
54
  "path": "dist/material-react-table.esm.js",
54
- "limit": "40 KB"
55
+ "limit": "50 KB"
55
56
  }
56
57
  ],
57
58
  "devDependencies": {
@@ -94,6 +95,8 @@
94
95
  },
95
96
  "dependencies": {
96
97
  "@tanstack/match-sorter-utils": "^8.0.0-alpha.83",
97
- "@tanstack/react-table": "^8.0.0-beta.2"
98
+ "@tanstack/react-table": "^8.0.0-alpha.89",
99
+ "react-dnd": "^16.0.1",
100
+ "react-dnd-html5-backend": "^16.0.1"
98
101
  }
99
102
  }
@@ -80,6 +80,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
80
80
  >,
81
81
  | 'getAllColumns'
82
82
  | 'getAllLeafColumns'
83
+ | 'getColumn'
83
84
  | 'getExpandedRowModel'
84
85
  | 'getPaginationRowModel'
85
86
  | 'getPrePaginationRowModel'
@@ -90,6 +91,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
90
91
  > & {
91
92
  getAllColumns: () => MRT_Column<D>[];
92
93
  getAllLeafColumns: () => MRT_Column<D>[];
94
+ getColumn: (columnId: string) => MRT_Column<D>;
93
95
  getExpandedRowModel: () => MRT_RowModel<D>;
94
96
  getPaginationRowModel: () => MRT_RowModel<D>;
95
97
  getPrePaginationRowModel: () => MRT_RowModel<D>;
@@ -176,6 +178,7 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
176
178
  columns?: MRT_ColumnDef<D>[];
177
179
  enableClickToCopy?: boolean;
178
180
  enableColumnActions?: boolean;
181
+ enableColumnOrdering?: boolean;
179
182
  enableEditing?: boolean;
180
183
  enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[];
181
184
  filterFn?: MRT_FilterFn;
@@ -330,6 +333,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
330
333
  editingMode?: 'table' | 'row' | 'cell';
331
334
  enableClickToCopy?: boolean;
332
335
  enableColumnActions?: boolean;
336
+ enableColumnOrdering?: boolean;
333
337
  enableDensePaddingToggle?: boolean;
334
338
  enableEditing?: boolean;
335
339
  enableExpandAll?: boolean;
@@ -757,15 +761,18 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
757
761
  export default <D extends Record<string, any> = {}>({
758
762
  autoResetExpanded = false,
759
763
  columnResizeMode = 'onEnd',
764
+ defaultColumn = { minSize: 50, maxSize: 1000, size: 150 },
760
765
  editingMode = 'row',
761
766
  enableColumnActions = true,
762
767
  enableColumnFilters = true,
768
+ enableColumnOrdering = false,
763
769
  enableColumnResizing = false,
764
770
  enableDensePaddingToggle = true,
765
771
  enableExpandAll = true,
766
772
  enableFilters = true,
767
773
  enableFullScreenToggle = true,
768
774
  enableGlobalFilter = true,
775
+ enableGrouping = false,
769
776
  enableHiding = true,
770
777
  enableMultiRowSelection = true,
771
778
  enablePagination = true,
@@ -790,15 +797,18 @@ export default <D extends Record<string, any> = {}>({
790
797
  <MRT_TableRoot
791
798
  autoResetExpanded={autoResetExpanded}
792
799
  columnResizeMode={columnResizeMode}
800
+ defaultColumn={defaultColumn}
793
801
  editingMode={editingMode}
794
802
  enableColumnActions={enableColumnActions}
795
803
  enableColumnFilters={enableColumnFilters}
804
+ enableColumnOrdering={enableColumnOrdering}
796
805
  enableColumnResizing={enableColumnResizing}
797
806
  enableDensePaddingToggle={enableDensePaddingToggle}
798
807
  enableExpandAll={enableExpandAll}
799
808
  enableFilters={enableFilters}
800
809
  enableFullScreenToggle={enableFullScreenToggle}
801
810
  enableGlobalFilter={enableGlobalFilter}
811
+ enableGrouping={enableGrouping}
802
812
  enableHiding={enableHiding}
803
813
  enableMultiRowSelection={enableMultiRowSelection}
804
814
  enablePagination={enablePagination}
@@ -132,8 +132,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
132
132
  column.getIsPinned() === 'left'
133
133
  ? `${column.getStart('left')}px`
134
134
  : undefined,
135
- maxWidth: `min(${column.getSize()}px, fit-content)`,
136
- minWidth: `max${column.getSize()}px, ${column.minSize}px`,
137
135
  p: isDensePadding
138
136
  ? column.columnDefType === 'display'
139
137
  ? '0 0.5rem'
@@ -150,7 +148,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
150
148
  column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
151
149
  transition: 'all 0.2s ease-in-out',
152
150
  whiteSpace: isDensePadding ? 'nowrap' : 'normal',
153
- width: column.getSize(),
154
151
  zIndex: column.getIsPinned() ? 1 : undefined,
155
152
  '&:hover': {
156
153
  backgroundColor: enableHover
@@ -161,6 +158,11 @@ export const MRT_TableBodyCell: FC<Props> = ({
161
158
  },
162
159
  ...(tableCellProps?.sx as any),
163
160
  })}
161
+ style={{
162
+ maxWidth: `min(${column.getSize()}px, fit-content)`,
163
+ minWidth: `max(${column.getSize()}px, ${column.minSize ?? 30}px)`,
164
+ width: column.getSize(),
165
+ }}
164
166
  >
165
167
  <>
166
168
  {isLoading || showSkeletons ? (
@@ -192,7 +194,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
192
194
  </>
193
195
  ) : (
194
196
  <>
195
- {cell.column.columnDef?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
197
+ {cell.column.columnDef?.Cell?.({ cell, tableInstance }) ??
198
+ cell.renderCell()}
196
199
  {row.getIsGrouped() && <> ({row.subRows?.length ?? ''})</>}
197
200
  </>
198
201
  )}
@@ -52,6 +52,8 @@ export const MRT_CopyButton: FC<Props> = ({
52
52
  aria-label={localization.clickToCopy}
53
53
  onClick={() => handleCopy(cell.getValue())}
54
54
  size="small"
55
+ type="button"
56
+ variant="text"
55
57
  {...buttonProps}
56
58
  sx={{
57
59
  backgroundColor: 'transparent',
@@ -67,7 +69,6 @@ export const MRT_CopyButton: FC<Props> = ({
67
69
  textTransform: 'inherit',
68
70
  ...buttonProps?.sx,
69
71
  }}
70
- variant="text"
71
72
  >
72
73
  {children}
73
74
  </Button>
@@ -10,10 +10,12 @@ export const MRT_ExpandAllButton: FC<Props> = ({ tableInstance }) => {
10
10
  const {
11
11
  getIsAllRowsExpanded,
12
12
  getIsSomeRowsExpanded,
13
+ getCanSomeRowsExpand,
13
14
  getState,
14
15
  options: {
15
16
  icons: { DoubleArrowDownIcon },
16
17
  localization,
18
+ renderDetailPanel,
17
19
  },
18
20
  toggleAllRowsExpanded,
19
21
  } = tableInstance;
@@ -29,6 +31,7 @@ export const MRT_ExpandAllButton: FC<Props> = ({ tableInstance }) => {
29
31
  >
30
32
  <IconButton
31
33
  aria-label={localization.expandAll}
34
+ disabled={!getCanSomeRowsExpand() && !renderDetailPanel}
32
35
  onClick={() => toggleAllRowsExpanded(!getIsAllRowsExpanded())}
33
36
  sx={{
34
37
  height: isDensePadding ? '1.75rem' : '2.25rem',
@@ -61,6 +61,7 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
61
61
  footer,
62
62
  tableInstance,
63
63
  }) ??
64
+ column.columnDef.footer ??
64
65
  footer.renderFooter() ??
65
66
  null}
66
67
  </>
@@ -0,0 +1,52 @@
1
+ import React, { FC } from 'react';
2
+ import { useDrag, useDrop } from 'react-dnd';
3
+ import { MRT_TableHeadCell } from './MRT_TableHeadCell';
4
+ import type { MRT_Header, MRT_TableInstance } from '..';
5
+
6
+ interface Props {
7
+ header: MRT_Header;
8
+ tableInstance: MRT_TableInstance;
9
+ }
10
+
11
+ export const MRT_DraggableTableHeadCell: FC<Props> = ({
12
+ header,
13
+ tableInstance,
14
+ }) => {
15
+ const {
16
+ getState,
17
+ options: {},
18
+ setColumnOrder,
19
+ } = tableInstance;
20
+
21
+ const { columnOrder } = getState();
22
+
23
+ const reorder = (item: MRT_Header, newIndex: number) => {
24
+ const { index: currentIndex } = item;
25
+ columnOrder.splice(newIndex, 0, columnOrder.splice(currentIndex, 1)[0]);
26
+ setColumnOrder([...columnOrder]);
27
+ };
28
+
29
+ const [, drop] = useDrop({
30
+ accept: 'header',
31
+ drop: (item: MRT_Header) => reorder(item, header.index),
32
+ });
33
+
34
+ const [{ isDragging }, drag, preview] = useDrag({
35
+ collect: (monitor) => ({
36
+ isDragging: monitor.isDragging(),
37
+ }),
38
+ item: () => header,
39
+ type: 'header',
40
+ });
41
+
42
+ return (
43
+ <MRT_TableHeadCell
44
+ dragRef={drag}
45
+ dropRef={drop}
46
+ header={header}
47
+ isDragging={isDragging}
48
+ previewRef={preview}
49
+ tableInstance={tableInstance}
50
+ />
51
+ );
52
+ };
@@ -1,42 +1,43 @@
1
- import React, { FC, MouseEvent, ReactNode } from 'react';
2
- import {
3
- Box,
4
- Collapse,
5
- Divider,
6
- IconButton,
7
- TableCell,
8
- TableSortLabel,
9
- Theme,
10
- Tooltip,
11
- alpha,
12
- lighten,
13
- } from '@mui/material';
14
- import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
1
+ import React, { FC, ReactNode, Ref } from 'react';
2
+ import { Box, TableCell, Theme, alpha, lighten } from '@mui/material';
3
+ import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
4
+ import { MRT_TableHeadCellFilterLabel } from './MRT_TableHeadCellFilterLabel';
5
+ import { MRT_TableHeadCellGrabHandle } from './MRT_TableHeadCellGrabHandle';
6
+ import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
7
+ import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
15
8
  import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
16
9
  import type { MRT_Header, MRT_TableInstance } from '..';
17
- import MRT_FilterRangeFields from '../inputs/MRT_FilterRangeFields';
18
- import { MRT_FILTER_OPTION } from '../enums';
19
10
 
20
11
  interface Props {
12
+ dragRef?: Ref<HTMLButtonElement>;
13
+ dropRef?: Ref<HTMLDivElement>;
21
14
  header: MRT_Header;
15
+ isDragging?: boolean;
16
+ previewRef?: Ref<HTMLTableCellElement>;
22
17
  tableInstance: MRT_TableInstance;
23
18
  }
24
19
 
25
- export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
20
+ export const MRT_TableHeadCell: FC<Props> = ({
21
+ dragRef,
22
+ dropRef,
23
+ header,
24
+ isDragging,
25
+ previewRef,
26
+ tableInstance,
27
+ }) => {
26
28
  const {
27
29
  getState,
28
30
  options: {
29
31
  enableColumnActions,
30
32
  enableColumnFilters,
33
+ enableColumnOrdering,
31
34
  enableColumnResizing,
32
- icons: { FilterAltIcon, FilterAltOff },
33
- localization,
35
+ enableGrouping,
34
36
  muiTableHeadCellProps,
35
37
  },
36
- setShowFilters,
37
38
  } = tableInstance;
38
39
 
39
- const { currentFilterFns, isDensePadding, showFilters } = getState();
40
+ const { isDensePadding } = getState();
40
41
 
41
42
  const { column } = header;
42
43
 
@@ -55,45 +56,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
55
56
  ...mcTableHeadCellProps,
56
57
  };
57
58
 
58
- const sortTooltip = !!column.getIsSorted()
59
- ? column.getIsSorted() === 'desc'
60
- ? localization.sortedByColumnDesc.replace(
61
- '{column}',
62
- column.columnDef.header,
63
- )
64
- : localization.sortedByColumnAsc.replace(
65
- '{column}',
66
- column.columnDef.header,
67
- )
68
- : localization.unsorted;
69
-
70
- const filterFn = getState()?.currentFilterFns?.[header.id];
71
-
72
- const filterTooltip = !!column.getFilterValue()
73
- ? localization.filteringByColumn
74
- .replace('{column}', String(column.columnDef.header))
75
- .replace(
76
- '{filterType}',
77
- filterFn instanceof Function
78
- ? ''
79
- : // @ts-ignore
80
- localization[
81
- `filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
82
- ],
83
- )
84
- .replace(
85
- '{filterValue}',
86
- `"${
87
- Array.isArray(column.getFilterValue())
88
- ? (column.getFilterValue() as [string, string]).join(
89
- `" ${localization.and} "`,
90
- )
91
- : (column.getFilterValue() as string)
92
- }"`,
93
- )
94
- .replace('" "', '')
95
- : localization.showHideFilters;
96
-
97
59
  const headerElement = (column.columnDef?.Header?.({
98
60
  header,
99
61
  tableInstance,
@@ -124,6 +86,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
124
86
  align={column.columnDefType === 'group' ? 'center' : 'left'}
125
87
  colSpan={header.colSpan}
126
88
  {...tableCellProps}
89
+ ref={column.columnDefType === 'data' ? dropRef : undefined}
127
90
  sx={(theme: Theme) => ({
128
91
  backgroundColor:
129
92
  column.getIsPinned() && column.columnDefType !== 'group'
@@ -141,8 +104,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
141
104
  column.getIsPinned() === 'left'
142
105
  ? `${column.getStart('left')}px`
143
106
  : undefined,
144
- maxWidth: `min(${column.getSize()}px, fit-content)`,
145
- minWidth: `max(${column.getSize()}px, ${column.minSize}px)`,
146
107
  overflow: 'visible',
147
108
  p: isDensePadding
148
109
  ? column.columnDefType === 'display'
@@ -166,7 +127,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
166
127
  column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
167
128
  transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
168
129
  verticalAlign: 'text-top',
169
- width: header.getSize(),
170
130
  zIndex: column.getIsResizing()
171
131
  ? 3
172
132
  : column.getIsPinned() && column.columnDefType !== 'group'
@@ -174,16 +134,23 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
174
134
  : 1,
175
135
  ...(tableCellProps?.sx as any),
176
136
  })}
137
+ style={{
138
+ maxWidth: `min(${column.getSize()}px, fit-content)`,
139
+ minWidth: `max(${column.getSize()}px, ${column.minSize ?? 30}px)`,
140
+ width: header.getSize(),
141
+ }}
177
142
  >
178
143
  {header.isPlaceholder ? null : column.columnDefType === 'display' ? (
179
144
  headerElement
180
145
  ) : (
181
146
  <Box
147
+ ref={previewRef}
182
148
  sx={{
183
149
  alignItems: 'flex-start',
184
150
  display: 'flex',
185
151
  justifyContent:
186
152
  column.columnDefType === 'group' ? 'center' : 'space-between',
153
+ opacity: isDragging ? 0.5 : 1,
187
154
  width: '100%',
188
155
  }}
189
156
  >
@@ -205,109 +172,53 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
205
172
  >
206
173
  {headerElement}
207
174
  {column.columnDefType === 'data' && column.getCanSort() && (
208
- <Tooltip arrow placement="top" title={sortTooltip}>
209
- <TableSortLabel
210
- aria-label={sortTooltip}
211
- active={!!column.getIsSorted()}
212
- direction={
213
- column.getIsSorted()
214
- ? (column.getIsSorted() as 'asc' | 'desc')
215
- : undefined
216
- }
217
- />
218
- </Tooltip>
175
+ <MRT_TableHeadCellSortLabel
176
+ header={header}
177
+ tableInstance={tableInstance}
178
+ />
219
179
  )}
220
180
  {column.columnDefType === 'data' &&
221
181
  enableColumnFilters &&
222
- !!column.getCanFilter() && (
223
- <Tooltip arrow placement="top" title={filterTooltip}>
224
- <IconButton
225
- disableRipple
226
- onClick={(event: MouseEvent<HTMLButtonElement>) => {
227
- event.stopPropagation();
228
- setShowFilters(!showFilters);
229
- }}
230
- size="small"
231
- sx={{
232
- m: 0,
233
- opacity: !!column.getFilterValue() ? 0.8 : 0,
234
- p: '2px',
235
- transition: 'all 0.2s ease-in-out',
236
- '&:hover': {
237
- backgroundColor: 'transparent',
238
- opacity: 0.8,
239
- },
240
- }}
241
- >
242
- {showFilters && !column.getFilterValue() ? (
243
- <FilterAltOff />
244
- ) : (
245
- <FilterAltIcon />
246
- )}
247
- </IconButton>
248
- </Tooltip>
182
+ column.getCanFilter() && (
183
+ <MRT_TableHeadCellFilterLabel
184
+ header={header}
185
+ tableInstance={tableInstance}
186
+ />
187
+ )}
188
+ </Box>
189
+ <Box sx={{ whiteSpace: 'nowrap' }}>
190
+ {column.columnDefType === 'data' &&
191
+ ((enableColumnOrdering &&
192
+ column.enableColumnOrdering !== false) ||
193
+ (enableGrouping && column.enableGrouping !== false)) && (
194
+ <MRT_TableHeadCellGrabHandle
195
+ header={header}
196
+ ref={dragRef as Ref<HTMLButtonElement>}
197
+ tableInstance={tableInstance}
198
+ />
199
+ )}
200
+ {(enableColumnActions || column.enableColumnActions) &&
201
+ column.enableColumnActions !== false &&
202
+ column.columnDefType !== 'group' && (
203
+ <MRT_ToggleColumnActionMenuButton
204
+ header={header}
205
+ tableInstance={tableInstance}
206
+ />
249
207
  )}
250
208
  </Box>
251
- {(enableColumnActions || column.enableColumnActions) &&
252
- column.enableColumnActions !== false &&
253
- column.columnDefType !== 'group' && (
254
- <MRT_ToggleColumnActionMenuButton
255
- header={header}
256
- tableInstance={tableInstance}
257
- />
258
- )}
259
209
  {column.getCanResize() && (
260
- <Divider
261
- flexItem
262
- orientation="vertical"
263
- onDoubleClick={() => column.resetSize()}
264
- sx={(theme: Theme) => ({
265
- borderRadius: '2px',
266
- borderRightWidth: '2px',
267
- cursor: 'col-resize',
268
- height:
269
- showFilters && column.columnDefType === 'data'
270
- ? '4rem'
271
- : '2rem',
272
- opacity: 0.8,
273
- position: 'absolute',
274
- right: '1px',
275
- touchAction: 'none',
276
- transition: 'all 0.2s ease-in-out',
277
- userSelect: 'none',
278
- zIndex: 2000,
279
- '&:active': {
280
- backgroundColor: theme.palette.info.main,
281
- opacity: 1,
282
- },
283
- })}
284
- {...{
285
- onMouseDown: header.getResizeHandler,
286
- onTouchStart: header.getResizeHandler,
287
- }}
288
- style={{
289
- transform: column.getIsResizing()
290
- ? `translateX(${getState().columnSizingInfo.deltaOffset}px)`
291
- : 'none',
292
- }}
210
+ <MRT_TableHeadCellResizeHandle
211
+ header={header}
212
+ tableInstance={tableInstance}
293
213
  />
294
214
  )}
295
215
  </Box>
296
216
  )}
297
217
  {column.columnDefType === 'data' && column.getCanFilter() && (
298
- <Collapse in={showFilters} mountOnEnter unmountOnExit>
299
- {currentFilterFns[column.id] === MRT_FILTER_OPTION.BETWEEN ? (
300
- <MRT_FilterRangeFields
301
- header={header}
302
- tableInstance={tableInstance}
303
- />
304
- ) : (
305
- <MRT_FilterTextField
306
- header={header}
307
- tableInstance={tableInstance}
308
- />
309
- )}
310
- </Collapse>
218
+ <MRT_TableHeadCellFilterContainer
219
+ header={header}
220
+ tableInstance={tableInstance}
221
+ />
311
222
  )}
312
223
  </TableCell>
313
224
  );
@@ -0,0 +1,32 @@
1
+ import React, { FC } from 'react';
2
+ import { Collapse } from '@mui/material';
3
+ import { MRT_FilterRangeFields } from '../inputs/MRT_FilterRangeFields';
4
+ import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
5
+ import { MRT_FILTER_OPTION } from '../enums';
6
+ import { MRT_Header, MRT_TableInstance } from '..';
7
+
8
+ interface Props {
9
+ header: MRT_Header;
10
+ tableInstance: MRT_TableInstance;
11
+ }
12
+
13
+ export const MRT_TableHeadCellFilterContainer: FC<Props> = ({
14
+ header,
15
+ tableInstance,
16
+ }) => {
17
+ const { getState } = tableInstance;
18
+
19
+ const { currentFilterFns, showFilters } = getState();
20
+
21
+ const { column } = header;
22
+
23
+ return (
24
+ <Collapse in={showFilters} mountOnEnter unmountOnExit>
25
+ {currentFilterFns[column.id] === MRT_FILTER_OPTION.BETWEEN ? (
26
+ <MRT_FilterRangeFields header={header} tableInstance={tableInstance} />
27
+ ) : (
28
+ <MRT_FilterTextField header={header} tableInstance={tableInstance} />
29
+ )}
30
+ </Collapse>
31
+ );
32
+ };