@cutting/material-react-table 4.0.0

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 (327) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +215 -0
  3. package/dist/index.d.ts +1876 -0
  4. package/dist/index.esm.js +4434 -0
  5. package/dist/index.esm.js.map +1 -0
  6. package/dist/index.js +4540 -0
  7. package/dist/index.js.map +1 -0
  8. package/locales/ar/index.d.ts +3 -0
  9. package/locales/ar/index.esm.d.ts +3 -0
  10. package/locales/ar/index.esm.js +96 -0
  11. package/locales/ar/index.js +98 -0
  12. package/locales/ar/package.json +6 -0
  13. package/locales/az/index.d.ts +3 -0
  14. package/locales/az/index.esm.d.ts +3 -0
  15. package/locales/az/index.esm.js +96 -0
  16. package/locales/az/index.js +98 -0
  17. package/locales/az/package.json +6 -0
  18. package/locales/bg/index.d.ts +3 -0
  19. package/locales/bg/index.esm.d.ts +3 -0
  20. package/locales/bg/index.esm.js +96 -0
  21. package/locales/bg/index.js +98 -0
  22. package/locales/bg/package.json +6 -0
  23. package/locales/cs/index.d.ts +3 -0
  24. package/locales/cs/index.esm.d.ts +3 -0
  25. package/locales/cs/index.esm.js +96 -0
  26. package/locales/cs/index.js +98 -0
  27. package/locales/cs/package.json +6 -0
  28. package/locales/da/index.d.ts +3 -0
  29. package/locales/da/index.esm.d.ts +3 -0
  30. package/locales/da/index.esm.js +96 -0
  31. package/locales/da/index.js +98 -0
  32. package/locales/da/package.json +6 -0
  33. package/locales/de/index.d.ts +3 -0
  34. package/locales/de/index.esm.d.ts +3 -0
  35. package/locales/de/index.esm.js +96 -0
  36. package/locales/de/index.js +98 -0
  37. package/locales/de/package.json +6 -0
  38. package/locales/el/index.d.ts +3 -0
  39. package/locales/el/index.esm.d.ts +3 -0
  40. package/locales/el/index.esm.js +96 -0
  41. package/locales/el/index.js +98 -0
  42. package/locales/el/package.json +6 -0
  43. package/locales/en/index.d.ts +3 -0
  44. package/locales/en/index.esm.d.ts +3 -0
  45. package/locales/en/index.esm.js +96 -0
  46. package/locales/en/index.js +98 -0
  47. package/locales/en/package.json +6 -0
  48. package/locales/es/index.d.ts +3 -0
  49. package/locales/es/index.esm.d.ts +3 -0
  50. package/locales/es/index.esm.js +96 -0
  51. package/locales/es/index.js +98 -0
  52. package/locales/es/package.json +6 -0
  53. package/locales/et/index.d.ts +3 -0
  54. package/locales/et/index.esm.d.ts +3 -0
  55. package/locales/et/index.esm.js +96 -0
  56. package/locales/et/index.js +98 -0
  57. package/locales/et/package.json +6 -0
  58. package/locales/fa/index.d.ts +3 -0
  59. package/locales/fa/index.esm.d.ts +3 -0
  60. package/locales/fa/index.esm.js +96 -0
  61. package/locales/fa/index.js +98 -0
  62. package/locales/fa/package.json +6 -0
  63. package/locales/fi/index.d.ts +3 -0
  64. package/locales/fi/index.esm.d.ts +3 -0
  65. package/locales/fi/index.esm.js +96 -0
  66. package/locales/fi/index.js +98 -0
  67. package/locales/fi/package.json +6 -0
  68. package/locales/fr/index.d.ts +3 -0
  69. package/locales/fr/index.esm.d.ts +3 -0
  70. package/locales/fr/index.esm.js +96 -0
  71. package/locales/fr/index.js +98 -0
  72. package/locales/fr/package.json +6 -0
  73. package/locales/he/index.d.ts +3 -0
  74. package/locales/he/index.esm.d.ts +3 -0
  75. package/locales/he/index.esm.js +96 -0
  76. package/locales/he/index.js +98 -0
  77. package/locales/he/package.json +6 -0
  78. package/locales/hr/index.d.ts +3 -0
  79. package/locales/hr/index.esm.d.ts +3 -0
  80. package/locales/hr/index.esm.js +96 -0
  81. package/locales/hr/index.js +98 -0
  82. package/locales/hr/package.json +6 -0
  83. package/locales/hu/index.d.ts +3 -0
  84. package/locales/hu/index.esm.d.ts +3 -0
  85. package/locales/hu/index.esm.js +96 -0
  86. package/locales/hu/index.js +98 -0
  87. package/locales/hu/package.json +6 -0
  88. package/locales/hy/index.d.ts +3 -0
  89. package/locales/hy/index.esm.d.ts +3 -0
  90. package/locales/hy/index.esm.js +96 -0
  91. package/locales/hy/index.js +98 -0
  92. package/locales/hy/package.json +6 -0
  93. package/locales/id/index.d.ts +3 -0
  94. package/locales/id/index.esm.d.ts +3 -0
  95. package/locales/id/index.esm.js +96 -0
  96. package/locales/id/index.js +98 -0
  97. package/locales/id/package.json +6 -0
  98. package/locales/it/index.d.ts +3 -0
  99. package/locales/it/index.esm.d.ts +3 -0
  100. package/locales/it/index.esm.js +96 -0
  101. package/locales/it/index.js +98 -0
  102. package/locales/it/package.json +6 -0
  103. package/locales/ja/index.d.ts +3 -0
  104. package/locales/ja/index.esm.d.ts +3 -0
  105. package/locales/ja/index.esm.js +96 -0
  106. package/locales/ja/index.js +98 -0
  107. package/locales/ja/package.json +6 -0
  108. package/locales/ko/index.d.ts +3 -0
  109. package/locales/ko/index.esm.d.ts +3 -0
  110. package/locales/ko/index.esm.js +96 -0
  111. package/locales/ko/index.js +98 -0
  112. package/locales/ko/package.json +6 -0
  113. package/locales/nl/index.d.ts +3 -0
  114. package/locales/nl/index.esm.d.ts +3 -0
  115. package/locales/nl/index.esm.js +96 -0
  116. package/locales/nl/index.js +98 -0
  117. package/locales/nl/package.json +6 -0
  118. package/locales/no/index.d.ts +3 -0
  119. package/locales/no/index.esm.d.ts +3 -0
  120. package/locales/no/index.esm.js +96 -0
  121. package/locales/no/index.js +98 -0
  122. package/locales/no/package.json +6 -0
  123. package/locales/np/index.d.ts +3 -0
  124. package/locales/np/index.esm.d.ts +3 -0
  125. package/locales/np/index.esm.js +96 -0
  126. package/locales/np/index.js +98 -0
  127. package/locales/np/package.json +6 -0
  128. package/locales/pl/index.d.ts +3 -0
  129. package/locales/pl/index.esm.d.ts +3 -0
  130. package/locales/pl/index.esm.js +96 -0
  131. package/locales/pl/index.js +98 -0
  132. package/locales/pl/package.json +6 -0
  133. package/locales/pt/index.d.ts +3 -0
  134. package/locales/pt/index.esm.d.ts +3 -0
  135. package/locales/pt/index.esm.js +96 -0
  136. package/locales/pt/index.js +98 -0
  137. package/locales/pt/package.json +6 -0
  138. package/locales/pt-BR/index.d.ts +3 -0
  139. package/locales/pt-BR/index.esm.d.ts +3 -0
  140. package/locales/pt-BR/index.esm.js +96 -0
  141. package/locales/pt-BR/index.js +98 -0
  142. package/locales/pt-BR/package.json +6 -0
  143. package/locales/ro/index.d.ts +3 -0
  144. package/locales/ro/index.esm.d.ts +3 -0
  145. package/locales/ro/index.esm.js +96 -0
  146. package/locales/ro/index.js +98 -0
  147. package/locales/ro/package.json +6 -0
  148. package/locales/ru/index.d.ts +3 -0
  149. package/locales/ru/index.esm.d.ts +3 -0
  150. package/locales/ru/index.esm.js +96 -0
  151. package/locales/ru/index.js +98 -0
  152. package/locales/ru/package.json +6 -0
  153. package/locales/sk/index.d.ts +3 -0
  154. package/locales/sk/index.esm.d.ts +3 -0
  155. package/locales/sk/index.esm.js +96 -0
  156. package/locales/sk/index.js +98 -0
  157. package/locales/sk/package.json +6 -0
  158. package/locales/sr-Cyrl-RS/index.d.ts +3 -0
  159. package/locales/sr-Cyrl-RS/index.esm.d.ts +3 -0
  160. package/locales/sr-Cyrl-RS/index.esm.js +96 -0
  161. package/locales/sr-Cyrl-RS/index.js +98 -0
  162. package/locales/sr-Cyrl-RS/package.json +6 -0
  163. package/locales/sr-Latn-RS/index.d.ts +3 -0
  164. package/locales/sr-Latn-RS/index.esm.d.ts +3 -0
  165. package/locales/sr-Latn-RS/index.esm.js +96 -0
  166. package/locales/sr-Latn-RS/index.js +98 -0
  167. package/locales/sr-Latn-RS/package.json +6 -0
  168. package/locales/sv/index.d.ts +3 -0
  169. package/locales/sv/index.esm.d.ts +3 -0
  170. package/locales/sv/index.esm.js +96 -0
  171. package/locales/sv/index.js +98 -0
  172. package/locales/sv/package.json +6 -0
  173. package/locales/tr/index.d.ts +3 -0
  174. package/locales/tr/index.esm.d.ts +3 -0
  175. package/locales/tr/index.esm.js +96 -0
  176. package/locales/tr/index.js +98 -0
  177. package/locales/tr/package.json +6 -0
  178. package/locales/uk/index.d.ts +3 -0
  179. package/locales/uk/index.esm.d.ts +3 -0
  180. package/locales/uk/index.esm.js +96 -0
  181. package/locales/uk/index.js +98 -0
  182. package/locales/uk/package.json +6 -0
  183. package/locales/vi/index.d.ts +3 -0
  184. package/locales/vi/index.esm.d.ts +3 -0
  185. package/locales/vi/index.esm.js +96 -0
  186. package/locales/vi/index.js +98 -0
  187. package/locales/vi/package.json +6 -0
  188. package/locales/zh-Hans/index.d.ts +3 -0
  189. package/locales/zh-Hans/index.esm.d.ts +3 -0
  190. package/locales/zh-Hans/index.esm.js +96 -0
  191. package/locales/zh-Hans/index.js +98 -0
  192. package/locales/zh-Hans/package.json +6 -0
  193. package/locales/zh-Hant/index.d.ts +3 -0
  194. package/locales/zh-Hant/index.esm.d.ts +3 -0
  195. package/locales/zh-Hant/index.esm.js +96 -0
  196. package/locales/zh-Hant/index.js +98 -0
  197. package/locales/zh-Hant/package.json +6 -0
  198. package/package.json +133 -0
  199. package/src/MaterialReactTable.smoke.test.tsx +56 -0
  200. package/src/components/MaterialReactTable.tsx +36 -0
  201. package/src/components/body/MRT_TableBody.tsx +222 -0
  202. package/src/components/body/MRT_TableBodyCell.tsx +352 -0
  203. package/src/components/body/MRT_TableBodyCellValue.tsx +131 -0
  204. package/src/components/body/MRT_TableBodyRow.tsx +283 -0
  205. package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +62 -0
  206. package/src/components/body/MRT_TableBodyRowPinButton.tsx +59 -0
  207. package/src/components/body/MRT_TableDetailPanel.tsx +111 -0
  208. package/src/components/buttons/MRT_ColumnPinningButtons.tsx +73 -0
  209. package/src/components/buttons/MRT_CopyButton.tsx +88 -0
  210. package/src/components/buttons/MRT_EditActionButtons.tsx +135 -0
  211. package/src/components/buttons/MRT_ExpandAllButton.tsx +79 -0
  212. package/src/components/buttons/MRT_ExpandButton.tsx +103 -0
  213. package/src/components/buttons/MRT_GrabHandleButton.tsx +66 -0
  214. package/src/components/buttons/MRT_RowPinButton.tsx +85 -0
  215. package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +51 -0
  216. package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +53 -0
  217. package/src/components/buttons/MRT_ToggleFiltersButton.tsx +41 -0
  218. package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +52 -0
  219. package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +47 -0
  220. package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +127 -0
  221. package/src/components/footer/MRT_TableFooter.tsx +89 -0
  222. package/src/components/footer/MRT_TableFooterCell.tsx +108 -0
  223. package/src/components/footer/MRT_TableFooterRow.tsx +96 -0
  224. package/src/components/head/MRT_TableHead.tsx +92 -0
  225. package/src/components/head/MRT_TableHeadCell.tsx +352 -0
  226. package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +97 -0
  227. package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +53 -0
  228. package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +179 -0
  229. package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +92 -0
  230. package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +97 -0
  231. package/src/components/head/MRT_TableHeadCellSortLabel.tsx +102 -0
  232. package/src/components/head/MRT_TableHeadRow.tsx +91 -0
  233. package/src/components/inputs/MRT_EditCellTextField.tsx +190 -0
  234. package/src/components/inputs/MRT_FilterCheckbox.tsx +91 -0
  235. package/src/components/inputs/MRT_FilterRangeFields.tsx +42 -0
  236. package/src/components/inputs/MRT_FilterRangeSlider.tsx +144 -0
  237. package/src/components/inputs/MRT_FilterTextField.tsx +599 -0
  238. package/src/components/inputs/MRT_GlobalFilterTextField.tsx +160 -0
  239. package/src/components/inputs/MRT_SelectCheckbox.tsx +136 -0
  240. package/src/components/menus/MRT_ActionMenuItem.tsx +63 -0
  241. package/src/components/menus/MRT_CellActionMenu.tsx +108 -0
  242. package/src/components/menus/MRT_ColumnActionMenu.tsx +353 -0
  243. package/src/components/menus/MRT_FilterOptionMenu.tsx +293 -0
  244. package/src/components/menus/MRT_RowActionMenu.tsx +89 -0
  245. package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +180 -0
  246. package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +204 -0
  247. package/src/components/modals/MRT_EditRowModal.tsx +115 -0
  248. package/src/components/table/MRT_Table.tsx +85 -0
  249. package/src/components/table/MRT_TableContainer.tsx +112 -0
  250. package/src/components/table/MRT_TableLoadingOverlay.tsx +59 -0
  251. package/src/components/table/MRT_TablePaper.tsx +90 -0
  252. package/src/components/toolbar/MRT_BottomToolbar.tsx +109 -0
  253. package/src/components/toolbar/MRT_LinearProgressBar.tsx +54 -0
  254. package/src/components/toolbar/MRT_TablePagination.tsx +244 -0
  255. package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +184 -0
  256. package/src/components/toolbar/MRT_ToolbarDropZone.tsx +81 -0
  257. package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +73 -0
  258. package/src/components/toolbar/MRT_TopToolbar.tsx +131 -0
  259. package/src/fns/aggregationFns.ts +3 -0
  260. package/src/fns/filterFns.ts +197 -0
  261. package/src/fns/sortingFns.ts +34 -0
  262. package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +28 -0
  263. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +30 -0
  264. package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +97 -0
  265. package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +30 -0
  266. package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +24 -0
  267. package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +34 -0
  268. package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +33 -0
  269. package/src/hooks/useMRT_ColumnVirtualizer.ts +125 -0
  270. package/src/hooks/useMRT_Effects.ts +107 -0
  271. package/src/hooks/useMRT_RowVirtualizer.ts +89 -0
  272. package/src/hooks/useMRT_Rows.ts +45 -0
  273. package/src/hooks/useMRT_TableInstance.ts +318 -0
  274. package/src/hooks/useMRT_TableOptions.ts +271 -0
  275. package/src/hooks/useMaterialReactTable.ts +12 -0
  276. package/src/icons.ts +73 -0
  277. package/src/index.ts +91 -0
  278. package/src/locales/ar.ts +97 -0
  279. package/src/locales/az.ts +97 -0
  280. package/src/locales/bg.ts +97 -0
  281. package/src/locales/cs.ts +98 -0
  282. package/src/locales/da.ts +97 -0
  283. package/src/locales/de.ts +97 -0
  284. package/src/locales/el.ts +97 -0
  285. package/src/locales/en.ts +97 -0
  286. package/src/locales/es.ts +97 -0
  287. package/src/locales/et.ts +98 -0
  288. package/src/locales/fa.ts +97 -0
  289. package/src/locales/fi.ts +98 -0
  290. package/src/locales/fr.ts +97 -0
  291. package/src/locales/he.ts +97 -0
  292. package/src/locales/hr.ts +97 -0
  293. package/src/locales/hu.ts +97 -0
  294. package/src/locales/hy.ts +97 -0
  295. package/src/locales/id.ts +98 -0
  296. package/src/locales/it.ts +97 -0
  297. package/src/locales/ja.ts +97 -0
  298. package/src/locales/ko.ts +97 -0
  299. package/src/locales/mk.ts +96 -0
  300. package/src/locales/nl.ts +97 -0
  301. package/src/locales/no.ts +99 -0
  302. package/src/locales/np.ts +98 -0
  303. package/src/locales/pl.ts +97 -0
  304. package/src/locales/pt-BR.ts +97 -0
  305. package/src/locales/pt.ts +97 -0
  306. package/src/locales/ro.ts +97 -0
  307. package/src/locales/ru.ts +97 -0
  308. package/src/locales/sk.ts +98 -0
  309. package/src/locales/sr-Cyrl-RS.ts +97 -0
  310. package/src/locales/sr-Latn-RS.ts +97 -0
  311. package/src/locales/sv.ts +97 -0
  312. package/src/locales/tr.ts +97 -0
  313. package/src/locales/uk.ts +97 -0
  314. package/src/locales/vi.ts +97 -0
  315. package/src/locales/zh-Hans.ts +96 -0
  316. package/src/locales/zh-Hant.ts +96 -0
  317. package/src/types.ts +1290 -0
  318. package/src/utils/cell.utils.ts +234 -0
  319. package/src/utils/column.utils.ts +210 -0
  320. package/src/utils/displayColumn.utils.ts +152 -0
  321. package/src/utils/row.utils.ts +261 -0
  322. package/src/utils/slotProps.utils.ts +25 -0
  323. package/src/utils/style.utils.ts +210 -0
  324. package/src/utils/tanstack.helpers.ts +65 -0
  325. package/src/utils/utils.ts +23 -0
  326. package/src/utils/virtualization.utils.ts +24 -0
  327. package/src/vitest.setup.ts +1 -0
@@ -0,0 +1,112 @@
1
+ import TableContainer, {
2
+ type TableContainerProps,
3
+ } from '@mui/material/TableContainer';
4
+ import { useEffect, useLayoutEffect, useState } from 'react';
5
+
6
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
7
+ import { parseFromValuesOrFunc } from '../../utils/utils';
8
+ import { MRT_CellActionMenu } from '../menus/MRT_CellActionMenu';
9
+ import { MRT_EditRowModal } from '../modals/MRT_EditRowModal';
10
+ import { MRT_Table } from './MRT_Table';
11
+ import { MRT_TableLoadingOverlay } from './MRT_TableLoadingOverlay';
12
+
13
+ const useIsomorphicLayoutEffect =
14
+ typeof window !== 'undefined' ? useLayoutEffect : useEffect;
15
+
16
+ export interface MRT_TableContainerProps<TData extends MRT_RowData>
17
+ extends TableContainerProps {
18
+ table: MRT_TableInstance<TData>;
19
+ }
20
+
21
+ export const MRT_TableContainer = <TData extends MRT_RowData>({
22
+ table,
23
+ ...rest
24
+ }: MRT_TableContainerProps<TData>) => {
25
+ const {
26
+ getState,
27
+ options: {
28
+ createDisplayMode,
29
+ editDisplayMode,
30
+ enableCellActions,
31
+ enableStickyHeader,
32
+ muiTableContainerProps,
33
+ },
34
+ refs: { bottomToolbarRef, tableContainerRef, topToolbarRef },
35
+ } = table;
36
+ const {
37
+ actionCell,
38
+ creatingRow,
39
+ editingRow,
40
+ isFullScreen,
41
+ isLoading,
42
+ showLoadingOverlay,
43
+ } = getState();
44
+
45
+ const loading =
46
+ showLoadingOverlay !== false && (isLoading || showLoadingOverlay);
47
+
48
+ const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
49
+
50
+ const tableContainerProps = {
51
+ ...parseFromValuesOrFunc(muiTableContainerProps, {
52
+ table,
53
+ }),
54
+ ...rest,
55
+ };
56
+
57
+ useIsomorphicLayoutEffect(() => {
58
+ const topToolbarHeight =
59
+ typeof document !== 'undefined'
60
+ ? (topToolbarRef.current?.offsetHeight ?? 0)
61
+ : 0;
62
+
63
+ const bottomToolbarHeight =
64
+ typeof document !== 'undefined'
65
+ ? (bottomToolbarRef?.current?.offsetHeight ?? 0)
66
+ : 0;
67
+
68
+ setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
69
+ });
70
+
71
+ const createModalOpen = createDisplayMode === 'modal' && creatingRow;
72
+ const editModalOpen = editDisplayMode === 'modal' && editingRow;
73
+
74
+ return (
75
+ <TableContainer
76
+ aria-busy={loading}
77
+ aria-describedby={loading ? 'mrt-progress' : undefined}
78
+ {...tableContainerProps}
79
+ ref={(node: HTMLDivElement) => {
80
+ if (node) {
81
+ tableContainerRef.current = node;
82
+ if (tableContainerProps?.ref) {
83
+ //@ts-expect-error
84
+ tableContainerProps.ref.current = node;
85
+ }
86
+ }
87
+ }}
88
+ style={{
89
+ maxHeight: isFullScreen
90
+ ? `calc(100vh - ${totalToolbarHeight}px)`
91
+ : undefined,
92
+ ...tableContainerProps?.style,
93
+ }}
94
+ sx={(theme) => ({
95
+ maxHeight: enableStickyHeader
96
+ ? `clamp(350px, calc(100vh - ${totalToolbarHeight}px), 9999px)`
97
+ : undefined,
98
+ maxWidth: '100%',
99
+ overflow: 'auto',
100
+ position: 'relative',
101
+ ...(parseFromValuesOrFunc(tableContainerProps?.sx, theme) as any),
102
+ })}
103
+ >
104
+ {loading ? <MRT_TableLoadingOverlay table={table} /> : null}
105
+ <MRT_Table table={table} />
106
+ {(createModalOpen || editModalOpen) && (
107
+ <MRT_EditRowModal open table={table} />
108
+ )}
109
+ {enableCellActions && actionCell && <MRT_CellActionMenu table={table} />}
110
+ </TableContainer>
111
+ );
112
+ };
@@ -0,0 +1,59 @@
1
+ import Box from '@mui/material/Box';
2
+ import CircularProgress, {
3
+ type CircularProgressProps,
4
+ } from '@mui/material/CircularProgress';
5
+ import { alpha } from '@mui/material/styles';
6
+
7
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
8
+ import { parseFromValuesOrFunc } from '../../utils/utils';
9
+
10
+ export interface MRT_TableLoadingOverlayProps<TData extends MRT_RowData>
11
+ extends CircularProgressProps {
12
+ table: MRT_TableInstance<TData>;
13
+ }
14
+
15
+ export const MRT_TableLoadingOverlay = <TData extends MRT_RowData>({
16
+ table,
17
+ ...rest
18
+ }: MRT_TableLoadingOverlayProps<TData>) => {
19
+ const {
20
+ options: {
21
+ id,
22
+ localization,
23
+ mrtTheme: { baseBackgroundColor },
24
+ muiCircularProgressProps,
25
+ },
26
+ } = table;
27
+
28
+ const circularProgressProps = {
29
+ ...parseFromValuesOrFunc(muiCircularProgressProps, { table }),
30
+ ...rest,
31
+ };
32
+
33
+ return (
34
+ <Box
35
+ sx={{
36
+ alignItems: 'center',
37
+ backgroundColor: alpha(baseBackgroundColor, 0.5),
38
+ bottom: 0,
39
+ display: 'flex',
40
+ justifyContent: 'center',
41
+ left: 0,
42
+ maxHeight: '100vh',
43
+ position: 'absolute',
44
+ right: 0,
45
+ top: 0,
46
+ width: '100%',
47
+ zIndex: 3,
48
+ }}
49
+ >
50
+ {circularProgressProps?.Component ?? (
51
+ <CircularProgress
52
+ aria-label={localization.noRecordsToDisplay}
53
+ id={`mrt-progress-${id}`}
54
+ {...circularProgressProps}
55
+ />
56
+ )}
57
+ </Box>
58
+ );
59
+ };
@@ -0,0 +1,90 @@
1
+ import Paper, { type PaperProps } from '@mui/material/Paper';
2
+ import { useTheme } from '@mui/material/styles';
3
+
4
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
5
+ import { parseFromValuesOrFunc } from '../../utils/utils';
6
+ import { MRT_BottomToolbar } from '../toolbar/MRT_BottomToolbar';
7
+ import { MRT_TopToolbar } from '../toolbar/MRT_TopToolbar';
8
+ import { MRT_TableContainer } from './MRT_TableContainer';
9
+
10
+ export interface MRT_TablePaperProps<TData extends MRT_RowData>
11
+ extends PaperProps {
12
+ table: MRT_TableInstance<TData>;
13
+ }
14
+
15
+ export const MRT_TablePaper = <TData extends MRT_RowData>({
16
+ table,
17
+ ...rest
18
+ }: MRT_TablePaperProps<TData>) => {
19
+ const {
20
+ getState,
21
+ options: {
22
+ enableBottomToolbar,
23
+ enableTopToolbar,
24
+ mrtTheme: { baseBackgroundColor },
25
+ muiTablePaperProps,
26
+ renderBottomToolbar,
27
+ renderTopToolbar,
28
+ },
29
+ refs: { tablePaperRef },
30
+ } = table;
31
+ const { isFullScreen } = getState();
32
+
33
+ const paperProps = {
34
+ ...parseFromValuesOrFunc(muiTablePaperProps, { table }),
35
+ ...rest,
36
+ };
37
+
38
+ const theme = useTheme();
39
+
40
+ return (
41
+ <Paper
42
+ elevation={2}
43
+ onKeyDown={(e) => e.key === 'Escape' && table.setIsFullScreen(false)}
44
+ {...paperProps}
45
+ ref={(ref: HTMLDivElement) => {
46
+ tablePaperRef.current = ref;
47
+ if (paperProps?.ref) {
48
+ //@ts-expect-error
49
+ paperProps.ref.current = ref;
50
+ }
51
+ }}
52
+ style={{
53
+ ...(isFullScreen
54
+ ? {
55
+ bottom: 0,
56
+ height: '100dvh',
57
+ left: 0,
58
+ margin: 0,
59
+ maxHeight: '100dvh',
60
+ maxWidth: '100dvw',
61
+ padding: 0,
62
+ position: 'fixed',
63
+ right: 0,
64
+ top: 0,
65
+ width: '100dvw',
66
+ zIndex: theme.zIndex.modal,
67
+ }
68
+ : {}),
69
+ ...paperProps?.style,
70
+ }}
71
+ sx={(theme) => ({
72
+ backgroundColor: baseBackgroundColor,
73
+ backgroundImage: 'unset',
74
+ overflow: 'hidden',
75
+ transition: 'all 100ms ease-in-out',
76
+ ...(parseFromValuesOrFunc(paperProps?.sx, theme) as any),
77
+ })}
78
+ >
79
+ {enableTopToolbar &&
80
+ (parseFromValuesOrFunc(renderTopToolbar, { table }) ?? (
81
+ <MRT_TopToolbar table={table} />
82
+ ))}
83
+ <MRT_TableContainer table={table} />
84
+ {enableBottomToolbar &&
85
+ (parseFromValuesOrFunc(renderBottomToolbar, { table }) ?? (
86
+ <MRT_BottomToolbar table={table} />
87
+ ))}
88
+ </Paper>
89
+ );
90
+ };
@@ -0,0 +1,109 @@
1
+ import Box, { type BoxProps } from '@mui/material/Box';
2
+ import { alpha } from '@mui/material/styles';
3
+ import useMediaQuery from '@mui/material/useMediaQuery';
4
+
5
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
6
+ import { getCommonToolbarStyles } from '../../utils/style.utils';
7
+ import { parseFromValuesOrFunc } from '../../utils/utils';
8
+ import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
9
+ import { MRT_TablePagination } from './MRT_TablePagination';
10
+ import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
11
+ import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
12
+
13
+ export interface MRT_BottomToolbarProps<TData extends MRT_RowData>
14
+ extends BoxProps {
15
+ table: MRT_TableInstance<TData>;
16
+ }
17
+
18
+ export const MRT_BottomToolbar = <TData extends MRT_RowData>({
19
+ table,
20
+ ...rest
21
+ }: MRT_BottomToolbarProps<TData>) => {
22
+ const {
23
+ getState,
24
+ options: {
25
+ enablePagination,
26
+ muiBottomToolbarProps,
27
+ positionPagination,
28
+ positionToolbarAlertBanner,
29
+ positionToolbarDropZone,
30
+ renderBottomToolbarCustomActions,
31
+ },
32
+ refs: { bottomToolbarRef },
33
+ } = table;
34
+ const { isFullScreen } = getState();
35
+
36
+ const isMobile = useMediaQuery('(max-width:720px)');
37
+
38
+ const toolbarProps = {
39
+ ...parseFromValuesOrFunc(muiBottomToolbarProps, { table }),
40
+ ...rest,
41
+ };
42
+
43
+ const stackAlertBanner = isMobile || !!renderBottomToolbarCustomActions;
44
+
45
+ return (
46
+ <Box
47
+ {...toolbarProps}
48
+ ref={(node: HTMLDivElement) => {
49
+ if (node) {
50
+ bottomToolbarRef.current = node;
51
+ if (toolbarProps?.ref) {
52
+ // @ts-expect-error
53
+ toolbarProps.ref.current = node;
54
+ }
55
+ }
56
+ }}
57
+ sx={(theme) => ({
58
+ ...getCommonToolbarStyles({ table, theme }),
59
+ bottom: isFullScreen ? '0' : undefined,
60
+ boxShadow: `0 1px 2px -1px ${alpha(theme.palette.grey[700], 0.5)} inset`,
61
+ left: 0,
62
+ position: isFullScreen ? 'fixed' : 'relative',
63
+ right: 0,
64
+ ...(parseFromValuesOrFunc(toolbarProps?.sx, theme) as any),
65
+ })}
66
+ >
67
+ <MRT_LinearProgressBar isTopToolbar={false} table={table} />
68
+ {positionToolbarAlertBanner === 'bottom' && (
69
+ <MRT_ToolbarAlertBanner
70
+ stackAlertBanner={stackAlertBanner}
71
+ table={table}
72
+ />
73
+ )}
74
+ {['both', 'bottom'].includes(positionToolbarDropZone ?? '') && (
75
+ <MRT_ToolbarDropZone table={table} />
76
+ )}
77
+ <Box
78
+ sx={{
79
+ alignItems: 'center',
80
+ boxSizing: 'border-box',
81
+ display: 'flex',
82
+ justifyContent: 'space-between',
83
+ p: '0.5rem',
84
+ width: '100%',
85
+ }}
86
+ >
87
+ {renderBottomToolbarCustomActions ? (
88
+ renderBottomToolbarCustomActions({ table })
89
+ ) : (
90
+ <span />
91
+ )}
92
+ <Box
93
+ sx={{
94
+ display: 'flex',
95
+ justifyContent: 'flex-end',
96
+ position: stackAlertBanner ? 'relative' : 'absolute',
97
+ right: 0,
98
+ top: 0,
99
+ }}
100
+ >
101
+ {enablePagination &&
102
+ ['both', 'bottom'].includes(positionPagination ?? '') && (
103
+ <MRT_TablePagination position="bottom" table={table} />
104
+ )}
105
+ </Box>
106
+ </Box>
107
+ </Box>
108
+ );
109
+ };
@@ -0,0 +1,54 @@
1
+ import Collapse from '@mui/material/Collapse';
2
+ import LinearProgress, {
3
+ type LinearProgressProps,
4
+ } from '@mui/material/LinearProgress';
5
+
6
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
7
+ import { parseFromValuesOrFunc } from '../../utils/utils';
8
+
9
+ export interface MRT_LinearProgressBarProps<TData extends MRT_RowData>
10
+ extends LinearProgressProps {
11
+ isTopToolbar: boolean;
12
+ table: MRT_TableInstance<TData>;
13
+ }
14
+
15
+ export const MRT_LinearProgressBar = <TData extends MRT_RowData>({
16
+ isTopToolbar,
17
+ table,
18
+ ...rest
19
+ }: MRT_LinearProgressBarProps<TData>) => {
20
+ const {
21
+ getState,
22
+ options: { muiLinearProgressProps },
23
+ } = table;
24
+ const { isSaving, showProgressBars } = getState();
25
+
26
+ const linearProgressProps = {
27
+ ...parseFromValuesOrFunc(muiLinearProgressProps, {
28
+ isTopToolbar,
29
+ table,
30
+ }),
31
+ ...rest,
32
+ };
33
+
34
+ return (
35
+ <Collapse
36
+ in={showProgressBars !== false && (showProgressBars || isSaving)}
37
+ mountOnEnter
38
+ sx={{
39
+ bottom: isTopToolbar ? 0 : undefined,
40
+ position: 'absolute',
41
+ top: !isTopToolbar ? 0 : undefined,
42
+ width: '100%',
43
+ }}
44
+ unmountOnExit
45
+ >
46
+ <LinearProgress
47
+ aria-busy="true"
48
+ aria-label="Loading"
49
+ sx={{ position: 'relative' }}
50
+ {...linearProgressProps}
51
+ />
52
+ </Collapse>
53
+ );
54
+ };
@@ -0,0 +1,244 @@
1
+ import Box from '@mui/material/Box';
2
+ import IconButton from '@mui/material/IconButton';
3
+ import InputLabel from '@mui/material/InputLabel';
4
+ import MenuItem from '@mui/material/MenuItem';
5
+ import Pagination, { type PaginationProps } from '@mui/material/Pagination';
6
+ import PaginationItem from '@mui/material/PaginationItem';
7
+ import Select, { type SelectProps } from '@mui/material/Select';
8
+ import { useTheme } from '@mui/material/styles';
9
+ import Tooltip from '@mui/material/Tooltip';
10
+ import Typography from '@mui/material/Typography';
11
+ import useMediaQuery from '@mui/material/useMediaQuery';
12
+
13
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
14
+ import { flipIconStyles, getCommonTooltipProps } from '../../utils/style.utils';
15
+ import { parseFromValuesOrFunc } from '../../utils/utils';
16
+
17
+ const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100];
18
+
19
+ export interface MRT_TablePaginationProps<TData extends MRT_RowData>
20
+ extends Partial<
21
+ PaginationProps & {
22
+ disabled?: boolean;
23
+ rowsPerPageOptions?: number[] | { label: string; value: number }[];
24
+ SelectProps?: Partial<SelectProps>;
25
+ showRowsPerPage?: boolean;
26
+ }
27
+ > {
28
+ position?: 'bottom' | 'top';
29
+ table: MRT_TableInstance<TData>;
30
+ }
31
+
32
+ export const MRT_TablePagination = <TData extends MRT_RowData>({
33
+ position = 'bottom',
34
+ table,
35
+ ...rest
36
+ }: MRT_TablePaginationProps<TData>) => {
37
+ const theme = useTheme();
38
+ const isMobile = useMediaQuery('(max-width: 720px)');
39
+
40
+ const {
41
+ getState,
42
+ options: {
43
+ enableToolbarInternalActions,
44
+ icons: { ChevronLeftIcon, ChevronRightIcon, FirstPageIcon, LastPageIcon },
45
+ id,
46
+ localization,
47
+ muiPaginationProps,
48
+ paginationDisplayMode,
49
+ },
50
+ } = table;
51
+ const {
52
+ pagination: { pageIndex = 0, pageSize = 10 },
53
+ } = getState();
54
+
55
+ const paginationProps = {
56
+ ...parseFromValuesOrFunc(muiPaginationProps, {
57
+ table,
58
+ }),
59
+ ...rest,
60
+ };
61
+
62
+ const totalRowCount = table.getRowCount();
63
+ const numberOfPages = table.getPageCount();
64
+ const showFirstLastPageButtons = numberOfPages > 2;
65
+ const firstRowIndex = pageIndex * pageSize;
66
+ const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount);
67
+
68
+ const {
69
+ disabled = false,
70
+ rowsPerPageOptions = defaultRowsPerPage,
71
+ SelectProps = {},
72
+ showFirstButton = showFirstLastPageButtons,
73
+ showLastButton = showFirstLastPageButtons,
74
+ showRowsPerPage = true,
75
+ ...restPaginationProps
76
+ } = paginationProps ?? {};
77
+
78
+ const disableBack = pageIndex <= 0 || disabled;
79
+ const disableNext = lastRowIndex >= totalRowCount || disabled;
80
+
81
+ if (isMobile && SelectProps?.native !== false) {
82
+ SelectProps.native = true;
83
+ }
84
+
85
+ const tooltipProps = getCommonTooltipProps();
86
+
87
+ return (
88
+ <Box
89
+ className="MuiTablePagination-root"
90
+ sx={{
91
+ alignItems: 'center',
92
+ display: 'flex',
93
+ flexWrap: 'wrap',
94
+ gap: '8px',
95
+ justifyContent: { md: 'space-between', sm: 'center' },
96
+ justifySelf: 'flex-end',
97
+ mt:
98
+ position === 'top' && enableToolbarInternalActions
99
+ ? '3rem'
100
+ : undefined,
101
+ position: 'relative',
102
+ px: '8px',
103
+ py: '12px',
104
+ zIndex: 2,
105
+ }}
106
+ >
107
+ {showRowsPerPage && (
108
+ <Box sx={{ alignItems: 'center', display: 'flex', gap: '8px' }}>
109
+ <InputLabel htmlFor={`mrt-rows-per-page-${id}`} sx={{ mb: 0 }}>
110
+ {localization.rowsPerPage}
111
+ </InputLabel>
112
+ <Select
113
+ disabled={disabled}
114
+ disableUnderline
115
+ inputProps={{
116
+ 'aria-label': localization.rowsPerPage,
117
+ id: `mrt-rows-per-page-${id}`,
118
+ }}
119
+ label={localization.rowsPerPage}
120
+ MenuProps={{ disableScrollLock: true }}
121
+ onChange={(event) =>
122
+ table.setPageSize(+(event.target.value as any))
123
+ }
124
+ sx={{ mb: 0 }}
125
+ value={pageSize}
126
+ variant="standard"
127
+ {...SelectProps}
128
+ >
129
+ {rowsPerPageOptions.map((option) => {
130
+ const value = typeof option !== 'number' ? option.value : option;
131
+ const label =
132
+ typeof option !== 'number' ? option.label : `${option}`;
133
+ return (
134
+ SelectProps?.children ??
135
+ (SelectProps?.native ? (
136
+ <option key={value} value={value}>
137
+ {label}
138
+ </option>
139
+ ) : (
140
+ <MenuItem key={value} sx={{ m: 0 }} value={value}>
141
+ {label}
142
+ </MenuItem>
143
+ ))
144
+ );
145
+ })}
146
+ </Select>
147
+ </Box>
148
+ )}
149
+ {paginationDisplayMode === 'pages' ? (
150
+ <Pagination
151
+ count={numberOfPages}
152
+ disabled={disabled}
153
+ onChange={(_e, newPageIndex) => table.setPageIndex(newPageIndex - 1)}
154
+ page={pageIndex + 1}
155
+ renderItem={(item) => (
156
+ <PaginationItem
157
+ slots={{
158
+ first: FirstPageIcon,
159
+ last: LastPageIcon,
160
+ next: ChevronRightIcon,
161
+ previous: ChevronLeftIcon,
162
+ }}
163
+ {...item}
164
+ />
165
+ )}
166
+ showFirstButton={showFirstButton}
167
+ showLastButton={showLastButton}
168
+ {...restPaginationProps}
169
+ />
170
+ ) : paginationDisplayMode === 'default' ? (
171
+ <>
172
+ <Typography
173
+ align="center"
174
+ component="span"
175
+ sx={{ m: '0 4px', minWidth: '8ch' }}
176
+ variant="body2"
177
+ >{`${
178
+ lastRowIndex === 0
179
+ ? 0
180
+ : (firstRowIndex + 1).toLocaleString(localization.language)
181
+ }-${lastRowIndex.toLocaleString(localization.language)} ${
182
+ localization.of
183
+ } ${totalRowCount.toLocaleString(localization.language)}`}</Typography>
184
+ <Box sx={{
185
+ gap: "xs"
186
+ }}>
187
+ {showFirstButton && (
188
+ <Tooltip {...tooltipProps} title={localization.goToFirstPage}>
189
+ <span>
190
+ <IconButton
191
+ aria-label={localization.goToFirstPage}
192
+ disabled={disableBack}
193
+ onClick={() => table.firstPage()}
194
+ size="small"
195
+ >
196
+ <FirstPageIcon {...flipIconStyles(theme)} />
197
+ </IconButton>
198
+ </span>
199
+ </Tooltip>
200
+ )}
201
+ <Tooltip {...tooltipProps} title={localization.goToPreviousPage}>
202
+ <span>
203
+ <IconButton
204
+ aria-label={localization.goToPreviousPage}
205
+ disabled={disableBack}
206
+ onClick={() => table.previousPage()}
207
+ size="small"
208
+ >
209
+ <ChevronLeftIcon {...flipIconStyles(theme)} />
210
+ </IconButton>
211
+ </span>
212
+ </Tooltip>
213
+ <Tooltip {...tooltipProps} title={localization.goToNextPage}>
214
+ <span>
215
+ <IconButton
216
+ aria-label={localization.goToNextPage}
217
+ disabled={disableNext}
218
+ onClick={() => table.nextPage()}
219
+ size="small"
220
+ >
221
+ <ChevronRightIcon {...flipIconStyles(theme)} />
222
+ </IconButton>
223
+ </span>
224
+ </Tooltip>
225
+ {showLastButton && (
226
+ <Tooltip {...tooltipProps} title={localization.goToLastPage}>
227
+ <span>
228
+ <IconButton
229
+ aria-label={localization.goToLastPage}
230
+ disabled={disableNext}
231
+ onClick={() => table.lastPage()}
232
+ size="small"
233
+ >
234
+ <LastPageIcon {...flipIconStyles(theme)} />
235
+ </IconButton>
236
+ </span>
237
+ </Tooltip>
238
+ )}
239
+ </Box>
240
+ </>
241
+ ) : null}
242
+ </Box>
243
+ );
244
+ };