@novastera-oss/material-react-table 4.0.0-beta.7

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