material-react-table 0.7.4 → 0.8.0-alpha.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.
Files changed (57) hide show
  1. package/dist/MaterialReactTable.d.ts +25 -31
  2. package/dist/body/MRT_TableBody.d.ts +0 -1
  3. package/dist/body/MRT_TableBodyCell.d.ts +1 -0
  4. package/dist/body/MRT_TableBodyRow.d.ts +0 -1
  5. package/dist/buttons/MRT_ColumnPinningButtons.d.ts +8 -0
  6. package/dist/buttons/MRT_CopyButton.d.ts +2 -1
  7. package/dist/enums.d.ts +3 -3
  8. package/dist/filtersFNs.d.ts +31 -30
  9. package/dist/footer/MRT_TableFooter.d.ts +0 -1
  10. package/dist/head/MRT_TableHead.d.ts +0 -1
  11. package/dist/inputs/MRT_FilterRangeFields.d.ts +8 -0
  12. package/dist/inputs/MRT_FilterTextField.d.ts +1 -0
  13. package/dist/localization.d.ts +7 -2
  14. package/dist/material-react-table.cjs.development.js +489 -448
  15. package/dist/material-react-table.cjs.development.js.map +1 -1
  16. package/dist/material-react-table.cjs.production.min.js +1 -1
  17. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  18. package/dist/material-react-table.esm.js +492 -451
  19. package/dist/material-react-table.esm.js.map +1 -1
  20. package/dist/menus/{MRT_FilterTypeMenu.d.ts → MRT_FilterOptionMenu.d.ts} +1 -1
  21. package/dist/table/MRT_Table.d.ts +0 -1
  22. package/dist/toolbar/MRT_ToolbarTop.d.ts +1 -0
  23. package/dist/utils.d.ts +6 -6
  24. package/package.json +24 -24
  25. package/src/MaterialReactTable.tsx +39 -41
  26. package/src/body/MRT_TableBody.tsx +3 -11
  27. package/src/body/MRT_TableBodyCell.tsx +102 -51
  28. package/src/body/MRT_TableBodyRow.tsx +21 -30
  29. package/src/buttons/MRT_ColumnPinningButtons.tsx +57 -0
  30. package/src/buttons/MRT_CopyButton.tsx +3 -2
  31. package/src/buttons/MRT_EditActionButtons.tsx +1 -2
  32. package/src/buttons/MRT_ExpandAllButton.tsx +1 -2
  33. package/src/enums.ts +3 -3
  34. package/src/filtersFNs.ts +71 -81
  35. package/src/footer/MRT_TableFooter.tsx +6 -16
  36. package/src/footer/MRT_TableFooterCell.tsx +5 -7
  37. package/src/footer/MRT_TableFooterRow.tsx +5 -8
  38. package/src/head/MRT_TableHead.tsx +5 -16
  39. package/src/head/MRT_TableHeadCell.tsx +101 -44
  40. package/src/head/MRT_TableHeadRow.tsx +8 -15
  41. package/src/inputs/MRT_EditCellTextField.tsx +2 -2
  42. package/src/inputs/MRT_FilterRangeFields.tsx +41 -0
  43. package/src/inputs/MRT_FilterTextField.tsx +84 -52
  44. package/src/inputs/MRT_SearchTextField.tsx +2 -2
  45. package/src/inputs/MRT_SelectCheckbox.tsx +16 -17
  46. package/src/localization.ts +15 -5
  47. package/src/menus/MRT_ColumnActionMenu.tsx +9 -8
  48. package/src/menus/{MRT_FilterTypeMenu.tsx → MRT_FilterOptionMenu.tsx} +54 -49
  49. package/src/menus/MRT_ShowHideColumnsMenu.tsx +25 -11
  50. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +15 -5
  51. package/src/table/MRT_Table.tsx +8 -19
  52. package/src/table/MRT_TableContainer.tsx +8 -69
  53. package/src/table/MRT_TableRoot.tsx +70 -70
  54. package/src/toolbar/MRT_LinearProgressBar.tsx +5 -2
  55. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -2
  56. package/src/toolbar/MRT_ToolbarTop.tsx +4 -6
  57. package/src/utils.ts +10 -10
@@ -7,5 +7,5 @@ interface Props {
7
7
  setAnchorEl: (anchorEl: HTMLElement | null) => void;
8
8
  tableInstance: MRT_TableInstance;
9
9
  }
10
- export declare const MRT_FilterTypeMenu: FC<Props>;
10
+ export declare const MRT_FilterOptionMenu: FC<Props>;
11
11
  export {};
@@ -1,7 +1,6 @@
1
1
  import { FC } from 'react';
2
2
  import { MRT_TableInstance } from '..';
3
3
  interface Props {
4
- pinned: 'left' | 'center' | 'right' | 'none';
5
4
  tableInstance: MRT_TableInstance;
6
5
  }
7
6
  export declare const MRT_Table: FC<Props>;
@@ -8,6 +8,7 @@ export declare const commonToolbarStyles: ({ theme }: {
8
8
  backgroundImage: string;
9
9
  display: string;
10
10
  p: string;
11
+ transition: string;
11
12
  width: string;
12
13
  zIndex: number;
13
14
  };
package/dist/utils.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { ColumnDef, Table } from '@tanstack/react-table';
2
- import { MRT_ColumnDef, MRT_FilterType } from '.';
2
+ import { MRT_ColumnDef, MRT_FilterFn } from '.';
3
3
  export declare const getAllLeafColumnDefs: (columns: MRT_ColumnDef[]) => MRT_ColumnDef[];
4
- export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterTypes: {
5
- [key: string]: MRT_FilterType;
4
+ export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
5
+ [key: string]: MRT_FilterFn<{}>;
6
6
  }) => ColumnDef<D>;
7
- export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterTypes: {
8
- [key: string]: MRT_FilterType;
7
+ export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
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" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "defaultCanHide" | "defaultIsVisible" | "enablePinning" | "defaultCanPin" | "filterFn" | "enableAllFilters" | "enableColumnFilter" | "enableGlobalFilter" | "defaultCanFilter" | "defaultCanColumnFilter" | "defaultCanGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "defaultCanSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregateValue" | "aggregatedCell" | "enableGrouping" | "defaultCanGroup" | "enableResizing" | "defaultCanResize" | "width" | "minWidth" | "maxWidth" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterTypes" | "filter" | "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" | "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,5 +1,5 @@
1
1
  {
2
- "version": "0.7.4",
2
+ "version": "0.8.0-alpha.1",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
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.",
@@ -55,39 +55,39 @@
55
55
  }
56
56
  ],
57
57
  "devDependencies": {
58
- "@babel/core": "^7.17.9",
58
+ "@babel/core": "^7.18.2",
59
59
  "@emotion/react": "^11.9.0",
60
60
  "@emotion/styled": "^11.8.1",
61
61
  "@etchteam/storybook-addon-status": "^4.2.1",
62
- "@faker-js/faker": "^6.2.0",
63
- "@mui/icons-material": "^5.6.2",
64
- "@mui/material": "^5.6.2",
62
+ "@faker-js/faker": "^7.1.0",
63
+ "@mui/icons-material": "^5.8.0",
64
+ "@mui/material": "^5.8.1",
65
65
  "@size-limit/preset-small-lib": "^7.0.8",
66
- "@storybook/addon-a11y": "^6.4.22",
67
- "@storybook/addon-actions": "^6.4.22",
66
+ "@storybook/addon-a11y": "^6.5.5",
67
+ "@storybook/addon-actions": "^6.5.5",
68
68
  "@storybook/addon-console": "^1.2.3",
69
- "@storybook/addon-essentials": "^6.4.22",
69
+ "@storybook/addon-essentials": "^6.5.5",
70
70
  "@storybook/addon-info": "^5.3.21",
71
- "@storybook/addon-links": "^6.4.22",
72
- "@storybook/addon-storysource": "^6.4.22",
73
- "@storybook/addons": "^6.4.22",
74
- "@storybook/react": "^6.4.22",
75
- "@types/react": "^17.0.41",
76
- "@types/react-dom": "^17.0.14",
71
+ "@storybook/addon-links": "^6.5.5",
72
+ "@storybook/addon-storysource": "^6.5.5",
73
+ "@storybook/addons": "^6.5.5",
74
+ "@storybook/react": "^6.5.5",
75
+ "@types/react": "^18.0.9",
76
+ "@types/react-dom": "^18.0.5",
77
77
  "babel-loader": "^8.2.5",
78
- "eslint": "^8.14.0",
79
- "eslint-plugin-react-hooks": "^4.4.0",
80
- "husky": "^7.0.4",
78
+ "eslint": "^8.16.0",
79
+ "eslint-plugin-react-hooks": "^4.5.0",
80
+ "husky": "^8.0.1",
81
81
  "prettier": "^2.6.2",
82
- "react": "^17.0.2",
83
- "react-dom": "^17.0.2",
84
- "react-is": "^17.0.2",
82
+ "react": "^18.1.0",
83
+ "react-dom": "^18.1.0",
84
+ "react-is": "^18.1.0",
85
85
  "size-limit": "^7.0.8",
86
86
  "storybook-addon-paddings": "^4.3.0",
87
- "storybook-dark-mode": "^1.0.9",
87
+ "storybook-dark-mode": "^1.1.0",
88
88
  "tsdx": "^0.14.1",
89
89
  "tslib": "^2.4.0",
90
- "typescript": "^4.6.3"
90
+ "typescript": "^4.7.2"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "@emotion/react": ">=11",
@@ -97,7 +97,7 @@
97
97
  "react": ">=16.8"
98
98
  },
99
99
  "dependencies": {
100
- "@tanstack/react-table": "^8.0.0-alpha.45",
101
- "match-sorter": "^6.3.1"
100
+ "@tanstack/match-sorter-utils": "^8.0.0-alpha.83",
101
+ "@tanstack/react-table": "^8.0.0-alpha.87"
102
102
  }
103
103
  }
@@ -30,34 +30,37 @@ import {
30
30
  Cell,
31
31
  Column,
32
32
  ColumnDef,
33
- DefaultGenerics,
34
- FilterType,
33
+ FilterFn,
34
+ FilterFnOption,
35
35
  Header,
36
36
  HeaderGroup,
37
- Options,
38
37
  Overwrite,
39
38
  PaginationState,
39
+ ReactTableGenerics,
40
40
  Row,
41
+ TableGenerics,
41
42
  TableInstance,
42
43
  TableState,
44
+ UseTableInstanceOptions,
43
45
  VisibilityState,
44
46
  } from '@tanstack/react-table';
45
47
  import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
46
48
  import { MRT_Default_Icons, MRT_Icons } from './icons';
47
- import { MRT_FILTER_TYPE } from './enums';
49
+ import { MRT_FILTER_OPTION } from './enums';
48
50
  import { MRT_TableRoot } from './table/MRT_TableRoot';
49
51
 
50
52
  export type MRT_TableOptions<D extends Record<string, any> = {}> = Partial<
51
53
  Omit<
52
- Options<D>,
53
- 'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn'
54
+ UseTableInstanceOptions<ReactTableGenerics>,
55
+ 'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn' | 'filterFns'
54
56
  >
55
57
  > & {
56
58
  columns: MRT_ColumnDef<D>[];
57
59
  data: D[];
60
+ expandRowsFn?: (dataRow: D) => D[];
61
+ filterFns?: MRT_FILTER_OPTION | FilterFn<D> | string | number | symbol;
58
62
  initialState?: Partial<MRT_TableState<D>>;
59
63
  state?: Partial<MRT_TableState<D>>;
60
- expandRowsFn?: (dataRow: D) => D[];
61
64
  };
62
65
 
63
66
  export interface MRT_RowModel<D extends Record<string, any> = {}> {
@@ -69,7 +72,7 @@ export interface MRT_RowModel<D extends Record<string, any> = {}> {
69
72
  export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
70
73
  TableInstance<
71
74
  Overwrite<
72
- Partial<DefaultGenerics>,
75
+ Partial<TableGenerics>,
73
76
  {
74
77
  Row: D;
75
78
  }
@@ -96,17 +99,16 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
96
99
  options: MaterialReactTableProps<D> & {
97
100
  icons: MRT_Icons;
98
101
  idPrefix: string;
99
- filterTypes: { [key in MRT_FILTER_TYPE]: any };
100
102
  localization: MRT_Localization;
101
103
  };
102
- setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell<D> | null>>;
103
- setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
104
- setCurrentFilterTypes: Dispatch<
104
+ setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell | null>>;
105
+ setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row | null>>;
106
+ setCurrentFilterFns: Dispatch<
105
107
  SetStateAction<{
106
- [key: string]: MRT_FilterType;
108
+ [key: string]: MRT_FilterFn;
107
109
  }>
108
110
  >;
109
- setCurrentGlobalFilterType: Dispatch<SetStateAction<MRT_FILTER_TYPE>>;
111
+ setCurrentGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterFn<D>>>;
110
112
  setIsDensePadding: Dispatch<SetStateAction<boolean>>;
111
113
  setIsFullScreen: Dispatch<SetStateAction<boolean>>;
112
114
  setShowFilters: Dispatch<SetStateAction<boolean>>;
@@ -119,34 +121,33 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
119
121
  > & {
120
122
  currentEditingCell: MRT_Cell<D> | null;
121
123
  currentEditingRow: MRT_Row<D> | null;
122
- currentFilterTypes: Record<string, string | Function>;
123
- currentGlobalFilterType: Record<string, string | Function>;
124
+ currentFilterFns: Record<string, string | Function>;
125
+ currentGlobalFilterFn: Record<string, string | Function>;
124
126
  isDensePadding: boolean;
127
+ isLoading: boolean;
125
128
  isFullScreen: boolean;
129
+ pagination: Partial<PaginationState>;
126
130
  showFilters: boolean;
127
131
  showGlobalFilter: boolean;
128
- pagination: Partial<PaginationState>;
132
+ showProgressBars: boolean;
133
+ showSkeletons: boolean;
129
134
  };
130
135
 
131
136
  export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
132
137
  ColumnDef<D>,
133
- 'header' | 'footer' | 'columns'
138
+ 'header' | 'footer' | 'columns' | 'filterFn'
134
139
  > & {
135
140
  Edit?: ({
136
141
  cell,
137
142
  tableInstance,
138
- }: // onChange,
139
- {
143
+ }: {
140
144
  cell: MRT_Cell<D>;
141
145
  tableInstance: MRT_TableInstance<D>;
142
- // onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
143
146
  }) => ReactNode;
144
147
  Filter?: ({
145
- // onChange,
146
148
  header,
147
149
  tableInstance,
148
150
  }: {
149
- // onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
150
151
  header: MRT_Header<D>;
151
152
  tableInstance: MRT_TableInstance<D>;
152
153
  }) => ReactNode;
@@ -176,8 +177,8 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
176
177
  enableClickToCopy?: boolean;
177
178
  enableColumnActions?: boolean;
178
179
  enableEditing?: boolean;
179
- enabledColumnFilterTypes?: (MRT_FILTER_TYPE | string)[];
180
- filter?: MRT_FilterType | string | FilterType<D>;
180
+ enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[];
181
+ filterFn?: MRT_FilterFn;
181
182
  filterSelectOptions?: (string | { text: string; value: string })[];
182
183
  footer?: string;
183
184
  header: string;
@@ -297,18 +298,9 @@ export type MRT_HeaderGroup<D extends Record<string, any> = {}> = Omit<
297
298
 
298
299
  export type MRT_Row<D extends Record<string, any> = {}> = Omit<
299
300
  Row<D>,
300
- | 'getVisibleCells'
301
- | 'getAllCells'
302
- | 'subRows'
303
- | 'original'
304
- | 'getLeftVisibleCells'
305
- | 'getRightVisibleCells'
306
- | 'getCenterVisibleCells'
301
+ 'getVisibleCells' | 'getAllCells' | 'subRows' | 'original'
307
302
  > & {
308
303
  getAllCells: () => MRT_Cell<D>[];
309
- getCenterVisibleCells: () => MRT_Cell<D>[];
310
- getLeftVisibleCells: () => MRT_Cell<D>[];
311
- getRightVisibleCells: () => MRT_Cell<D>[];
312
304
  getVisibleCells: () => MRT_Cell<D>[];
313
305
  subRows?: MRT_Row<D>[];
314
306
  original: D;
@@ -322,7 +314,13 @@ export type MRT_Cell<D extends Record<string, any> = {}> = Omit<
322
314
  row: MRT_Row<D>;
323
315
  };
324
316
 
325
- export type MRT_FilterType = MRT_FILTER_TYPE | Function;
317
+ export type MRT_FilterFn<D extends Record<string, any> = {}> =
318
+ | FilterFn<TableGenerics>
319
+ | FilterFnOption<D>
320
+ | MRT_FILTER_OPTION
321
+ | number
322
+ | string
323
+ | symbol;
326
324
 
327
325
  export type MaterialReactTableProps<D extends Record<string, any> = {}> =
328
326
  MRT_TableOptions<D> & {
@@ -344,12 +342,10 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
344
342
  enableToolbarBottom?: boolean;
345
343
  enableToolbarInternalActions?: boolean;
346
344
  enableToolbarTop?: boolean;
347
- enabledGlobalFilterTypes?: (MRT_FILTER_TYPE | string)[];
348
- filterTypes?: { [key in MRT_FILTER_TYPE]: any };
345
+ enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[];
346
+ enabledGlobalFilterOptions?: (MRT_FILTER_OPTION | string)[];
349
347
  icons?: Partial<MRT_Icons>;
350
348
  idPrefix?: string;
351
- isLoading?: boolean;
352
- isReloading?: boolean;
353
349
  localization?: Partial<MRT_Localization>;
354
350
  muiLinearProgressProps?:
355
351
  | LinearProgressProps
@@ -770,6 +766,7 @@ export default <D extends Record<string, any> = {}>({
770
766
  enableHiding = true,
771
767
  enableMultiRowSelection = true,
772
768
  enablePagination = true,
769
+ enablePinning = false,
773
770
  enableSelectAll = true,
774
771
  enableSorting = true,
775
772
  enableStickyHeader = true,
@@ -792,8 +789,8 @@ export default <D extends Record<string, any> = {}>({
792
789
  columnResizeMode={columnResizeMode}
793
790
  editingMode={editingMode}
794
791
  enableColumnActions={enableColumnActions}
795
- enableColumnResizing={enableColumnResizing}
796
792
  enableColumnFilters={enableColumnFilters}
793
+ enableColumnResizing={enableColumnResizing}
797
794
  enableDensePaddingToggle={enableDensePaddingToggle}
798
795
  enableExpandAll={enableExpandAll}
799
796
  enableFilters={enableFilters}
@@ -802,6 +799,7 @@ export default <D extends Record<string, any> = {}>({
802
799
  enableHiding={enableHiding}
803
800
  enableMultiRowSelection={enableMultiRowSelection}
804
801
  enablePagination={enablePagination}
802
+ enablePinning={enablePinning}
805
803
  enableSelectAll={enableSelectAll}
806
804
  enableSorting={enableSorting}
807
805
  enableStickyHeader={enableStickyHeader}
@@ -4,15 +4,13 @@ import { MRT_TableBodyRow } from './MRT_TableBodyRow';
4
4
  import { MRT_TableInstance } from '..';
5
5
 
6
6
  interface Props {
7
- pinned: 'left' | 'center' | 'right' | 'none';
8
7
  tableInstance: MRT_TableInstance;
9
8
  }
10
9
 
11
- export const MRT_TableBody: FC<Props> = ({ pinned, tableInstance }) => {
10
+ export const MRT_TableBody: FC<Props> = ({ tableInstance }) => {
12
11
  const {
13
12
  getPaginationRowModel,
14
13
  getPrePaginationRowModel,
15
- getTableBodyProps,
16
14
  options: { enablePagination, muiTableBodyProps },
17
15
  } = tableInstance;
18
16
 
@@ -20,22 +18,16 @@ export const MRT_TableBody: FC<Props> = ({ pinned, tableInstance }) => {
20
18
  ? getPaginationRowModel().rows
21
19
  : getPrePaginationRowModel().rows;
22
20
 
23
- const mTableBodyProps =
21
+ const tableBodyProps =
24
22
  muiTableBodyProps instanceof Function
25
23
  ? muiTableBodyProps({ tableInstance })
26
24
  : muiTableBodyProps;
27
25
 
28
- const tableBodyProps = {
29
- ...getTableBodyProps(),
30
- ...mTableBodyProps,
31
- };
32
-
33
26
  return (
34
27
  <TableBody {...tableBodyProps}>
35
28
  {rows.map((row) => (
36
29
  <MRT_TableBodyRow
37
- key={row.getRowProps().key}
38
- pinned={pinned}
30
+ key={row.id}
39
31
  row={row}
40
32
  tableInstance={tableInstance}
41
33
  />
@@ -1,25 +1,27 @@
1
1
  import React, { FC, MouseEvent, useMemo } from 'react';
2
- import { Skeleton, TableCell } from '@mui/material';
2
+ import { alpha, darken, lighten, Skeleton, TableCell } from '@mui/material';
3
3
  import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
4
4
  import type { MRT_Cell, MRT_TableInstance } from '..';
5
5
  import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
6
6
 
7
7
  interface Props {
8
8
  cell: MRT_Cell;
9
+ enableHover?: boolean;
9
10
  tableInstance: MRT_TableInstance;
10
11
  }
11
12
 
12
- export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
13
+ export const MRT_TableBodyCell: FC<Props> = ({
14
+ cell,
15
+ enableHover,
16
+ tableInstance,
17
+ }) => {
13
18
  const {
14
- getIsSomeColumnsPinned,
15
19
  getState,
16
20
  options: {
17
21
  editingMode,
18
22
  enableClickToCopy,
19
23
  enableEditing,
20
- enablePinning,
21
24
  idPrefix,
22
- isLoading,
23
25
  muiTableBodyCellProps,
24
26
  muiTableBodyCellSkeletonProps,
25
27
  onCellClick,
@@ -27,7 +29,13 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
27
29
  setCurrentEditingCell,
28
30
  } = tableInstance;
29
31
 
30
- const { currentEditingCell, currentEditingRow, isDensePadding } = getState();
32
+ const {
33
+ currentEditingCell,
34
+ currentEditingRow,
35
+ isDensePadding,
36
+ isLoading,
37
+ showSkeletons,
38
+ } = getState();
31
39
 
32
40
  const { column, row } = cell;
33
41
 
@@ -42,7 +50,6 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
42
50
  : column.muiTableBodyCellProps;
43
51
 
44
52
  const tableCellProps = {
45
- ...cell.getCellProps(),
46
53
  ...mTableCellBodyProps,
47
54
  ...mcTableCellBodyProps,
48
55
  };
@@ -50,10 +57,10 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
50
57
  const skeletonWidth = useMemo(
51
58
  () =>
52
59
  column.columnDefType === 'display'
53
- ? column.getWidth() / 2
54
- : Math.random() * (column.getWidth() - column.getWidth() / 3) +
55
- column.getWidth() / 3,
56
- [column.columnDefType, column.getWidth()],
60
+ ? column.getSize() / 2
61
+ : Math.random() * (column.getSize() - column.getSize() / 3) +
62
+ column.getSize() / 3,
63
+ [column.columnDefType, column.getSize()],
57
64
  );
58
65
 
59
66
  const isEditable =
@@ -84,6 +91,26 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
84
91
  }
85
92
  };
86
93
 
94
+ const getIsLastLeftPinnedColumn = () => {
95
+ return (
96
+ column.getIsPinned() === 'left' &&
97
+ tableInstance.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
98
+ );
99
+ };
100
+
101
+ const getIsFirstRightPinnedColumn = () => {
102
+ return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
103
+ };
104
+
105
+ const getTotalRight = () => {
106
+ return (
107
+ (tableInstance.getRightLeafHeaders().length -
108
+ 1 -
109
+ column.getPinnedIndex()) *
110
+ 150
111
+ );
112
+ };
113
+
87
114
  return (
88
115
  <TableCell
89
116
  onClick={(event: MouseEvent<HTMLTableCellElement>) =>
@@ -91,10 +118,22 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
91
118
  }
92
119
  onDoubleClick={handleDoubleClick}
93
120
  {...tableCellProps}
94
- sx={{
121
+ sx={(theme) => ({
122
+ backgroundColor: column.getIsPinned()
123
+ ? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
124
+ : undefined,
125
+ boxShadow: getIsLastLeftPinnedColumn()
126
+ ? `4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
127
+ : getIsFirstRightPinnedColumn()
128
+ ? `-4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
129
+ : undefined,
95
130
  cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text',
96
- maxWidth: `min(${column.getWidth()}px, fit-content)`,
97
- minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
131
+ left:
132
+ column.getIsPinned() === 'left'
133
+ ? `${column.getStart('left')}px`
134
+ : undefined,
135
+ maxWidth: `min(${column.getSize()}px, fit-content)`,
136
+ minWidth: `max${column.getSize()}px, ${column.minSize}px`,
98
137
  p: isDensePadding
99
138
  ? column.columnDefType === 'display'
100
139
  ? '0 0.5rem'
@@ -106,46 +145,58 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
106
145
  column.id === 'mrt-expand'
107
146
  ? `${row.depth + (isDensePadding ? 0.5 : 0.75)}rem`
108
147
  : undefined,
148
+ position: column.getIsPinned() ? 'sticky' : 'relative',
149
+ right:
150
+ column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
109
151
  transition: 'all 0.2s ease-in-out',
110
- whiteSpace:
111
- isDensePadding || (enablePinning && getIsSomeColumnsPinned())
112
- ? 'nowrap'
113
- : 'normal',
114
- width: column.getWidth(),
115
- //@ts-ignore
116
- ...tableCellProps?.sx,
117
- }}
152
+ whiteSpace: isDensePadding ? 'nowrap' : 'normal',
153
+ width: column.getSize(),
154
+ zIndex: column.getIsPinned() ? 1 : undefined,
155
+ '&:hover': {
156
+ backgroundColor: enableHover
157
+ ? theme.palette.mode === 'dark'
158
+ ? `${lighten(theme.palette.background.default, 0.13)} !important`
159
+ : `${darken(theme.palette.background.default, 0.07)} !important`
160
+ : undefined,
161
+ },
162
+ ...(tableCellProps?.sx as any),
163
+ })}
118
164
  >
119
- {isLoading ? (
120
- <Skeleton
121
- animation="wave"
122
- height={20}
123
- width={skeletonWidth}
124
- {...muiTableBodyCellSkeletonProps}
125
- />
126
- ) : column.columnDefType === 'display' ? (
127
- column.Cell?.({ cell, tableInstance })
128
- ) : cell.getIsPlaceholder() ||
129
- (row.getIsGrouped() &&
130
- column.id !==
131
- row.groupingColumnId) ? null : cell.getIsAggregated() ? (
132
- cell.renderAggregatedCell()
133
- ) : isEditing ? (
134
- <MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
135
- ) : (enableClickToCopy || column.enableClickToCopy) &&
136
- column.enableClickToCopy !== false ? (
137
- <>
138
- <MRT_CopyButton cell={cell} tableInstance={tableInstance}>
165
+ <>
166
+ {isLoading || showSkeletons ? (
167
+ <Skeleton
168
+ animation="wave"
169
+ height={20}
170
+ width={skeletonWidth}
171
+ {...muiTableBodyCellSkeletonProps}
172
+ />
173
+ ) : column.columnDefType === 'display' ? (
174
+ column.Cell?.({ cell, tableInstance })
175
+ ) : cell.getIsPlaceholder() ||
176
+ (row.getIsGrouped() &&
177
+ column.id !==
178
+ row.groupingColumnId) ? null : cell.getIsAggregated() ? (
179
+ cell.renderAggregatedCell()
180
+ ) : isEditing ? (
181
+ <MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
182
+ ) : (enableClickToCopy || column.enableClickToCopy) &&
183
+ column.enableClickToCopy !== false ? (
184
+ <>
185
+ <MRT_CopyButton cell={cell} tableInstance={tableInstance}>
186
+ <>
187
+ {cell.column?.Cell?.({ cell, tableInstance }) ??
188
+ cell.renderCell()}
189
+ </>
190
+ </MRT_CopyButton>
191
+ {row.getIsGrouped() && <> ({row.subRows?.length})</>}
192
+ </>
193
+ ) : (
194
+ <>
139
195
  {cell.column?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
140
- </MRT_CopyButton>
141
- {row.getIsGrouped() && <> ({row.subRows?.length})</>}
142
- </>
143
- ) : (
144
- <>
145
- {cell.column?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
146
- {row.getIsGrouped() && <> ({row.subRows?.length})</>}
147
- </>
148
- )}
196
+ {row.getIsGrouped() && <> ({row.subRows?.length})</>}
197
+ </>
198
+ )}
199
+ </>
149
200
  </TableCell>
150
201
  );
151
202
  };