@lminii/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 (349) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +234 -0
  3. package/dist/index.d.mts +2408 -0
  4. package/dist/index.d.ts +2408 -0
  5. package/dist/index.js +4825 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +4631 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/locales/ar/index.d.mts +3 -0
  10. package/locales/ar/index.d.ts +3 -0
  11. package/locales/ar/index.js +100 -0
  12. package/locales/ar/index.mjs +96 -0
  13. package/locales/ar/package.json +6 -0
  14. package/locales/az/index.d.mts +3 -0
  15. package/locales/az/index.d.ts +3 -0
  16. package/locales/az/index.js +100 -0
  17. package/locales/az/index.mjs +96 -0
  18. package/locales/az/package.json +6 -0
  19. package/locales/bg/index.d.mts +3 -0
  20. package/locales/bg/index.d.ts +3 -0
  21. package/locales/bg/index.js +100 -0
  22. package/locales/bg/index.mjs +96 -0
  23. package/locales/bg/package.json +6 -0
  24. package/locales/cs/index.d.mts +3 -0
  25. package/locales/cs/index.d.ts +3 -0
  26. package/locales/cs/index.js +100 -0
  27. package/locales/cs/index.mjs +96 -0
  28. package/locales/cs/package.json +6 -0
  29. package/locales/da/index.d.mts +3 -0
  30. package/locales/da/index.d.ts +3 -0
  31. package/locales/da/index.js +100 -0
  32. package/locales/da/index.mjs +96 -0
  33. package/locales/da/package.json +6 -0
  34. package/locales/de/index.d.mts +3 -0
  35. package/locales/de/index.d.ts +3 -0
  36. package/locales/de/index.js +100 -0
  37. package/locales/de/index.mjs +96 -0
  38. package/locales/de/package.json +6 -0
  39. package/locales/el/index.d.mts +3 -0
  40. package/locales/el/index.d.ts +3 -0
  41. package/locales/el/index.js +100 -0
  42. package/locales/el/index.mjs +96 -0
  43. package/locales/el/package.json +6 -0
  44. package/locales/en/index.d.mts +3 -0
  45. package/locales/en/index.d.ts +3 -0
  46. package/locales/en/index.js +100 -0
  47. package/locales/en/index.mjs +96 -0
  48. package/locales/en/package.json +6 -0
  49. package/locales/es/index.d.mts +3 -0
  50. package/locales/es/index.d.ts +3 -0
  51. package/locales/es/index.js +100 -0
  52. package/locales/es/index.mjs +96 -0
  53. package/locales/es/package.json +6 -0
  54. package/locales/et/index.d.mts +3 -0
  55. package/locales/et/index.d.ts +3 -0
  56. package/locales/et/index.js +100 -0
  57. package/locales/et/index.mjs +96 -0
  58. package/locales/et/package.json +6 -0
  59. package/locales/fa/index.d.mts +3 -0
  60. package/locales/fa/index.d.ts +3 -0
  61. package/locales/fa/index.js +100 -0
  62. package/locales/fa/index.mjs +96 -0
  63. package/locales/fa/package.json +6 -0
  64. package/locales/fi/index.d.mts +3 -0
  65. package/locales/fi/index.d.ts +3 -0
  66. package/locales/fi/index.js +100 -0
  67. package/locales/fi/index.mjs +96 -0
  68. package/locales/fi/package.json +6 -0
  69. package/locales/fr/index.d.mts +3 -0
  70. package/locales/fr/index.d.ts +3 -0
  71. package/locales/fr/index.js +100 -0
  72. package/locales/fr/index.mjs +96 -0
  73. package/locales/fr/package.json +6 -0
  74. package/locales/he/index.d.mts +3 -0
  75. package/locales/he/index.d.ts +3 -0
  76. package/locales/he/index.js +100 -0
  77. package/locales/he/index.mjs +96 -0
  78. package/locales/he/package.json +6 -0
  79. package/locales/hr/index.d.mts +3 -0
  80. package/locales/hr/index.d.ts +3 -0
  81. package/locales/hr/index.js +100 -0
  82. package/locales/hr/index.mjs +96 -0
  83. package/locales/hr/package.json +6 -0
  84. package/locales/hu/index.d.mts +3 -0
  85. package/locales/hu/index.d.ts +3 -0
  86. package/locales/hu/index.js +100 -0
  87. package/locales/hu/index.mjs +96 -0
  88. package/locales/hu/package.json +6 -0
  89. package/locales/hy/index.d.mts +3 -0
  90. package/locales/hy/index.d.ts +3 -0
  91. package/locales/hy/index.js +100 -0
  92. package/locales/hy/index.mjs +96 -0
  93. package/locales/hy/package.json +6 -0
  94. package/locales/id/index.d.mts +3 -0
  95. package/locales/id/index.d.ts +3 -0
  96. package/locales/id/index.js +100 -0
  97. package/locales/id/index.mjs +96 -0
  98. package/locales/id/package.json +6 -0
  99. package/locales/it/index.d.mts +3 -0
  100. package/locales/it/index.d.ts +3 -0
  101. package/locales/it/index.js +100 -0
  102. package/locales/it/index.mjs +96 -0
  103. package/locales/it/package.json +6 -0
  104. package/locales/ja/index.d.mts +3 -0
  105. package/locales/ja/index.d.ts +3 -0
  106. package/locales/ja/index.js +100 -0
  107. package/locales/ja/index.mjs +96 -0
  108. package/locales/ja/package.json +6 -0
  109. package/locales/ko/index.d.mts +3 -0
  110. package/locales/ko/index.d.ts +3 -0
  111. package/locales/ko/index.js +100 -0
  112. package/locales/ko/index.mjs +96 -0
  113. package/locales/ko/package.json +6 -0
  114. package/locales/nl/index.d.mts +3 -0
  115. package/locales/nl/index.d.ts +3 -0
  116. package/locales/nl/index.js +100 -0
  117. package/locales/nl/index.mjs +96 -0
  118. package/locales/nl/package.json +6 -0
  119. package/locales/no/index.d.mts +3 -0
  120. package/locales/no/index.d.ts +3 -0
  121. package/locales/no/index.js +100 -0
  122. package/locales/no/index.mjs +96 -0
  123. package/locales/no/package.json +6 -0
  124. package/locales/np/index.d.mts +3 -0
  125. package/locales/np/index.d.ts +3 -0
  126. package/locales/np/index.js +100 -0
  127. package/locales/np/index.mjs +96 -0
  128. package/locales/np/package.json +6 -0
  129. package/locales/pl/index.d.mts +3 -0
  130. package/locales/pl/index.d.ts +3 -0
  131. package/locales/pl/index.js +100 -0
  132. package/locales/pl/index.mjs +96 -0
  133. package/locales/pl/package.json +6 -0
  134. package/locales/pt/index.d.mts +3 -0
  135. package/locales/pt/index.d.ts +3 -0
  136. package/locales/pt/index.js +100 -0
  137. package/locales/pt/index.mjs +96 -0
  138. package/locales/pt/package.json +6 -0
  139. package/locales/pt-BR/index.d.mts +3 -0
  140. package/locales/pt-BR/index.d.ts +3 -0
  141. package/locales/pt-BR/index.js +100 -0
  142. package/locales/pt-BR/index.mjs +96 -0
  143. package/locales/pt-BR/package.json +6 -0
  144. package/locales/ro/index.d.mts +3 -0
  145. package/locales/ro/index.d.ts +3 -0
  146. package/locales/ro/index.js +100 -0
  147. package/locales/ro/index.mjs +96 -0
  148. package/locales/ro/package.json +6 -0
  149. package/locales/ru/index.d.mts +3 -0
  150. package/locales/ru/index.d.ts +3 -0
  151. package/locales/ru/index.js +100 -0
  152. package/locales/ru/index.mjs +96 -0
  153. package/locales/ru/package.json +6 -0
  154. package/locales/sk/index.d.mts +3 -0
  155. package/locales/sk/index.d.ts +3 -0
  156. package/locales/sk/index.js +100 -0
  157. package/locales/sk/index.mjs +96 -0
  158. package/locales/sk/package.json +6 -0
  159. package/locales/sr-Cyrl-RS/index.d.mts +3 -0
  160. package/locales/sr-Cyrl-RS/index.d.ts +3 -0
  161. package/locales/sr-Cyrl-RS/index.js +100 -0
  162. package/locales/sr-Cyrl-RS/index.mjs +96 -0
  163. package/locales/sr-Cyrl-RS/package.json +6 -0
  164. package/locales/sr-Latn-RS/index.d.mts +3 -0
  165. package/locales/sr-Latn-RS/index.d.ts +3 -0
  166. package/locales/sr-Latn-RS/index.js +100 -0
  167. package/locales/sr-Latn-RS/index.mjs +96 -0
  168. package/locales/sr-Latn-RS/package.json +6 -0
  169. package/locales/sv/index.d.mts +3 -0
  170. package/locales/sv/index.d.ts +3 -0
  171. package/locales/sv/index.js +100 -0
  172. package/locales/sv/index.mjs +96 -0
  173. package/locales/sv/package.json +6 -0
  174. package/locales/tr/index.d.mts +3 -0
  175. package/locales/tr/index.d.ts +3 -0
  176. package/locales/tr/index.js +100 -0
  177. package/locales/tr/index.mjs +96 -0
  178. package/locales/tr/package.json +6 -0
  179. package/locales/uk/index.d.mts +3 -0
  180. package/locales/uk/index.d.ts +3 -0
  181. package/locales/uk/index.js +100 -0
  182. package/locales/uk/index.mjs +96 -0
  183. package/locales/uk/package.json +6 -0
  184. package/locales/vi/index.d.mts +3 -0
  185. package/locales/vi/index.d.ts +3 -0
  186. package/locales/vi/index.js +100 -0
  187. package/locales/vi/index.mjs +96 -0
  188. package/locales/vi/package.json +6 -0
  189. package/locales/zh-Hans/index.d.mts +3 -0
  190. package/locales/zh-Hans/index.d.ts +3 -0
  191. package/locales/zh-Hans/index.js +100 -0
  192. package/locales/zh-Hans/index.mjs +96 -0
  193. package/locales/zh-Hans/package.json +6 -0
  194. package/locales/zh-Hant/index.d.mts +3 -0
  195. package/locales/zh-Hant/index.d.ts +3 -0
  196. package/locales/zh-Hant/index.js +100 -0
  197. package/locales/zh-Hant/index.mjs +96 -0
  198. package/locales/zh-Hant/package.json +6 -0
  199. package/package.json +147 -0
  200. package/skills/README.md +81 -0
  201. package/skills/composable-components/SKILL.md +189 -0
  202. package/skills/customization/SKILL.md +190 -0
  203. package/skills/drag-and-drop-ordering/SKILL.md +227 -0
  204. package/skills/editing/SKILL.md +243 -0
  205. package/skills/filtering/SKILL.md +213 -0
  206. package/skills/getting-started/SKILL.md +213 -0
  207. package/skills/localization/SKILL.md +182 -0
  208. package/skills/migrate-v3-to-v4/SKILL.md +161 -0
  209. package/skills/state-and-server-data/SKILL.md +200 -0
  210. package/skills/virtualization/SKILL.md +203 -0
  211. package/src/components/MaterialReactTable.tsx +36 -0
  212. package/src/components/body/MRT_TableBody.tsx +221 -0
  213. package/src/components/body/MRT_TableBodyCell.tsx +351 -0
  214. package/src/components/body/MRT_TableBodyCellValue.tsx +130 -0
  215. package/src/components/body/MRT_TableBodyRow.tsx +288 -0
  216. package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +61 -0
  217. package/src/components/body/MRT_TableBodyRowPinButton.tsx +58 -0
  218. package/src/components/body/MRT_TableDetailPanel.tsx +110 -0
  219. package/src/components/buttons/MRT_ColumnPinningButtons.tsx +72 -0
  220. package/src/components/buttons/MRT_CopyButton.tsx +87 -0
  221. package/src/components/buttons/MRT_EditActionButtons.tsx +134 -0
  222. package/src/components/buttons/MRT_ExpandAllButton.tsx +78 -0
  223. package/src/components/buttons/MRT_ExpandButton.tsx +102 -0
  224. package/src/components/buttons/MRT_GrabHandleButton.tsx +65 -0
  225. package/src/components/buttons/MRT_RowPinButton.tsx +84 -0
  226. package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +50 -0
  227. package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +52 -0
  228. package/src/components/buttons/MRT_ToggleFiltersButton.tsx +40 -0
  229. package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +51 -0
  230. package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +46 -0
  231. package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +126 -0
  232. package/src/components/footer/MRT_TableFooter.tsx +88 -0
  233. package/src/components/footer/MRT_TableFooterCell.tsx +107 -0
  234. package/src/components/footer/MRT_TableFooterRow.tsx +95 -0
  235. package/src/components/head/MRT_TableHead.tsx +91 -0
  236. package/src/components/head/MRT_TableHeadCell.tsx +351 -0
  237. package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +96 -0
  238. package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +52 -0
  239. package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +178 -0
  240. package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +91 -0
  241. package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +96 -0
  242. package/src/components/head/MRT_TableHeadCellSortLabel.tsx +101 -0
  243. package/src/components/head/MRT_TableHeadRow.tsx +90 -0
  244. package/src/components/inputs/MRT_EditCellTextField.tsx +202 -0
  245. package/src/components/inputs/MRT_FilterCheckbox.tsx +90 -0
  246. package/src/components/inputs/MRT_FilterRangeFields.tsx +41 -0
  247. package/src/components/inputs/MRT_FilterRangeSlider.tsx +143 -0
  248. package/src/components/inputs/MRT_FilterTextField.tsx +592 -0
  249. package/src/components/inputs/MRT_GlobalFilterTextField.tsx +167 -0
  250. package/src/components/inputs/MRT_SelectCheckbox.tsx +135 -0
  251. package/src/components/menus/MRT_ActionMenuItem.tsx +62 -0
  252. package/src/components/menus/MRT_CellActionMenu.tsx +107 -0
  253. package/src/components/menus/MRT_ColumnActionMenu.tsx +352 -0
  254. package/src/components/menus/MRT_FilterOptionMenu.tsx +292 -0
  255. package/src/components/menus/MRT_RowActionMenu.tsx +88 -0
  256. package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +181 -0
  257. package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +203 -0
  258. package/src/components/modals/MRT_EditRowModal.tsx +114 -0
  259. package/src/components/table/MRT_Table.tsx +84 -0
  260. package/src/components/table/MRT_TableContainer.tsx +111 -0
  261. package/src/components/table/MRT_TableLoadingOverlay.tsx +58 -0
  262. package/src/components/table/MRT_TablePaper.tsx +89 -0
  263. package/src/components/toolbar/MRT_BottomToolbar.tsx +111 -0
  264. package/src/components/toolbar/MRT_LinearProgressBar.tsx +53 -0
  265. package/src/components/toolbar/MRT_TablePagination.tsx +241 -0
  266. package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +184 -0
  267. package/src/components/toolbar/MRT_ToolbarDropZone.tsx +83 -0
  268. package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +72 -0
  269. package/src/components/toolbar/MRT_TopToolbar.tsx +130 -0
  270. package/src/features/mrtCellActionsFeature.ts +67 -0
  271. package/src/features/mrtColumnDraggingFeature.ts +83 -0
  272. package/src/features/mrtDensityFeature.ts +64 -0
  273. package/src/features/mrtEditingFeature.ts +102 -0
  274. package/src/features/mrtFeatures.ts +103 -0
  275. package/src/features/mrtFilterModesFeature.ts +99 -0
  276. package/src/features/mrtFnsFeature.ts +46 -0
  277. package/src/features/mrtFullScreenFeature.ts +63 -0
  278. package/src/features/mrtLoadingFeature.ts +35 -0
  279. package/src/features/mrtRefsFeature.ts +60 -0
  280. package/src/features/mrtRowDraggingFeature.ts +81 -0
  281. package/src/features/mrtStateCompatFeature.ts +43 -0
  282. package/src/features/mrtToolbarsFeature.ts +76 -0
  283. package/src/fns/aggregationFns.ts +3 -0
  284. package/src/fns/filterFns.ts +196 -0
  285. package/src/fns/sortingFns.ts +31 -0
  286. package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +28 -0
  287. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +29 -0
  288. package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +97 -0
  289. package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +30 -0
  290. package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +24 -0
  291. package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +34 -0
  292. package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +33 -0
  293. package/src/hooks/useMRT_ColumnVirtualizer.ts +124 -0
  294. package/src/hooks/useMRT_Effects.ts +108 -0
  295. package/src/hooks/useMRT_RowVirtualizer.ts +88 -0
  296. package/src/hooks/useMRT_Rows.ts +44 -0
  297. package/src/hooks/useMRT_TableInstance.ts +181 -0
  298. package/src/hooks/useMRT_TableOptions.ts +241 -0
  299. package/src/hooks/useMaterialReactTable.ts +12 -0
  300. package/src/icons.ts +73 -0
  301. package/src/index.ts +91 -0
  302. package/src/locales/ar.ts +97 -0
  303. package/src/locales/az.ts +97 -0
  304. package/src/locales/bg.ts +97 -0
  305. package/src/locales/cs.ts +98 -0
  306. package/src/locales/da.ts +97 -0
  307. package/src/locales/de.ts +97 -0
  308. package/src/locales/el.ts +97 -0
  309. package/src/locales/en.ts +97 -0
  310. package/src/locales/es.ts +97 -0
  311. package/src/locales/et.ts +98 -0
  312. package/src/locales/fa.ts +97 -0
  313. package/src/locales/fi.ts +98 -0
  314. package/src/locales/fr.ts +97 -0
  315. package/src/locales/he.ts +97 -0
  316. package/src/locales/hr.ts +97 -0
  317. package/src/locales/hu.ts +97 -0
  318. package/src/locales/hy.ts +97 -0
  319. package/src/locales/id.ts +98 -0
  320. package/src/locales/it.ts +97 -0
  321. package/src/locales/ja.ts +97 -0
  322. package/src/locales/ko.ts +97 -0
  323. package/src/locales/mk.ts +96 -0
  324. package/src/locales/nl.ts +97 -0
  325. package/src/locales/no.ts +99 -0
  326. package/src/locales/np.ts +98 -0
  327. package/src/locales/pl.ts +97 -0
  328. package/src/locales/pt-BR.ts +97 -0
  329. package/src/locales/pt.ts +97 -0
  330. package/src/locales/ro.ts +97 -0
  331. package/src/locales/ru.ts +97 -0
  332. package/src/locales/sk.ts +98 -0
  333. package/src/locales/sr-Cyrl-RS.ts +97 -0
  334. package/src/locales/sr-Latn-RS.ts +97 -0
  335. package/src/locales/sv.ts +97 -0
  336. package/src/locales/tr.ts +97 -0
  337. package/src/locales/uk.ts +97 -0
  338. package/src/locales/vi.ts +97 -0
  339. package/src/locales/zh-Hans.ts +96 -0
  340. package/src/locales/zh-Hant.ts +96 -0
  341. package/src/types.ts +1314 -0
  342. package/src/utils/cell.utils.ts +234 -0
  343. package/src/utils/column.utils.ts +204 -0
  344. package/src/utils/displayColumn.utils.ts +152 -0
  345. package/src/utils/row.utils.ts +258 -0
  346. package/src/utils/style.utils.ts +211 -0
  347. package/src/utils/tanstack.helpers.ts +64 -0
  348. package/src/utils/utils.ts +34 -0
  349. package/src/utils/virtualization.utils.ts +24 -0
@@ -0,0 +1,88 @@
1
+ import { type MouseEvent, type ReactNode, useMemo } from 'react';
2
+ import Menu, { type MenuProps } from '@mui/material/Menu';
3
+ import { MRT_ActionMenuItem } from './MRT_ActionMenuItem';
4
+ import {
5
+ type MRT_Row,
6
+ type MRT_RowData,
7
+ type MRT_TableInstance,
8
+ } from '../../types';
9
+ import { parseFromValuesOrFunc } from '../../utils/utils';
10
+
11
+ export interface MRT_RowActionMenuProps<TData extends MRT_RowData>
12
+ extends Partial<MenuProps> {
13
+ anchorEl: HTMLElement | null;
14
+ handleEdit: (event: MouseEvent) => void;
15
+ row: MRT_Row<TData>;
16
+ setAnchorEl: (anchorEl: HTMLElement | null) => void;
17
+ staticRowIndex?: number;
18
+ table: MRT_TableInstance<TData>;
19
+ }
20
+
21
+ export const MRT_RowActionMenu = <TData extends MRT_RowData>({
22
+ anchorEl,
23
+ handleEdit,
24
+ row,
25
+ setAnchorEl,
26
+ staticRowIndex,
27
+ table,
28
+ ...rest
29
+ }: MRT_RowActionMenuProps<TData>) => {
30
+ const {
31
+ options: {
32
+ editDisplayMode,
33
+ enableEditing,
34
+ icons: { EditIcon },
35
+ localization,
36
+ mrtTheme: { menuBackgroundColor },
37
+ renderRowActionMenuItems,
38
+ },
39
+ state,
40
+ } = table;
41
+ const { density } = state;
42
+
43
+ const menuItems = useMemo(() => {
44
+ const items: ReactNode[] = [];
45
+ const editItem = parseFromValuesOrFunc(enableEditing, row) &&
46
+ ['modal', 'row'].includes(editDisplayMode!) && (
47
+ <MRT_ActionMenuItem
48
+ icon={<EditIcon />}
49
+ key={'edit'}
50
+ label={localization.edit}
51
+ onClick={handleEdit}
52
+ table={table}
53
+ />
54
+ );
55
+ if (editItem) items.push(editItem);
56
+ const rowActionMenuItems = renderRowActionMenuItems?.({
57
+ closeMenu: () => setAnchorEl(null),
58
+ row,
59
+ staticRowIndex,
60
+ table,
61
+ });
62
+ if (rowActionMenuItems?.length) items.push(...rowActionMenuItems);
63
+ return items;
64
+ }, [renderRowActionMenuItems, row, staticRowIndex, table]);
65
+
66
+ if (!menuItems.length) return null;
67
+
68
+ return (
69
+ <Menu
70
+ anchorEl={anchorEl}
71
+ disableScrollLock
72
+ onClick={(event) => event.stopPropagation()}
73
+ onClose={() => setAnchorEl(null)}
74
+ open={!!anchorEl}
75
+ {...rest}
76
+ slotProps={{
77
+ list: {
78
+ dense: density === 'compact',
79
+ sx: {
80
+ backgroundColor: menuBackgroundColor,
81
+ },
82
+ },
83
+ }}
84
+ >
85
+ {menuItems}
86
+ </Menu>
87
+ );
88
+ };
@@ -0,0 +1,181 @@
1
+ import { useMemo, useState } from 'react';
2
+ import Box from '@mui/material/Box';
3
+ import Button from '@mui/material/Button';
4
+ import Divider from '@mui/material/Divider';
5
+ import Menu, { type MenuProps } from '@mui/material/Menu';
6
+ import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
7
+ import {
8
+ type MRT_Column,
9
+ type MRT_RowData,
10
+ type MRT_TableInstance,
11
+ type MRT_VisibilityState,
12
+ } from '../../types';
13
+ import { getDefaultColumnOrderIds } from '../../utils/displayColumn.utils';
14
+
15
+ export interface MRT_ShowHideColumnsMenuProps<TData extends MRT_RowData>
16
+ extends Partial<MenuProps> {
17
+ anchorEl: HTMLElement | null;
18
+ isSubMenu?: boolean;
19
+ setAnchorEl: (anchorEl: HTMLElement | null) => void;
20
+ table: MRT_TableInstance<TData>;
21
+ }
22
+
23
+ export const MRT_ShowHideColumnsMenu = <TData extends MRT_RowData>({
24
+ anchorEl,
25
+ setAnchorEl,
26
+ table,
27
+ ...rest
28
+ }: MRT_ShowHideColumnsMenuProps<TData>) => {
29
+ const {
30
+ getAllColumns,
31
+ getAllLeafColumns,
32
+ getCenterLeafColumns,
33
+ getEndLeafColumns,
34
+ getIsAllColumnsVisible,
35
+ getIsSomeColumnsPinned,
36
+ getIsSomeColumnsVisible,
37
+ getStartLeafColumns,
38
+ initialState,
39
+ options: {
40
+ enableColumnOrdering,
41
+ enableColumnPinning,
42
+ enableHiding,
43
+ localization,
44
+ mrtTheme: { menuBackgroundColor },
45
+ },
46
+ state,
47
+ } = table;
48
+ const { columnOrder, columnPinning, density } = state;
49
+
50
+ const handleToggleAllColumns = (value?: boolean) => {
51
+ const updates = getAllLeafColumns()
52
+ .filter((column) => column.columnDef.enableHiding !== false)
53
+ .reduce((acc, column) => {
54
+ acc[column.id] = value ?? !column.getIsVisible();
55
+ return acc;
56
+ }, {} as MRT_VisibilityState);
57
+
58
+ table.setColumnVisibility((old) => ({ ...old, ...updates }));
59
+ };
60
+
61
+ const allColumns = useMemo(() => {
62
+ const columns = getAllColumns();
63
+ if (
64
+ columnOrder.length > 0 &&
65
+ !columns.some((col) => col.columnDef.columnDefType === 'group')
66
+ ) {
67
+ return [
68
+ ...getStartLeafColumns(),
69
+ ...Array.from(new Set(columnOrder)).map((colId) =>
70
+ getCenterLeafColumns().find((col) => col?.id === colId),
71
+ ),
72
+ ...getEndLeafColumns(),
73
+ ].filter(Boolean);
74
+ }
75
+ return columns;
76
+ }, [
77
+ columnOrder,
78
+ columnPinning,
79
+ getAllColumns(),
80
+ getCenterLeafColumns(),
81
+ getStartLeafColumns(),
82
+ getEndLeafColumns(),
83
+ ]) as MRT_Column<TData>[];
84
+
85
+ const isNestedColumns = allColumns.some(
86
+ (col) => col.columnDef.columnDefType === 'group',
87
+ );
88
+
89
+ const hasColumnOrderChanged = useMemo(
90
+ () =>
91
+ columnOrder.length !== initialState.columnOrder.length ||
92
+ !columnOrder.every(
93
+ (column, index) => column === initialState.columnOrder[index],
94
+ ),
95
+
96
+ [columnOrder, initialState.columnOrder],
97
+ );
98
+
99
+ const [hoveredColumn, setHoveredColumn] = useState<MRT_Column<TData> | null>(
100
+ null,
101
+ );
102
+
103
+ return (
104
+ <Menu
105
+ anchorEl={anchorEl}
106
+ disableScrollLock
107
+ onClose={() => setAnchorEl(null)}
108
+ open={!!anchorEl}
109
+ {...rest}
110
+ slotProps={{
111
+ list: {
112
+ dense: density === 'compact',
113
+ sx: {
114
+ backgroundColor: menuBackgroundColor,
115
+ },
116
+ },
117
+ }}
118
+ >
119
+ <Box
120
+ sx={{
121
+ display: 'flex',
122
+ justifyContent: 'space-between',
123
+ p: '0.5rem',
124
+ pt: 0,
125
+ }}
126
+ >
127
+ {enableHiding && (
128
+ <Button
129
+ disabled={!getIsSomeColumnsVisible()}
130
+ onClick={() => handleToggleAllColumns(false)}
131
+ >
132
+ {localization.hideAll}
133
+ </Button>
134
+ )}
135
+ {enableColumnOrdering && (
136
+ <Button
137
+ disabled={!hasColumnOrderChanged}
138
+ onClick={() =>
139
+ table.setColumnOrder(
140
+ getDefaultColumnOrderIds(
141
+ { ...table.options, state: table.state },
142
+ true,
143
+ ),
144
+ )
145
+ }
146
+ >
147
+ {localization.resetOrder}
148
+ </Button>
149
+ )}
150
+ {enableColumnPinning && (
151
+ <Button
152
+ disabled={!getIsSomeColumnsPinned()}
153
+ onClick={() => table.resetColumnPinning(true)}
154
+ >
155
+ {localization.unpinAll}
156
+ </Button>
157
+ )}
158
+ {enableHiding && (
159
+ <Button
160
+ disabled={getIsAllColumnsVisible()}
161
+ onClick={() => handleToggleAllColumns(true)}
162
+ >
163
+ {localization.showAll}
164
+ </Button>
165
+ )}
166
+ </Box>
167
+ <Divider />
168
+ {allColumns.map((column, index) => (
169
+ <MRT_ShowHideColumnsMenuItems
170
+ allColumns={allColumns}
171
+ column={column}
172
+ hoveredColumn={hoveredColumn}
173
+ isNestedColumns={isNestedColumns}
174
+ key={`${index}-${column.id}`}
175
+ setHoveredColumn={setHoveredColumn}
176
+ table={table}
177
+ />
178
+ ))}
179
+ </Menu>
180
+ );
181
+ };
@@ -0,0 +1,203 @@
1
+ import {
2
+ type Dispatch,
3
+ type DragEvent,
4
+ type SetStateAction,
5
+ useRef,
6
+ useState,
7
+ } from 'react';
8
+ import Box from '@mui/material/Box';
9
+ import FormControlLabel from '@mui/material/FormControlLabel';
10
+ import MenuItem, { type MenuItemProps } from '@mui/material/MenuItem';
11
+ import Switch from '@mui/material/Switch';
12
+ import Tooltip from '@mui/material/Tooltip';
13
+ import Typography from '@mui/material/Typography';
14
+ import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
15
+ import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
16
+ import {
17
+ type MRT_Column,
18
+ type MRT_RowData,
19
+ type MRT_TableInstance,
20
+ } from '../../types';
21
+ import { reorderColumn } from '../../utils/column.utils';
22
+ import { getCommonTooltipProps } from '../../utils/style.utils';
23
+ import { parseFromValuesOrFunc } from '../../utils/utils';
24
+
25
+ export interface MRT_ShowHideColumnsMenuItemsProps<TData extends MRT_RowData>
26
+ extends MenuItemProps {
27
+ allColumns: MRT_Column<TData>[];
28
+ column: MRT_Column<TData>;
29
+ hoveredColumn: MRT_Column<TData> | null;
30
+ isNestedColumns: boolean;
31
+ setHoveredColumn: Dispatch<SetStateAction<MRT_Column<TData> | null>>;
32
+ table: MRT_TableInstance<TData>;
33
+ }
34
+
35
+ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
36
+ allColumns,
37
+ column,
38
+ hoveredColumn,
39
+ isNestedColumns,
40
+ setHoveredColumn,
41
+ table,
42
+ ...rest
43
+ }: MRT_ShowHideColumnsMenuItemsProps<TData>) => {
44
+ const {
45
+ options: {
46
+ enableColumnOrdering,
47
+ enableColumnPinning,
48
+ enableHiding,
49
+ localization,
50
+ mrtTheme: { draggingBorderColor },
51
+ },
52
+ setColumnOrder,
53
+ setColumnPinning,
54
+ state,
55
+ } = table;
56
+ const { columnOrder } = state;
57
+ const { columnDef } = column;
58
+ const { columnDefType } = columnDef;
59
+
60
+ const switchChecked = column.getIsVisible();
61
+
62
+ const handleToggleColumnHidden = (column: MRT_Column<TData>) => {
63
+ if (columnDefType === 'group') {
64
+ column?.columns?.forEach?.((childColumn: MRT_Column<TData>) => {
65
+ childColumn.toggleVisibility(!switchChecked);
66
+ });
67
+ } else {
68
+ column.toggleVisibility();
69
+ }
70
+ };
71
+
72
+ const menuItemRef = useRef<HTMLElement>(null);
73
+
74
+ const [isDragging, setIsDragging] = useState(false);
75
+
76
+ const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
77
+ setIsDragging(true);
78
+ try {
79
+ e.dataTransfer.setDragImage(menuItemRef.current as HTMLElement, 0, 0);
80
+ } catch (e) {
81
+ console.error(e);
82
+ }
83
+ };
84
+
85
+ const handleDragEnd = (_e: DragEvent<HTMLButtonElement>) => {
86
+ setIsDragging(false);
87
+ setHoveredColumn(null);
88
+ if (hoveredColumn) {
89
+ const reorderedColumns = reorderColumn(
90
+ column,
91
+ hoveredColumn,
92
+ columnOrder,
93
+ );
94
+ setColumnOrder(reorderedColumns);
95
+ setColumnPinning(({ end = [], start = [] }) => ({
96
+ end: reorderedColumns.filter((header) => end.includes(header)),
97
+ start: reorderedColumns.filter((header) => start.includes(header)),
98
+ }));
99
+ }
100
+ };
101
+
102
+ const handleDragEnter = (_e: DragEvent) => {
103
+ if (!isDragging && columnDef.enableColumnOrdering !== false) {
104
+ setHoveredColumn(column);
105
+ }
106
+ };
107
+
108
+ if (!columnDef.header || columnDef.visibleInShowHideMenu === false) {
109
+ return null;
110
+ }
111
+
112
+ return (
113
+ <>
114
+ <MenuItem
115
+ disableRipple
116
+ onDragEnter={handleDragEnter}
117
+ ref={menuItemRef as any}
118
+ {...rest}
119
+ sx={(theme) => ({
120
+ alignItems: 'center',
121
+ justifyContent: 'flex-start',
122
+ my: 0,
123
+ opacity: isDragging ? 0.5 : 1,
124
+ outline: isDragging
125
+ ? `2px dashed ${theme.palette.grey[500]}`
126
+ : hoveredColumn?.id === column.id
127
+ ? `2px dashed ${draggingBorderColor}`
128
+ : 'none',
129
+ outlineOffset: '-2px',
130
+ pl: `${(column.depth + 0.5) * 2}rem`,
131
+ py: '6px',
132
+ ...(parseFromValuesOrFunc(rest?.sx, theme) as any),
133
+ })}
134
+ >
135
+ <Box
136
+ sx={{
137
+ display: 'flex',
138
+ flexWrap: 'nowrap',
139
+ gap: '8px',
140
+ }}
141
+ >
142
+ {columnDefType !== 'group' &&
143
+ enableColumnOrdering &&
144
+ !isNestedColumns &&
145
+ (columnDef.enableColumnOrdering !== false ? (
146
+ <MRT_GrabHandleButton
147
+ onDragEnd={handleDragEnd}
148
+ onDragStart={handleDragStart}
149
+ table={table}
150
+ />
151
+ ) : (
152
+ <Box sx={{ width: '28px' }} />
153
+ ))}
154
+ {enableColumnPinning &&
155
+ (column.getCanPin() ? (
156
+ <MRT_ColumnPinningButtons column={column} table={table} />
157
+ ) : (
158
+ <Box sx={{ width: '70px' }} />
159
+ ))}
160
+ {enableHiding ? (
161
+ <FormControlLabel
162
+ checked={switchChecked}
163
+ control={
164
+ <Tooltip
165
+ {...getCommonTooltipProps()}
166
+ title={localization.toggleVisibility}
167
+ >
168
+ <Switch />
169
+ </Tooltip>
170
+ }
171
+ disabled={!column.getCanHide()}
172
+ label={columnDef.header}
173
+ onChange={() => handleToggleColumnHidden(column)}
174
+ slotProps={{
175
+ typography: {
176
+ sx: {
177
+ mb: 0,
178
+ opacity: columnDefType !== 'display' ? 1 : 0.5,
179
+ },
180
+ },
181
+ }}
182
+ />
183
+ ) : (
184
+ <Typography sx={{ alignSelf: 'center' }}>
185
+ {columnDef.header}
186
+ </Typography>
187
+ )}
188
+ </Box>
189
+ </MenuItem>
190
+ {column.columns?.map((c: MRT_Column<TData>, i) => (
191
+ <MRT_ShowHideColumnsMenuItems
192
+ allColumns={allColumns}
193
+ column={c}
194
+ hoveredColumn={hoveredColumn}
195
+ isNestedColumns={isNestedColumns}
196
+ key={`${i}-${c.id}`}
197
+ setHoveredColumn={setHoveredColumn}
198
+ table={table}
199
+ />
200
+ ))}
201
+ </>
202
+ );
203
+ };
@@ -0,0 +1,114 @@
1
+ import Dialog, { type DialogProps } from '@mui/material/Dialog';
2
+ import DialogActions from '@mui/material/DialogActions';
3
+ import DialogContent from '@mui/material/DialogContent';
4
+ import DialogTitle from '@mui/material/DialogTitle';
5
+ import Stack from '@mui/material/Stack';
6
+ import { MRT_EditActionButtons } from '../buttons/MRT_EditActionButtons';
7
+ import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
8
+ import {
9
+ type MRT_Row,
10
+ type MRT_RowData,
11
+ type MRT_TableInstance,
12
+ } from '../../types';
13
+ import { parseFromValuesOrFunc } from '../../utils/utils';
14
+
15
+ export interface MRT_EditRowModalProps<TData extends MRT_RowData>
16
+ extends Partial<DialogProps> {
17
+ open: boolean;
18
+ table: MRT_TableInstance<TData>;
19
+ }
20
+
21
+ export const MRT_EditRowModal = <TData extends MRT_RowData>({
22
+ open,
23
+ table,
24
+ ...rest
25
+ }: MRT_EditRowModalProps<TData>) => {
26
+ const {
27
+ options: {
28
+ localization,
29
+ muiCreateRowModalProps,
30
+ muiEditRowDialogProps,
31
+ onCreatingRowCancel,
32
+ onEditingRowCancel,
33
+ renderCreateRowDialogContent,
34
+ renderEditRowDialogContent,
35
+ },
36
+ setCreatingRow,
37
+ setEditingRow,
38
+ state,
39
+ } = table;
40
+ const { creatingRow, editingRow } = state;
41
+ const row = (creatingRow ?? editingRow) as MRT_Row<TData>;
42
+
43
+ const dialogProps = {
44
+ ...parseFromValuesOrFunc(muiEditRowDialogProps, { row, table }),
45
+ ...(creatingRow &&
46
+ parseFromValuesOrFunc(muiCreateRowModalProps, { row, table })),
47
+ ...rest,
48
+ };
49
+
50
+ const internalEditComponents = row
51
+ .getAllCells()
52
+ .filter((cell) => cell.column.columnDef.columnDefType === 'data')
53
+ .map((cell) => (
54
+ <MRT_EditCellTextField
55
+ cell={cell as any}
56
+ key={cell.id}
57
+ table={table as any}
58
+ />
59
+ ));
60
+
61
+ return (
62
+ <Dialog
63
+ fullWidth
64
+ maxWidth="xs"
65
+ onClose={(event, reason) => {
66
+ if (creatingRow) {
67
+ onCreatingRowCancel?.({ row, table });
68
+ setCreatingRow(null);
69
+ } else {
70
+ onEditingRowCancel?.({ row, table });
71
+ setEditingRow(null);
72
+ }
73
+ row._valuesCache = {} as any; //reset values cache
74
+ dialogProps.onClose?.(event, reason);
75
+ }}
76
+ open={open}
77
+ {...dialogProps}
78
+ >
79
+ {((creatingRow &&
80
+ renderCreateRowDialogContent?.({
81
+ internalEditComponents,
82
+ row,
83
+ table,
84
+ })) ||
85
+ renderEditRowDialogContent?.({
86
+ internalEditComponents,
87
+ row,
88
+ table,
89
+ })) ?? (
90
+ <>
91
+ <DialogTitle sx={{ textAlign: 'center' }}>
92
+ {localization.edit}
93
+ </DialogTitle>
94
+ <DialogContent>
95
+ <form onSubmit={(e) => e.preventDefault()}>
96
+ <Stack
97
+ sx={{
98
+ gap: '32px',
99
+ paddingTop: '16px',
100
+ width: '100%',
101
+ }}
102
+ >
103
+ {internalEditComponents}
104
+ </Stack>
105
+ </form>
106
+ </DialogContent>
107
+ <DialogActions sx={{ p: '1.25rem' }}>
108
+ <MRT_EditActionButtons row={row} table={table} variant="text" />
109
+ </DialogActions>
110
+ </>
111
+ )}
112
+ </Dialog>
113
+ );
114
+ };
@@ -0,0 +1,84 @@
1
+ import { useMemo } from 'react';
2
+ import Table, { type TableProps } from '@mui/material/Table';
3
+ import { useMRT_ColumnVirtualizer } from '../../hooks/useMRT_ColumnVirtualizer';
4
+ import { Memo_MRT_TableBody, MRT_TableBody } from '../body/MRT_TableBody';
5
+ import { MRT_TableFooter } from '../footer/MRT_TableFooter';
6
+ import { MRT_TableHead } from '../head/MRT_TableHead';
7
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
8
+ import { parseCSSVarId } from '../../utils/style.utils';
9
+ import { parseFromValuesOrFunc } from '../../utils/utils';
10
+
11
+ export interface MRT_TableProps<TData extends MRT_RowData> extends TableProps {
12
+ table: MRT_TableInstance<TData>;
13
+ }
14
+
15
+ export const MRT_Table = <TData extends MRT_RowData>({
16
+ table,
17
+ ...rest
18
+ }: MRT_TableProps<TData>) => {
19
+ const {
20
+ getFlatHeaders,
21
+ options: {
22
+ columns,
23
+ enableStickyHeader,
24
+ enableTableFooter,
25
+ enableTableHead,
26
+ layoutMode,
27
+ memoMode,
28
+ muiTableProps,
29
+ renderCaption,
30
+ },
31
+ state,
32
+ } = table;
33
+ const { columnResizing, columnSizing, columnVisibility, isFullScreen } =
34
+ state;
35
+
36
+ const tableProps = {
37
+ ...parseFromValuesOrFunc(muiTableProps, { table }),
38
+ ...rest,
39
+ };
40
+
41
+ const Caption = parseFromValuesOrFunc(renderCaption, { table });
42
+
43
+ const columnSizeVars = useMemo(() => {
44
+ const headers = getFlatHeaders();
45
+ const colSizes: { [key: string]: number } = {};
46
+ for (let i = 0; i < headers.length; i++) {
47
+ const header = headers[i];
48
+ const colSize = header.getSize();
49
+ colSizes[`--header-${parseCSSVarId(header.id)}-size`] = colSize;
50
+ colSizes[`--col-${parseCSSVarId(header.column.id)}-size`] = colSize;
51
+ }
52
+ return colSizes;
53
+ }, [columns, columnSizing, columnResizing, columnVisibility]);
54
+
55
+ const columnVirtualizer = useMRT_ColumnVirtualizer(table);
56
+
57
+ const commonTableGroupProps = {
58
+ columnVirtualizer,
59
+ table,
60
+ };
61
+
62
+ return (
63
+ <Table
64
+ stickyHeader={enableStickyHeader || isFullScreen}
65
+ {...tableProps}
66
+ style={{ ...columnSizeVars, ...tableProps?.style }}
67
+ sx={(theme) => ({
68
+ borderCollapse: 'separate',
69
+ display: layoutMode?.startsWith('grid') ? 'grid' : undefined,
70
+ position: 'relative',
71
+ ...(parseFromValuesOrFunc(tableProps?.sx, theme) as any),
72
+ })}
73
+ >
74
+ {!!Caption && <caption>{Caption}</caption>}
75
+ {enableTableHead && <MRT_TableHead {...commonTableGroupProps} />}
76
+ {memoMode === 'table-body' || columnResizing.isResizingColumn ? (
77
+ <Memo_MRT_TableBody {...commonTableGroupProps} />
78
+ ) : (
79
+ <MRT_TableBody {...commonTableGroupProps} />
80
+ )}
81
+ {enableTableFooter && <MRT_TableFooter {...commonTableGroupProps} />}
82
+ </Table>
83
+ );
84
+ };