@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,306 @@
1
+ import { type DragEvent, memo, useMemo, useRef } from 'react';
2
+ import { type VirtualItem } from '@tanstack/react-virtual';
3
+ import TableRow, { type TableRowProps } from '@mui/material/TableRow';
4
+ import {
5
+ type Theme,
6
+ alpha,
7
+ darken,
8
+ lighten,
9
+ useTheme,
10
+ } from '@mui/material/styles';
11
+ import { MRT_TableBodyCell, Memo_MRT_TableBodyCell } from './MRT_TableBodyCell';
12
+ import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
13
+ import {
14
+ type MRT_Cell,
15
+ type MRT_ColumnVirtualizer,
16
+ type MRT_Row,
17
+ type MRT_RowData,
18
+ type MRT_RowVirtualizer,
19
+ type MRT_TableInstance,
20
+ type MRT_VirtualItem,
21
+ } from '../../types';
22
+ import { getIsRowSelected } from '../../utils/row.utils';
23
+ import {
24
+ commonCellBeforeAfterStyles,
25
+ getCommonPinnedCellStyles,
26
+ } from '../../utils/style.utils';
27
+ import { parseFromValuesOrFunc } from '../../utils/utils';
28
+
29
+ export interface MRT_TableBodyRowProps<TData extends MRT_RowData>
30
+ extends TableRowProps {
31
+ columnVirtualizer?: MRT_ColumnVirtualizer;
32
+ numRows?: number;
33
+ pinnedRowIds?: string[];
34
+ row: MRT_Row<TData>;
35
+ rowVirtualizer?: MRT_RowVirtualizer;
36
+ staticRowIndex: number;
37
+ table: MRT_TableInstance<TData>;
38
+ virtualRow?: VirtualItem;
39
+ }
40
+
41
+ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
42
+ columnVirtualizer,
43
+ numRows,
44
+ pinnedRowIds,
45
+ row,
46
+ rowVirtualizer,
47
+ staticRowIndex,
48
+ table,
49
+ virtualRow,
50
+ ...rest
51
+ }: MRT_TableBodyRowProps<TData>) => {
52
+ const theme = useTheme();
53
+
54
+ const {
55
+ getState,
56
+ options: {
57
+ enableRowOrdering,
58
+ enableRowPinning,
59
+ enableStickyFooter,
60
+ enableStickyHeader,
61
+ layoutMode,
62
+ memoMode,
63
+ mrtTheme: {
64
+ baseBackgroundColor,
65
+ pinnedRowBackgroundColor,
66
+ selectedRowBackgroundColor,
67
+ },
68
+ muiTableBodyRowProps,
69
+ renderDetailPanel,
70
+ rowPinningDisplayMode,
71
+ },
72
+ refs: { tableFooterRef, tableHeadRef },
73
+ setHoveredRow,
74
+ } = table;
75
+ const {
76
+ density,
77
+ draggingColumn,
78
+ draggingRow,
79
+ editingCell,
80
+ editingRow,
81
+ hoveredRow,
82
+ isFullScreen,
83
+ rowPinning,
84
+ } = getState();
85
+
86
+ const visibleCells = row.getVisibleCells();
87
+
88
+ const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } =
89
+ columnVirtualizer ?? {};
90
+
91
+ const isRowSelected = getIsRowSelected({ row, table });
92
+ const isRowPinned = enableRowPinning && row.getIsPinned();
93
+ const isDraggingRow = draggingRow?.id === row.id;
94
+ const isHoveredRow = hoveredRow?.id === row.id;
95
+
96
+ const tableRowProps = {
97
+ ...parseFromValuesOrFunc(muiTableBodyRowProps, {
98
+ row,
99
+ staticRowIndex,
100
+ table,
101
+ }),
102
+ ...rest,
103
+ };
104
+
105
+ const [bottomPinnedIndex, topPinnedIndex] = useMemo(() => {
106
+ if (
107
+ !enableRowPinning ||
108
+ !rowPinningDisplayMode?.includes('sticky') ||
109
+ !pinnedRowIds ||
110
+ !row.getIsPinned()
111
+ )
112
+ return [];
113
+ return [
114
+ [...pinnedRowIds].reverse().indexOf(row.id),
115
+ pinnedRowIds.indexOf(row.id),
116
+ ];
117
+ }, [pinnedRowIds, rowPinning]);
118
+
119
+ const tableHeadHeight =
120
+ ((enableStickyHeader || isFullScreen) &&
121
+ tableHeadRef.current?.clientHeight) ||
122
+ 0;
123
+ const tableFooterHeight =
124
+ (enableStickyFooter && tableFooterRef.current?.clientHeight) || 0;
125
+
126
+ const sx = (
127
+ Array.isArray(tableRowProps?.sx)
128
+ ? tableRowProps?.sx[0]
129
+ : typeof tableRowProps?.sx === 'function'
130
+ ? tableRowProps?.sx(theme)
131
+ : tableRowProps?.sx
132
+ ) as any;
133
+
134
+ const defaultRowHeight =
135
+ density === 'compact' ? 37 : density === 'comfortable' ? 53 : 69;
136
+
137
+ const customRowHeight =
138
+ parseInt(
139
+ (tableRowProps?.style?.height as string) ?? (sx?.height as string),
140
+ 10,
141
+ ) || undefined;
142
+
143
+ const rowHeight = customRowHeight || defaultRowHeight;
144
+
145
+ const handleDragEnter = (_e: DragEvent) => {
146
+ if (enableRowOrdering && draggingRow) {
147
+ setHoveredRow(row);
148
+ }
149
+ };
150
+
151
+ const handleDragOver = (e: DragEvent) => {
152
+ e.preventDefault();
153
+ };
154
+
155
+ const rowRef = useRef<HTMLTableRowElement | null>(null);
156
+
157
+ const cellHighlightColor = isRowSelected
158
+ ? selectedRowBackgroundColor
159
+ : isRowPinned
160
+ ? pinnedRowBackgroundColor
161
+ : undefined;
162
+
163
+ const cellHighlightColorHover =
164
+ tableRowProps?.hover !== false
165
+ ? isRowSelected
166
+ ? cellHighlightColor
167
+ : theme.palette.mode === 'dark'
168
+ ? `${lighten(baseBackgroundColor, 0.3)}`
169
+ : `${darken(baseBackgroundColor, 0.3)}`
170
+ : undefined;
171
+
172
+ return (
173
+ <>
174
+ <TableRow
175
+ data-index={renderDetailPanel ? staticRowIndex * 2 : staticRowIndex}
176
+ data-pinned={!!isRowPinned || undefined}
177
+ data-selected={isRowSelected || undefined}
178
+ onDragEnter={handleDragEnter}
179
+ onDragOver={handleDragOver}
180
+ ref={(node: HTMLTableRowElement) => {
181
+ if (node) {
182
+ rowRef.current = node;
183
+ rowVirtualizer?.measureElement(node);
184
+ }
185
+ }}
186
+ selected={isRowSelected}
187
+ {...tableRowProps}
188
+ style={{
189
+ transform: virtualRow
190
+ ? `translateY(${virtualRow.start}px)`
191
+ : undefined,
192
+ ...tableRowProps?.style,
193
+ }}
194
+ sx={[
195
+ (theme: Theme) => ({
196
+ '&:hover td:after': cellHighlightColorHover
197
+ ? {
198
+ backgroundColor: alpha(cellHighlightColorHover, 0.3),
199
+ ...commonCellBeforeAfterStyles,
200
+ }
201
+ : undefined,
202
+ backgroundColor: `${baseBackgroundColor} !important`,
203
+ bottom:
204
+ !virtualRow && bottomPinnedIndex !== undefined && isRowPinned
205
+ ? `${
206
+ bottomPinnedIndex * rowHeight +
207
+ (enableStickyFooter ? tableFooterHeight - 1 : 0)
208
+ }px`
209
+ : undefined,
210
+ boxSizing: 'border-box',
211
+ display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
212
+ opacity: isRowPinned
213
+ ? 0.97
214
+ : isDraggingRow || isHoveredRow
215
+ ? 0.5
216
+ : 1,
217
+ position: virtualRow
218
+ ? 'absolute'
219
+ : rowPinningDisplayMode?.includes('sticky') && isRowPinned
220
+ ? 'sticky'
221
+ : 'relative',
222
+ td: {
223
+ ...getCommonPinnedCellStyles({ table, theme }),
224
+ },
225
+ 'td:after': cellHighlightColor
226
+ ? {
227
+ backgroundColor: cellHighlightColor,
228
+ ...commonCellBeforeAfterStyles,
229
+ }
230
+ : undefined,
231
+ top: virtualRow
232
+ ? 0
233
+ : topPinnedIndex !== undefined && isRowPinned
234
+ ? `${
235
+ topPinnedIndex * rowHeight +
236
+ (enableStickyHeader || isFullScreen
237
+ ? tableHeadHeight - 1
238
+ : 0)
239
+ }px`
240
+ : undefined,
241
+ transition: virtualRow ? 'none' : 'all 150ms ease-in-out',
242
+ width: '100%',
243
+ zIndex:
244
+ rowPinningDisplayMode?.includes('sticky') && isRowPinned ? 2 : 0,
245
+ }),
246
+ ...(Array.isArray(tableRowProps?.sx)
247
+ ? tableRowProps.sx
248
+ : [tableRowProps?.sx]),
249
+ ]}
250
+ >
251
+ {virtualPaddingLeft ? (
252
+ <td style={{ display: 'flex', width: virtualPaddingLeft }} />
253
+ ) : null}
254
+ {(virtualColumns ?? visibleCells).map(
255
+ (cellOrVirtualCell, staticColumnIndex) => {
256
+ let cell = cellOrVirtualCell as MRT_Cell<TData>;
257
+ if (columnVirtualizer) {
258
+ staticColumnIndex = (cellOrVirtualCell as MRT_VirtualItem).index;
259
+ cell = visibleCells[staticColumnIndex];
260
+ }
261
+ const props = {
262
+ cell,
263
+ numRows,
264
+ rowRef,
265
+ staticColumnIndex,
266
+ staticRowIndex,
267
+ table,
268
+ };
269
+ const key = `${cell.id}-${staticRowIndex}`;
270
+ return cell ? (
271
+ memoMode === 'cells' &&
272
+ cell.column.columnDef.columnDefType === 'data' &&
273
+ !draggingColumn &&
274
+ !draggingRow &&
275
+ editingCell?.id !== cell.id &&
276
+ editingRow?.id !== row.id ? (
277
+ <Memo_MRT_TableBodyCell key={key} {...props} />
278
+ ) : (
279
+ <MRT_TableBodyCell key={key} {...props} />
280
+ )
281
+ ) : null;
282
+ },
283
+ )}
284
+ {virtualPaddingRight ? (
285
+ <td style={{ display: 'flex', width: virtualPaddingRight }} />
286
+ ) : null}
287
+ </TableRow>
288
+ {renderDetailPanel && !row.getIsGrouped() && (
289
+ <MRT_TableDetailPanel
290
+ parentRowRef={rowRef}
291
+ row={row}
292
+ rowVirtualizer={rowVirtualizer}
293
+ staticRowIndex={staticRowIndex}
294
+ table={table}
295
+ virtualRow={virtualRow}
296
+ />
297
+ )}
298
+ </>
299
+ );
300
+ };
301
+
302
+ export const Memo_MRT_TableBodyRow = memo(
303
+ MRT_TableBodyRow,
304
+ (prev, next) =>
305
+ prev.row === next.row && prev.staticRowIndex === next.staticRowIndex,
306
+ ) as typeof MRT_TableBodyRow;
@@ -0,0 +1,61 @@
1
+ import { type DragEvent, type RefObject } from 'react';
2
+ import { type IconButtonProps } from '@mui/material/IconButton';
3
+ import {
4
+ type MRT_Row,
5
+ type MRT_RowData,
6
+ type MRT_TableInstance,
7
+ } from '../../types';
8
+ import { parseFromValuesOrFunc } from '../../utils/utils';
9
+ import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
10
+
11
+ export interface MRT_TableBodyRowGrabHandleProps<TData extends MRT_RowData>
12
+ extends IconButtonProps {
13
+ row: MRT_Row<TData>;
14
+ rowRef: RefObject<HTMLTableRowElement | null>;
15
+ table: MRT_TableInstance<TData>;
16
+ }
17
+
18
+ export const MRT_TableBodyRowGrabHandle = <TData extends MRT_RowData>({
19
+ row,
20
+ rowRef,
21
+ table,
22
+ ...rest
23
+ }: MRT_TableBodyRowGrabHandleProps<TData>) => {
24
+ const {
25
+ options: { muiRowDragHandleProps },
26
+ } = table;
27
+
28
+ const iconButtonProps = {
29
+ ...parseFromValuesOrFunc(muiRowDragHandleProps, {
30
+ row,
31
+ table,
32
+ }),
33
+ ...rest,
34
+ };
35
+
36
+ const handleDragStart = (event: DragEvent<HTMLButtonElement>) => {
37
+ iconButtonProps?.onDragStart?.(event);
38
+ try {
39
+ event.dataTransfer.setDragImage(rowRef.current as HTMLElement, 0, 0);
40
+ } catch (e) {
41
+ console.error(e);
42
+ }
43
+ table.setDraggingRow(row as any);
44
+ };
45
+
46
+ const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
47
+ iconButtonProps?.onDragEnd?.(event);
48
+ table.setDraggingRow(null);
49
+ table.setHoveredRow(null);
50
+ };
51
+
52
+ return (
53
+ <MRT_GrabHandleButton
54
+ {...iconButtonProps}
55
+ location="row"
56
+ onDragEnd={handleDragEnd}
57
+ onDragStart={handleDragStart}
58
+ table={table}
59
+ />
60
+ );
61
+ };
@@ -0,0 +1,58 @@
1
+ import Box from '@mui/material/Box';
2
+ import { type IconButtonProps } from '@mui/material/IconButton';
3
+ import {
4
+ type MRT_Row,
5
+ type MRT_RowData,
6
+ type MRT_TableInstance,
7
+ } from '../../types';
8
+ import { parseFromValuesOrFunc } from '../../utils/utils';
9
+ import { MRT_RowPinButton } from '../buttons/MRT_RowPinButton';
10
+
11
+ export interface MRT_TableBodyRowPinButtonProps<TData extends MRT_RowData>
12
+ extends IconButtonProps {
13
+ row: MRT_Row<TData>;
14
+ table: MRT_TableInstance<TData>;
15
+ }
16
+
17
+ export const MRT_TableBodyRowPinButton = <TData extends MRT_RowData>({
18
+ row,
19
+ table,
20
+ ...rest
21
+ }: MRT_TableBodyRowPinButtonProps<TData>) => {
22
+ const {
23
+ getState,
24
+ options: { enableRowPinning, rowPinningDisplayMode },
25
+ } = table;
26
+ const { density } = getState();
27
+
28
+ const canPin = parseFromValuesOrFunc(enableRowPinning, row as any);
29
+
30
+ if (!canPin) return null;
31
+
32
+ const rowPinButtonProps = {
33
+ row,
34
+ table,
35
+ ...rest,
36
+ };
37
+
38
+ if (rowPinningDisplayMode === 'top-and-bottom' && !row.getIsPinned()) {
39
+ return (
40
+ <Box
41
+ sx={{
42
+ display: 'flex',
43
+ flexDirection: density === 'compact' ? 'row' : 'column',
44
+ }}
45
+ >
46
+ <MRT_RowPinButton pinningPosition="top" {...rowPinButtonProps} />
47
+ <MRT_RowPinButton pinningPosition="bottom" {...rowPinButtonProps} />
48
+ </Box>
49
+ );
50
+ }
51
+
52
+ return (
53
+ <MRT_RowPinButton
54
+ pinningPosition={rowPinningDisplayMode === 'bottom' ? 'bottom' : 'top'}
55
+ {...rowPinButtonProps}
56
+ />
57
+ );
58
+ };
@@ -0,0 +1,118 @@
1
+ import { type RefObject } from 'react';
2
+ import Collapse from '@mui/material/Collapse';
3
+ import TableCell, { type TableCellProps } from '@mui/material/TableCell';
4
+ import TableRow from '@mui/material/TableRow';
5
+ import {
6
+ type MRT_Row,
7
+ type MRT_RowData,
8
+ type MRT_RowVirtualizer,
9
+ type MRT_TableInstance,
10
+ type MRT_VirtualItem,
11
+ } from '../../types';
12
+ import { parseFromValuesOrFunc } from '../../utils/utils';
13
+
14
+ export interface MRT_TableDetailPanelProps<TData extends MRT_RowData>
15
+ extends TableCellProps {
16
+ parentRowRef: RefObject<HTMLTableRowElement | null>;
17
+ row: MRT_Row<TData>;
18
+ rowVirtualizer?: MRT_RowVirtualizer;
19
+ staticRowIndex: number;
20
+ table: MRT_TableInstance<TData>;
21
+ virtualRow?: MRT_VirtualItem;
22
+ }
23
+
24
+ export const MRT_TableDetailPanel = <TData extends MRT_RowData>({
25
+ parentRowRef,
26
+ row,
27
+ rowVirtualizer,
28
+ staticRowIndex,
29
+ table,
30
+ virtualRow,
31
+ ...rest
32
+ }: MRT_TableDetailPanelProps<TData>) => {
33
+ const {
34
+ getState,
35
+ getVisibleLeafColumns,
36
+ options: {
37
+ layoutMode,
38
+ mrtTheme: { baseBackgroundColor },
39
+ muiDetailPanelProps,
40
+ muiTableBodyRowProps,
41
+ renderDetailPanel,
42
+ },
43
+ } = table;
44
+ const { isLoading } = getState();
45
+
46
+ const tableRowProps = parseFromValuesOrFunc(muiTableBodyRowProps, {
47
+ isDetailPanel: true,
48
+ row,
49
+ staticRowIndex,
50
+ table,
51
+ });
52
+
53
+ const tableCellProps = {
54
+ ...parseFromValuesOrFunc(muiDetailPanelProps, {
55
+ row,
56
+ table,
57
+ }),
58
+ ...rest,
59
+ };
60
+
61
+ const DetailPanel = !isLoading && renderDetailPanel?.({ row, table });
62
+
63
+ return (
64
+ <TableRow
65
+ className="Mui-TableBodyCell-DetailPanel"
66
+ data-index={renderDetailPanel ? staticRowIndex * 2 + 1 : staticRowIndex}
67
+ ref={(node: HTMLTableRowElement) => {
68
+ if (node) {
69
+ rowVirtualizer?.measureElement?.(node);
70
+ }
71
+ }}
72
+ {...tableRowProps}
73
+ sx={[
74
+ {
75
+ display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
76
+ position: virtualRow ? 'absolute' : undefined,
77
+ top: virtualRow
78
+ ? `${parentRowRef.current?.getBoundingClientRect()?.height}px`
79
+ : undefined,
80
+ transform: virtualRow
81
+ ? `translateY(${virtualRow?.start}px)`
82
+ : undefined,
83
+ width: '100%',
84
+ },
85
+ ...(Array.isArray(tableRowProps?.sx)
86
+ ? tableRowProps.sx
87
+ : [tableRowProps?.sx]),
88
+ ]}
89
+ >
90
+ <TableCell
91
+ className="Mui-TableBodyCell-DetailPanel"
92
+ colSpan={getVisibleLeafColumns().length}
93
+ {...tableCellProps}
94
+ sx={[
95
+ {
96
+ backgroundColor: virtualRow ? baseBackgroundColor : undefined,
97
+ borderBottom: !row.getIsExpanded() ? 'none' : undefined,
98
+ display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
99
+ py: !!DetailPanel && row.getIsExpanded() ? '1rem' : 0,
100
+ transition: !virtualRow ? 'all 150ms ease-in-out' : undefined,
101
+ width: `100%`,
102
+ },
103
+ ...(Array.isArray(tableCellProps?.sx)
104
+ ? tableCellProps.sx
105
+ : [tableCellProps?.sx]),
106
+ ]}
107
+ >
108
+ {virtualRow ? (
109
+ row.getIsExpanded() && DetailPanel
110
+ ) : (
111
+ <Collapse in={row.getIsExpanded()} mountOnEnter unmountOnExit>
112
+ {DetailPanel}
113
+ </Collapse>
114
+ )}
115
+ </TableCell>
116
+ </TableRow>
117
+ );
118
+ };
@@ -0,0 +1,73 @@
1
+ import Box, { type BoxProps } from '@mui/material/Box';
2
+ import IconButton from '@mui/material/IconButton';
3
+ import Tooltip from '@mui/material/Tooltip';
4
+ import {
5
+ type MRT_Column,
6
+ type MRT_RowData,
7
+ type MRT_TableInstance,
8
+ } from '../../types';
9
+
10
+ export interface MRT_ColumnPinningButtonsProps<TData extends MRT_RowData>
11
+ extends BoxProps {
12
+ column: MRT_Column<TData>;
13
+ table: MRT_TableInstance<TData>;
14
+ }
15
+
16
+ export const MRT_ColumnPinningButtons = <TData extends MRT_RowData>({
17
+ column,
18
+ table,
19
+ ...rest
20
+ }: MRT_ColumnPinningButtonsProps<TData>) => {
21
+ const {
22
+ options: {
23
+ icons: { PushPinIcon },
24
+ localization,
25
+ },
26
+ } = table;
27
+
28
+ const handlePinColumn = (pinDirection: 'left' | 'right' | false) => {
29
+ column.pin(pinDirection);
30
+ };
31
+
32
+ return (
33
+ <Box
34
+ {...rest}
35
+ sx={[
36
+ {
37
+ minWidth: '70px',
38
+ textAlign: 'center',
39
+ },
40
+ ...(Array.isArray(rest?.sx) ? rest.sx : [rest?.sx]),
41
+ ]}
42
+ >
43
+ {column.getIsPinned() ? (
44
+ <Tooltip title={localization.unpin}>
45
+ <IconButton onClick={() => handlePinColumn(false)} size="small">
46
+ <PushPinIcon />
47
+ </IconButton>
48
+ </Tooltip>
49
+ ) : (
50
+ <>
51
+ <Tooltip title={localization.pinToLeft}>
52
+ <IconButton onClick={() => handlePinColumn('left')} size="small">
53
+ <PushPinIcon
54
+ style={{
55
+ transform: 'rotate(90deg)',
56
+ }}
57
+ />
58
+ </IconButton>
59
+ </Tooltip>
60
+ <Tooltip title={localization.pinToRight}>
61
+ <IconButton onClick={() => handlePinColumn('right')} size="small">
62
+ <PushPinIcon
63
+ style={{
64
+ transform: 'rotate(-90deg)',
65
+ }}
66
+ />
67
+ </IconButton>
68
+ </Tooltip>
69
+ </>
70
+ )}
71
+ </Box>
72
+ );
73
+ };
@@ -0,0 +1,91 @@
1
+ import { type MouseEvent, useState } from 'react';
2
+ import Button, { type ButtonProps } from '@mui/material/Button';
3
+ import Tooltip from '@mui/material/Tooltip';
4
+ import {
5
+ type MRT_Cell,
6
+ type MRT_RowData,
7
+ type MRT_TableInstance,
8
+ } from '../../types';
9
+ import { getCommonTooltipProps } from '../../utils/style.utils';
10
+ import { parseFromValuesOrFunc } from '../../utils/utils';
11
+
12
+ export interface MRT_CopyButtonProps<TData extends MRT_RowData>
13
+ extends ButtonProps {
14
+ cell: MRT_Cell<TData>;
15
+ table: MRT_TableInstance<TData>;
16
+ }
17
+
18
+ export const MRT_CopyButton = <TData extends MRT_RowData>({
19
+ cell,
20
+ table,
21
+ ...rest
22
+ }: MRT_CopyButtonProps<TData>) => {
23
+ const {
24
+ options: { localization, muiCopyButtonProps },
25
+ } = table;
26
+ const { column, row } = cell;
27
+ const { columnDef } = column;
28
+
29
+ const [copied, setCopied] = useState(false);
30
+
31
+ const handleCopy = (event: MouseEvent, text: unknown) => {
32
+ event.stopPropagation();
33
+ navigator.clipboard.writeText(text as string);
34
+ setCopied(true);
35
+ setTimeout(() => setCopied(false), 4000);
36
+ };
37
+
38
+ const buttonProps = {
39
+ ...parseFromValuesOrFunc(muiCopyButtonProps, {
40
+ cell,
41
+ column,
42
+ row,
43
+ table,
44
+ }),
45
+ ...parseFromValuesOrFunc(columnDef.muiCopyButtonProps, {
46
+ cell,
47
+ column,
48
+ row,
49
+ table,
50
+ }),
51
+ ...rest,
52
+ };
53
+
54
+ return (
55
+ <Tooltip
56
+ {...getCommonTooltipProps('top')}
57
+ title={
58
+ buttonProps?.title ??
59
+ (copied ? localization.copiedToClipboard : localization.clickToCopy)
60
+ }
61
+ >
62
+ <Button
63
+ onClick={(e) => handleCopy(e, cell.getValue())}
64
+ size="small"
65
+ type="button"
66
+ variant="text"
67
+ {...buttonProps}
68
+ sx={[
69
+ {
70
+ backgroundColor: 'transparent',
71
+ border: 'none',
72
+ color: 'inherit',
73
+ cursor: 'copy',
74
+ fontFamily: 'inherit',
75
+ fontSize: 'inherit',
76
+ letterSpacing: 'inherit',
77
+ m: '-0.25rem',
78
+ minWidth: 'unset',
79
+ py: 0,
80
+ textAlign: 'inherit',
81
+ textTransform: 'inherit',
82
+ },
83
+ ...(Array.isArray(buttonProps?.sx)
84
+ ? buttonProps.sx
85
+ : [buttonProps?.sx]),
86
+ ]}
87
+ title={undefined}
88
+ />
89
+ </Tooltip>
90
+ );
91
+ };