@careharmony/mantine-react-table-ng 0.0.0-stage → 4.0.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +217 -3
- package/dist/index.cjs +4023 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1488 -0
- package/dist/index.esm.d.mts +1488 -0
- package/dist/index.esm.mjs +3909 -0
- package/dist/index.esm.mjs.map +1 -0
- package/locales/ar/index.cjs +97 -0
- package/locales/ar/index.d.cts +3 -0
- package/locales/ar/index.esm.d.mts +3 -0
- package/locales/ar/index.esm.mjs +95 -0
- package/locales/ar/package.json +19 -0
- package/locales/az/index.cjs +97 -0
- package/locales/az/index.d.cts +3 -0
- package/locales/az/index.esm.d.mts +3 -0
- package/locales/az/index.esm.mjs +95 -0
- package/locales/az/package.json +19 -0
- package/locales/bg/index.cjs +97 -0
- package/locales/bg/index.d.cts +3 -0
- package/locales/bg/index.esm.d.mts +3 -0
- package/locales/bg/index.esm.mjs +95 -0
- package/locales/bg/package.json +19 -0
- package/locales/cs/index.cjs +97 -0
- package/locales/cs/index.d.cts +3 -0
- package/locales/cs/index.esm.d.mts +3 -0
- package/locales/cs/index.esm.mjs +95 -0
- package/locales/cs/package.json +19 -0
- package/locales/da/index.cjs +97 -0
- package/locales/da/index.d.cts +3 -0
- package/locales/da/index.esm.d.mts +3 -0
- package/locales/da/index.esm.mjs +95 -0
- package/locales/da/package.json +19 -0
- package/locales/de/index.cjs +97 -0
- package/locales/de/index.d.cts +3 -0
- package/locales/de/index.esm.d.mts +3 -0
- package/locales/de/index.esm.mjs +95 -0
- package/locales/de/package.json +19 -0
- package/locales/el/index.cjs +97 -0
- package/locales/el/index.d.cts +3 -0
- package/locales/el/index.esm.d.mts +3 -0
- package/locales/el/index.esm.mjs +95 -0
- package/locales/el/package.json +19 -0
- package/locales/en/index.cjs +97 -0
- package/locales/en/index.d.cts +3 -0
- package/locales/en/index.esm.d.mts +3 -0
- package/locales/en/index.esm.mjs +95 -0
- package/locales/en/package.json +19 -0
- package/locales/es/index.cjs +97 -0
- package/locales/es/index.d.cts +3 -0
- package/locales/es/index.esm.d.mts +3 -0
- package/locales/es/index.esm.mjs +95 -0
- package/locales/es/package.json +19 -0
- package/locales/et/index.cjs +97 -0
- package/locales/et/index.d.cts +3 -0
- package/locales/et/index.esm.d.mts +3 -0
- package/locales/et/index.esm.mjs +95 -0
- package/locales/et/package.json +19 -0
- package/locales/fa/index.cjs +97 -0
- package/locales/fa/index.d.cts +3 -0
- package/locales/fa/index.esm.d.mts +3 -0
- package/locales/fa/index.esm.mjs +95 -0
- package/locales/fa/package.json +19 -0
- package/locales/fi/index.cjs +97 -0
- package/locales/fi/index.d.cts +3 -0
- package/locales/fi/index.esm.d.mts +3 -0
- package/locales/fi/index.esm.mjs +95 -0
- package/locales/fi/package.json +19 -0
- package/locales/fr/index.cjs +97 -0
- package/locales/fr/index.d.cts +3 -0
- package/locales/fr/index.esm.d.mts +3 -0
- package/locales/fr/index.esm.mjs +95 -0
- package/locales/fr/package.json +19 -0
- package/locales/he/index.cjs +97 -0
- package/locales/he/index.d.cts +3 -0
- package/locales/he/index.esm.d.mts +3 -0
- package/locales/he/index.esm.mjs +95 -0
- package/locales/he/package.json +19 -0
- package/locales/hr/index.cjs +97 -0
- package/locales/hr/index.d.cts +3 -0
- package/locales/hr/index.esm.d.mts +3 -0
- package/locales/hr/index.esm.mjs +95 -0
- package/locales/hr/package.json +19 -0
- package/locales/hu/index.cjs +97 -0
- package/locales/hu/index.d.cts +3 -0
- package/locales/hu/index.esm.d.mts +3 -0
- package/locales/hu/index.esm.mjs +95 -0
- package/locales/hu/package.json +19 -0
- package/locales/hy/index.cjs +97 -0
- package/locales/hy/index.d.cts +3 -0
- package/locales/hy/index.esm.d.mts +3 -0
- package/locales/hy/index.esm.mjs +95 -0
- package/locales/hy/package.json +19 -0
- package/locales/id/index.cjs +97 -0
- package/locales/id/index.d.cts +3 -0
- package/locales/id/index.esm.d.mts +3 -0
- package/locales/id/index.esm.mjs +95 -0
- package/locales/id/package.json +19 -0
- package/locales/it/index.cjs +97 -0
- package/locales/it/index.d.cts +3 -0
- package/locales/it/index.esm.d.mts +3 -0
- package/locales/it/index.esm.mjs +95 -0
- package/locales/it/package.json +19 -0
- package/locales/ja/index.cjs +97 -0
- package/locales/ja/index.d.cts +3 -0
- package/locales/ja/index.esm.d.mts +3 -0
- package/locales/ja/index.esm.mjs +95 -0
- package/locales/ja/package.json +19 -0
- package/locales/ko/index.cjs +97 -0
- package/locales/ko/index.d.cts +3 -0
- package/locales/ko/index.esm.d.mts +3 -0
- package/locales/ko/index.esm.mjs +95 -0
- package/locales/ko/package.json +19 -0
- package/locales/nl/index.cjs +97 -0
- package/locales/nl/index.d.cts +3 -0
- package/locales/nl/index.esm.d.mts +3 -0
- package/locales/nl/index.esm.mjs +95 -0
- package/locales/nl/package.json +19 -0
- package/locales/no/index.cjs +97 -0
- package/locales/no/index.d.cts +3 -0
- package/locales/no/index.esm.d.mts +3 -0
- package/locales/no/index.esm.mjs +95 -0
- package/locales/no/package.json +19 -0
- package/locales/np/index.cjs +97 -0
- package/locales/np/index.d.cts +3 -0
- package/locales/np/index.esm.d.mts +3 -0
- package/locales/np/index.esm.mjs +95 -0
- package/locales/np/package.json +19 -0
- package/locales/pl/index.cjs +97 -0
- package/locales/pl/index.d.cts +3 -0
- package/locales/pl/index.esm.d.mts +3 -0
- package/locales/pl/index.esm.mjs +95 -0
- package/locales/pl/package.json +19 -0
- package/locales/pt/index.cjs +97 -0
- package/locales/pt/index.d.cts +3 -0
- package/locales/pt/index.esm.d.mts +3 -0
- package/locales/pt/index.esm.mjs +95 -0
- package/locales/pt/package.json +19 -0
- package/locales/pt-BR/index.cjs +97 -0
- package/locales/pt-BR/index.d.cts +3 -0
- package/locales/pt-BR/index.esm.d.mts +3 -0
- package/locales/pt-BR/index.esm.mjs +95 -0
- package/locales/pt-BR/package.json +19 -0
- package/locales/ro/index.cjs +97 -0
- package/locales/ro/index.d.cts +3 -0
- package/locales/ro/index.esm.d.mts +3 -0
- package/locales/ro/index.esm.mjs +95 -0
- package/locales/ro/package.json +19 -0
- package/locales/ru/index.cjs +97 -0
- package/locales/ru/index.d.cts +3 -0
- package/locales/ru/index.esm.d.mts +3 -0
- package/locales/ru/index.esm.mjs +95 -0
- package/locales/ru/package.json +19 -0
- package/locales/sk/index.cjs +97 -0
- package/locales/sk/index.d.cts +3 -0
- package/locales/sk/index.esm.d.mts +3 -0
- package/locales/sk/index.esm.mjs +95 -0
- package/locales/sk/package.json +19 -0
- package/locales/sr-Cyrl-RS/index.cjs +97 -0
- package/locales/sr-Cyrl-RS/index.d.cts +3 -0
- package/locales/sr-Cyrl-RS/index.esm.d.mts +3 -0
- package/locales/sr-Cyrl-RS/index.esm.mjs +95 -0
- package/locales/sr-Cyrl-RS/package.json +19 -0
- package/locales/sr-Latn-RS/index.cjs +97 -0
- package/locales/sr-Latn-RS/index.d.cts +3 -0
- package/locales/sr-Latn-RS/index.esm.d.mts +3 -0
- package/locales/sr-Latn-RS/index.esm.mjs +95 -0
- package/locales/sr-Latn-RS/package.json +19 -0
- package/locales/sv/index.cjs +97 -0
- package/locales/sv/index.d.cts +3 -0
- package/locales/sv/index.esm.d.mts +3 -0
- package/locales/sv/index.esm.mjs +95 -0
- package/locales/sv/package.json +19 -0
- package/locales/th/index.cjs +97 -0
- package/locales/th/index.d.cts +3 -0
- package/locales/th/index.esm.d.mts +3 -0
- package/locales/th/index.esm.mjs +95 -0
- package/locales/th/package.json +19 -0
- package/locales/tr/index.cjs +97 -0
- package/locales/tr/index.d.cts +3 -0
- package/locales/tr/index.esm.d.mts +3 -0
- package/locales/tr/index.esm.mjs +95 -0
- package/locales/tr/package.json +19 -0
- package/locales/uk/index.cjs +97 -0
- package/locales/uk/index.d.cts +3 -0
- package/locales/uk/index.esm.d.mts +3 -0
- package/locales/uk/index.esm.mjs +95 -0
- package/locales/uk/package.json +19 -0
- package/locales/vi/index.cjs +97 -0
- package/locales/vi/index.d.cts +3 -0
- package/locales/vi/index.esm.d.mts +3 -0
- package/locales/vi/index.esm.mjs +95 -0
- package/locales/vi/package.json +19 -0
- package/locales/zh-Hans/index.cjs +97 -0
- package/locales/zh-Hans/index.d.cts +3 -0
- package/locales/zh-Hans/index.esm.d.mts +3 -0
- package/locales/zh-Hans/index.esm.mjs +95 -0
- package/locales/zh-Hans/package.json +19 -0
- package/locales/zh-Hant/index.cjs +97 -0
- package/locales/zh-Hant/index.d.cts +3 -0
- package/locales/zh-Hant/index.esm.d.mts +3 -0
- package/locales/zh-Hant/index.esm.mjs +95 -0
- package/locales/zh-Hant/package.json +19 -0
- package/package.json +184 -4
- package/src/components/MantineReactTable.tsx +38 -0
- package/src/components/body/MRT_TableBody.module.css +42 -0
- package/src/components/body/MRT_TableBody.tsx +214 -0
- package/src/components/body/MRT_TableBodyCell.module.css +107 -0
- package/src/components/body/MRT_TableBodyCell.tsx +355 -0
- package/src/components/body/MRT_TableBodyCellValue.tsx +114 -0
- package/src/components/body/MRT_TableBodyEmptyRow.tsx +89 -0
- package/src/components/body/MRT_TableBodyRow.module.css +261 -0
- package/src/components/body/MRT_TableBodyRow.tsx +278 -0
- package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +59 -0
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +59 -0
- package/src/components/body/MRT_TableDetailPanel.module.css +35 -0
- package/src/components/body/MRT_TableDetailPanel.tsx +132 -0
- package/src/components/buttons/MRT_ColumnPinningButtons.module.css +11 -0
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +69 -0
- package/src/components/buttons/MRT_CopyButton.module.css +27 -0
- package/src/components/buttons/MRT_CopyButton.tsx +84 -0
- package/src/components/buttons/MRT_EditActionButtons.module.css +4 -0
- package/src/components/buttons/MRT_EditActionButtons.tsx +139 -0
- package/src/components/buttons/MRT_ExpandAllButton.module.css +26 -0
- package/src/components/buttons/MRT_ExpandAllButton.tsx +84 -0
- package/src/components/buttons/MRT_ExpandButton.module.css +37 -0
- package/src/components/buttons/MRT_ExpandButton.tsx +121 -0
- package/src/components/buttons/MRT_GrabHandleButton.module.css +6 -0
- package/src/components/buttons/MRT_GrabHandleButton.tsx +65 -0
- package/src/components/buttons/MRT_RowPinButton.tsx +84 -0
- package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +46 -0
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +66 -0
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +45 -0
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +59 -0
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +52 -0
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +87 -0
- package/src/components/footer/MRT_TableFooter.module.css +17 -0
- package/src/components/footer/MRT_TableFooter.tsx +70 -0
- package/src/components/footer/MRT_TableFooterCell.module.css +59 -0
- package/src/components/footer/MRT_TableFooterCell.tsx +126 -0
- package/src/components/footer/MRT_TableFooterRow.module.css +10 -0
- package/src/components/footer/MRT_TableFooterRow.tsx +111 -0
- package/src/components/head/MRT_TableHead.module.css +32 -0
- package/src/components/head/MRT_TableHead.tsx +106 -0
- package/src/components/head/MRT_TableHeadCell.module.css +172 -0
- package/src/components/head/MRT_TableHeadCell.tsx +317 -0
- package/src/components/head/MRT_TableHeadCellFilterContainer.module.css +5 -0
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +123 -0
- package/src/components/head/MRT_TableHeadCellFilterLabel.module.css +14 -0
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +176 -0
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +82 -0
- package/src/components/head/MRT_TableHeadCellResizeHandle.module.css +44 -0
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +68 -0
- package/src/components/head/MRT_TableHeadCellSortLabel.module.css +22 -0
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +90 -0
- package/src/components/head/MRT_TableHeadRow.module.css +12 -0
- package/src/components/head/MRT_TableHeadRow.tsx +105 -0
- package/src/components/inputs/MRT_EditCellTextInput.tsx +214 -0
- package/src/components/inputs/MRT_FilterCheckBox.module.css +4 -0
- package/src/components/inputs/MRT_FilterCheckbox.tsx +80 -0
- package/src/components/inputs/MRT_FilterRangeFields.module.css +5 -0
- package/src/components/inputs/MRT_FilterRangeFields.tsx +36 -0
- package/src/components/inputs/MRT_FilterRangeSlider.module.css +6 -0
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +107 -0
- package/src/components/inputs/MRT_FilterTextInput.module.css +27 -0
- package/src/components/inputs/MRT_FilterTextInput.tsx +418 -0
- package/src/components/inputs/MRT_GlobalFilterTextInput.module.css +11 -0
- package/src/components/inputs/MRT_GlobalFilterTextInput.tsx +142 -0
- package/src/components/inputs/MRT_SelectCheckbox.tsx +138 -0
- package/src/components/menus/MRT_ColumnActionMenu.module.css +7 -0
- package/src/components/menus/MRT_ColumnActionMenu.tsx +288 -0
- package/src/components/menus/MRT_FilterOptionMenu.module.css +6 -0
- package/src/components/menus/MRT_FilterOptionMenu.tsx +279 -0
- package/src/components/menus/MRT_RowActionMenu.tsx +75 -0
- package/src/components/menus/MRT_ShowHideColumnsMenu.module.css +10 -0
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +136 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.module.css +35 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +171 -0
- package/src/components/modals/MRT_EditRowModal.tsx +98 -0
- package/src/components/table/MRT_Table.module.css +7 -0
- package/src/components/table/MRT_Table.tsx +155 -0
- package/src/components/table/MRT_TableContainer.module.css +32 -0
- package/src/components/table/MRT_TableContainer.tsx +124 -0
- package/src/components/table/MRT_TablePaper.module.css +88 -0
- package/src/components/table/MRT_TablePaper.tsx +91 -0
- package/src/components/toolbar/MRT_BottomToolbar.module.css +40 -0
- package/src/components/toolbar/MRT_BottomToolbar.tsx +99 -0
- package/src/components/toolbar/MRT_ProgressBar.module.css +10 -0
- package/src/components/toolbar/MRT_ProgressBar.tsx +54 -0
- package/src/components/toolbar/MRT_TablePagination.module.css +20 -0
- package/src/components/toolbar/MRT_TablePagination.tsx +175 -0
- package/src/components/toolbar/MRT_ToolbarAlertBanner.module.css +37 -0
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +169 -0
- package/src/components/toolbar/MRT_ToolbarDropZone.module.css +23 -0
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +68 -0
- package/src/components/toolbar/MRT_ToolbarInternalButtons.module.css +6 -0
- package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +74 -0
- package/src/components/toolbar/MRT_TopToolbar.module.css +24 -0
- package/src/components/toolbar/MRT_TopToolbar.tsx +127 -0
- package/src/components/toolbar/common.styles.module.css +10 -0
- package/src/fns/aggregationFns.ts +3 -0
- package/src/fns/filterFns.ts +243 -0
- package/src/fns/sortingFns.ts +34 -0
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +25 -0
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +32 -0
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +94 -0
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +32 -0
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +26 -0
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +36 -0
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +36 -0
- package/src/hooks/useMRT_ColumnVirtualizer.ts +135 -0
- package/src/hooks/useMRT_Effects.ts +109 -0
- package/src/hooks/useMRT_RowVirtualizer.ts +101 -0
- package/src/hooks/useMRT_Rows.ts +47 -0
- package/src/hooks/useMRT_TableInstance.ts +320 -0
- package/src/hooks/useMRT_TableOptions.ts +300 -0
- package/src/hooks/useMRT_TableSnapshot.ts +134 -0
- package/src/hooks/useMRT_VirtualizerScrollElement.ts +31 -0
- package/src/hooks/useMantineReactTable.ts +23 -0
- package/src/icons.ts +108 -0
- package/src/index.ts +91 -0
- package/src/locales/ar.ts +96 -0
- package/src/locales/az.ts +96 -0
- package/src/locales/bg.ts +96 -0
- package/src/locales/cs.ts +97 -0
- package/src/locales/da.ts +96 -0
- package/src/locales/de.ts +96 -0
- package/src/locales/el.ts +96 -0
- package/src/locales/en.ts +96 -0
- package/src/locales/es.ts +96 -0
- package/src/locales/et.ts +97 -0
- package/src/locales/fa.ts +96 -0
- package/src/locales/fi.ts +97 -0
- package/src/locales/fr.ts +96 -0
- package/src/locales/he.ts +96 -0
- package/src/locales/hr.ts +96 -0
- package/src/locales/hu.ts +96 -0
- package/src/locales/hy.ts +96 -0
- package/src/locales/id.ts +97 -0
- package/src/locales/it.ts +96 -0
- package/src/locales/ja.ts +96 -0
- package/src/locales/ko.ts +96 -0
- package/src/locales/nl.ts +96 -0
- package/src/locales/no.ts +97 -0
- package/src/locales/np.ts +97 -0
- package/src/locales/pl.ts +96 -0
- package/src/locales/pt-BR.ts +96 -0
- package/src/locales/pt.ts +96 -0
- package/src/locales/ro.ts +96 -0
- package/src/locales/ru.ts +96 -0
- package/src/locales/sk.ts +97 -0
- package/src/locales/sr-Cyrl-RS.ts +96 -0
- package/src/locales/sr-Latn-RS.ts +96 -0
- package/src/locales/sv.ts +96 -0
- package/src/locales/th.ts +97 -0
- package/src/locales/tr.ts +96 -0
- package/src/locales/uk.ts +96 -0
- package/src/locales/vi.ts +96 -0
- package/src/locales/zh-Hans.ts +95 -0
- package/src/locales/zh-Hant.ts +95 -0
- package/src/types.ts +1299 -0
- package/src/typings.d.ts +1 -0
- package/src/utils/column.utils.ts +157 -0
- package/src/utils/displayColumn.utils.ts +153 -0
- package/src/utils/row.utils.ts +263 -0
- package/src/utils/snapshot.utils.ts +97 -0
- package/src/utils/style.utils.ts +32 -0
- package/src/utils/tanstack.helpers.ts +66 -0
- package/src/utils/utils.ts +15 -0
- package/src/utils/virtualization.utils.ts +85 -0
- package/styles.css +1381 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
|
|
5
|
+
import classes from './MRT_TableContainer.module.css';
|
|
6
|
+
|
|
7
|
+
import { useEffect, useLayoutEffect, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
import { Box, type BoxProps, LoadingOverlay } from '@mantine/core';
|
|
10
|
+
|
|
11
|
+
import { MRT_Table } from './MRT_Table';
|
|
12
|
+
|
|
13
|
+
import { type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
14
|
+
import { assignRef, parseFromValuesOrFunc } from '../../utils/utils';
|
|
15
|
+
import { MRT_EditRowModal } from '../modals/MRT_EditRowModal';
|
|
16
|
+
const useIsomorphicLayoutEffect =
|
|
17
|
+
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
18
|
+
interface Props<TData extends MRT_RowData> extends BoxProps {
|
|
19
|
+
table: MRT_TableInstance<TData>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const MRT_TableContainer = <TData extends MRT_RowData>({
|
|
23
|
+
table,
|
|
24
|
+
...rest
|
|
25
|
+
}: Props<TData>) => {
|
|
26
|
+
const {
|
|
27
|
+
getState,
|
|
28
|
+
options: {
|
|
29
|
+
createDisplayMode,
|
|
30
|
+
editDisplayMode,
|
|
31
|
+
enableStickyHeader,
|
|
32
|
+
mantineLoadingOverlayProps,
|
|
33
|
+
mantineTableContainerProps,
|
|
34
|
+
withScrollArea,
|
|
35
|
+
},
|
|
36
|
+
refs: { bottomToolbarRef, tableContainerRef, tableHeadRef, topToolbarRef },
|
|
37
|
+
} = table;
|
|
38
|
+
const {
|
|
39
|
+
creatingRow,
|
|
40
|
+
density,
|
|
41
|
+
editingRow,
|
|
42
|
+
isFullScreen,
|
|
43
|
+
isLoading,
|
|
44
|
+
showLoadingOverlay,
|
|
45
|
+
} = getState();
|
|
46
|
+
|
|
47
|
+
const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
|
|
48
|
+
const [scrollOffset, setScrollOffset] = useState(0);
|
|
49
|
+
|
|
50
|
+
const tableContainerProps = {
|
|
51
|
+
...parseFromValuesOrFunc(mantineTableContainerProps, { table }),
|
|
52
|
+
...rest,
|
|
53
|
+
};
|
|
54
|
+
const loadingOverlayProps = parseFromValuesOrFunc(
|
|
55
|
+
mantineLoadingOverlayProps,
|
|
56
|
+
{ table },
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
useIsomorphicLayoutEffect(() => {
|
|
60
|
+
const topToolbarHeight =
|
|
61
|
+
typeof document !== 'undefined'
|
|
62
|
+
? (topToolbarRef.current?.offsetHeight ?? 0)
|
|
63
|
+
: 0;
|
|
64
|
+
|
|
65
|
+
const bottomToolbarHeight =
|
|
66
|
+
typeof document !== 'undefined'
|
|
67
|
+
? (bottomToolbarRef?.current?.offsetHeight ?? 0)
|
|
68
|
+
: 0;
|
|
69
|
+
|
|
70
|
+
setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
|
|
71
|
+
}); //no dependency list: the bottom toolbar ref attaches after this effect first runs
|
|
72
|
+
|
|
73
|
+
useIsomorphicLayoutEffect(() => {
|
|
74
|
+
const setOffset = () => {
|
|
75
|
+
const offset =
|
|
76
|
+
typeof document !== 'undefined'
|
|
77
|
+
? (tableHeadRef?.current?.offsetHeight ?? 0)
|
|
78
|
+
: 0;
|
|
79
|
+
setScrollOffset(offset);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
setOffset();
|
|
83
|
+
const timeout = setTimeout(setOffset, 150);
|
|
84
|
+
return () => clearTimeout(timeout);
|
|
85
|
+
}, [tableHeadRef?.current?.offsetHeight, density]);
|
|
86
|
+
|
|
87
|
+
const createModalOpen = createDisplayMode === 'modal' && creatingRow;
|
|
88
|
+
const editModalOpen = editDisplayMode === 'modal' && editingRow;
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Box
|
|
92
|
+
{...tableContainerProps}
|
|
93
|
+
__vars={{
|
|
94
|
+
'--mrt-scroll-offset': `${scrollOffset}px`,
|
|
95
|
+
'--mrt-top-toolbar-height': `${totalToolbarHeight}`,
|
|
96
|
+
...tableContainerProps?.__vars,
|
|
97
|
+
}}
|
|
98
|
+
className={clsx(
|
|
99
|
+
'mrt-table-container',
|
|
100
|
+
classes.root,
|
|
101
|
+
enableStickyHeader && classes['root-sticky'],
|
|
102
|
+
isFullScreen && classes['root-fullscreen'],
|
|
103
|
+
withScrollArea && classes['root-scroll-area'],
|
|
104
|
+
tableContainerProps?.className,
|
|
105
|
+
)}
|
|
106
|
+
ref={(node: HTMLDivElement) => {
|
|
107
|
+
if (node) {
|
|
108
|
+
tableContainerRef.current = node;
|
|
109
|
+
assignRef(tableContainerProps?.ref, node);
|
|
110
|
+
}
|
|
111
|
+
}}
|
|
112
|
+
>
|
|
113
|
+
<LoadingOverlay
|
|
114
|
+
visible={isLoading || showLoadingOverlay}
|
|
115
|
+
zIndex={2}
|
|
116
|
+
{...loadingOverlayProps}
|
|
117
|
+
/>
|
|
118
|
+
<MRT_Table table={table} />
|
|
119
|
+
{(createModalOpen || editModalOpen) && (
|
|
120
|
+
<MRT_EditRowModal open table={table} />
|
|
121
|
+
)}
|
|
122
|
+
</Box>
|
|
123
|
+
);
|
|
124
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
/* default background color for everything */
|
|
3
|
+
--mrt-base-background-color: var(--mantine-color-body);
|
|
4
|
+
|
|
5
|
+
@mixin light-root {
|
|
6
|
+
--mrt-striped-row-background-color: darken(
|
|
7
|
+
var(--mrt-base-background-color),
|
|
8
|
+
0.05
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
@mixin dark-root {
|
|
12
|
+
--mrt-striped-row-background-color: lighten(
|
|
13
|
+
var(--mrt-base-background-color),
|
|
14
|
+
0.04
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* row hover */
|
|
19
|
+
@mixin light-root {
|
|
20
|
+
--mrt-row-hover-background-color: darken(
|
|
21
|
+
var(--mrt-base-background-color),
|
|
22
|
+
0.08
|
|
23
|
+
);
|
|
24
|
+
--mrt-striped-row-hover-background-color: darken(
|
|
25
|
+
var(--mrt-striped-row-background-color),
|
|
26
|
+
0.12
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
@mixin dark-root {
|
|
30
|
+
--mrt-row-hover-background-color: lighten(
|
|
31
|
+
var(--mrt-base-background-color),
|
|
32
|
+
0.08
|
|
33
|
+
);
|
|
34
|
+
--mrt-striped-row-hover-background-color: lighten(
|
|
35
|
+
var(--mrt-striped-row-background-color),
|
|
36
|
+
0.08
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* row selection */
|
|
41
|
+
--mrt-selected-row-background-color: alpha(
|
|
42
|
+
var(--mantine-primary-color-light),
|
|
43
|
+
0.8
|
|
44
|
+
);
|
|
45
|
+
@mixin light-root {
|
|
46
|
+
--mrt-selected-row-hover-background-color: darken(
|
|
47
|
+
var(--mantine-primary-color-light-hover),
|
|
48
|
+
0.05
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
@mixin dark-root {
|
|
52
|
+
--mrt-selected-row-hover-background-color: lighten(
|
|
53
|
+
var(--mantine-primary-color-light-hover),
|
|
54
|
+
0.05
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* row pinning */
|
|
59
|
+
--mrt-pinned-row-background-color: var(--mrt-selected-row-background-color);
|
|
60
|
+
--mrt-pinned-row-hover-background-color: var(
|
|
61
|
+
--mrt-selected-row-hover-background-color
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
/* column pinning */
|
|
65
|
+
@mixin light-root {
|
|
66
|
+
--mrt-pinned-column-background-color: darken(
|
|
67
|
+
var(--mrt-base-background-color),
|
|
68
|
+
0.01
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
@mixin dark-root {
|
|
72
|
+
--mrt-pinned-column-background-color: darken(
|
|
73
|
+
var(--mrt-base-background-color),
|
|
74
|
+
0.05
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* cell borders */
|
|
79
|
+
--mrt-dragging-hovered-border-color: var(--mantine-primary-color-filled);
|
|
80
|
+
--mrt-dragging-drag-border-color: var(--mantine-color-gray-7);
|
|
81
|
+
--mrt-resize-column-border-color: var(--mantine-primary-color-filled);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.root {
|
|
85
|
+
background-color: var(--mrt-base-background-color);
|
|
86
|
+
overflow: hidden;
|
|
87
|
+
transition: all 150ms ease-in-out;
|
|
88
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
|
|
5
|
+
import classes from './MRT_TablePaper.module.css';
|
|
6
|
+
|
|
7
|
+
import { Paper, type PaperProps } from '@mantine/core';
|
|
8
|
+
|
|
9
|
+
import { MRT_TableContainer } from './MRT_TableContainer';
|
|
10
|
+
|
|
11
|
+
import { type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
12
|
+
import { assignRef, parseFromValuesOrFunc } from '../../utils/utils';
|
|
13
|
+
import { MRT_BottomToolbar } from '../toolbar/MRT_BottomToolbar';
|
|
14
|
+
import { MRT_TopToolbar } from '../toolbar/MRT_TopToolbar';
|
|
15
|
+
|
|
16
|
+
interface Props<TData extends MRT_RowData> extends PaperProps {
|
|
17
|
+
table: MRT_TableInstance<TData>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const MRT_TablePaper = <TData extends MRT_RowData>({
|
|
21
|
+
table,
|
|
22
|
+
...rest
|
|
23
|
+
}: Props<TData>) => {
|
|
24
|
+
const {
|
|
25
|
+
getState,
|
|
26
|
+
options: {
|
|
27
|
+
enableBottomToolbar,
|
|
28
|
+
enableTopToolbar,
|
|
29
|
+
mantinePaperProps,
|
|
30
|
+
renderBottomToolbar,
|
|
31
|
+
renderTopToolbar,
|
|
32
|
+
},
|
|
33
|
+
refs: { tablePaperRef },
|
|
34
|
+
} = table;
|
|
35
|
+
const { isFullScreen } = getState();
|
|
36
|
+
|
|
37
|
+
const tablePaperProps = {
|
|
38
|
+
...parseFromValuesOrFunc(mantinePaperProps, { table }),
|
|
39
|
+
...rest,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Paper
|
|
44
|
+
shadow="xs"
|
|
45
|
+
withBorder
|
|
46
|
+
{...tablePaperProps}
|
|
47
|
+
className={clsx(
|
|
48
|
+
'mrt-table-paper',
|
|
49
|
+
classes.root,
|
|
50
|
+
isFullScreen && 'mrt-table-paper-fullscreen',
|
|
51
|
+
tablePaperProps?.className,
|
|
52
|
+
)}
|
|
53
|
+
ref={(ref: HTMLDivElement) => {
|
|
54
|
+
tablePaperRef.current = ref;
|
|
55
|
+
assignRef(tablePaperProps?.ref, ref);
|
|
56
|
+
}}
|
|
57
|
+
// rare case where we should use inline styles to guarantee highest specificity
|
|
58
|
+
style={(theme) => ({
|
|
59
|
+
zIndex: isFullScreen ? 200 : undefined,
|
|
60
|
+
...parseFromValuesOrFunc(tablePaperProps?.style, theme),
|
|
61
|
+
...(isFullScreen
|
|
62
|
+
? {
|
|
63
|
+
border: 0,
|
|
64
|
+
borderRadius: 0,
|
|
65
|
+
bottom: 0,
|
|
66
|
+
height: '100vh',
|
|
67
|
+
left: 0,
|
|
68
|
+
margin: 0,
|
|
69
|
+
maxHeight: '100vh',
|
|
70
|
+
maxWidth: '100vw',
|
|
71
|
+
padding: 0,
|
|
72
|
+
position: 'fixed',
|
|
73
|
+
right: 0,
|
|
74
|
+
top: 0,
|
|
75
|
+
width: '100vw',
|
|
76
|
+
}
|
|
77
|
+
: null),
|
|
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,40 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
background-color: var(--mrt-base-background-color);
|
|
3
|
+
border-top: 1px solid
|
|
4
|
+
light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4));
|
|
5
|
+
bottom: var(--mrt-bottom-toolbar-bottom);
|
|
6
|
+
box-shadow: 0 1px 2px -1px color-mix(
|
|
7
|
+
in srgb,
|
|
8
|
+
var(--mantine-color-black) 10%,
|
|
9
|
+
transparent
|
|
10
|
+
) inset;
|
|
11
|
+
left: 0;
|
|
12
|
+
right: 0;
|
|
13
|
+
position: relative;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.root-fullscreen {
|
|
17
|
+
position: fixed !important;
|
|
18
|
+
bottom: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.custom-toolbar-container {
|
|
22
|
+
align-items: center;
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
display: flex;
|
|
25
|
+
justify-content: space-between;
|
|
26
|
+
padding: rem(8px);
|
|
27
|
+
width: 100%;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.paginator-container {
|
|
31
|
+
display: flex;
|
|
32
|
+
justify-content: flex-end;
|
|
33
|
+
right: 0;
|
|
34
|
+
top: 0;
|
|
35
|
+
position: absolute;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.paginator-container-alert-banner {
|
|
39
|
+
position: relative !important;
|
|
40
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
|
|
5
|
+
import commonClasses from './common.styles.module.css';
|
|
6
|
+
import classes from './MRT_BottomToolbar.module.css';
|
|
7
|
+
|
|
8
|
+
import { Box, type BoxProps } from '@mantine/core';
|
|
9
|
+
import { useMediaQuery } from '@mantine/hooks';
|
|
10
|
+
|
|
11
|
+
import { MRT_ProgressBar } from './MRT_ProgressBar';
|
|
12
|
+
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
13
|
+
import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
14
|
+
import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
|
|
15
|
+
|
|
16
|
+
import { type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
17
|
+
import { assignRef, parseFromValuesOrFunc } from '../../utils/utils';
|
|
18
|
+
|
|
19
|
+
interface Props<TData extends MRT_RowData> extends BoxProps {
|
|
20
|
+
table: MRT_TableInstance<TData>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const MRT_BottomToolbar = <TData extends MRT_RowData>({
|
|
24
|
+
table,
|
|
25
|
+
...rest
|
|
26
|
+
}: Props<TData>) => {
|
|
27
|
+
const {
|
|
28
|
+
getState,
|
|
29
|
+
options: {
|
|
30
|
+
enablePagination,
|
|
31
|
+
mantineBottomToolbarProps,
|
|
32
|
+
positionPagination,
|
|
33
|
+
positionToolbarAlertBanner,
|
|
34
|
+
positionToolbarDropZone,
|
|
35
|
+
renderBottomToolbarCustomActions,
|
|
36
|
+
},
|
|
37
|
+
refs: { bottomToolbarRef },
|
|
38
|
+
} = table;
|
|
39
|
+
const { isFullScreen } = getState();
|
|
40
|
+
|
|
41
|
+
const isMobile = useMediaQuery('(max-width: 720px)');
|
|
42
|
+
|
|
43
|
+
const toolbarProps = {
|
|
44
|
+
...parseFromValuesOrFunc(mantineBottomToolbarProps, {
|
|
45
|
+
table,
|
|
46
|
+
}),
|
|
47
|
+
...rest,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const stackAlertBanner = isMobile || !!renderBottomToolbarCustomActions;
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Box
|
|
54
|
+
{...toolbarProps}
|
|
55
|
+
className={clsx(
|
|
56
|
+
'mrt-bottom-toolbar',
|
|
57
|
+
classes.root,
|
|
58
|
+
commonClasses['common-toolbar-styles'],
|
|
59
|
+
isFullScreen && classes['root-fullscreen'],
|
|
60
|
+
toolbarProps?.className,
|
|
61
|
+
)}
|
|
62
|
+
ref={(node: HTMLDivElement) => {
|
|
63
|
+
if (node) {
|
|
64
|
+
bottomToolbarRef.current = node;
|
|
65
|
+
assignRef(toolbarProps?.ref, node);
|
|
66
|
+
}
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
<MRT_ProgressBar isTopToolbar={false} table={table} />
|
|
70
|
+
{positionToolbarAlertBanner === 'bottom' && (
|
|
71
|
+
<MRT_ToolbarAlertBanner
|
|
72
|
+
stackAlertBanner={stackAlertBanner}
|
|
73
|
+
table={table}
|
|
74
|
+
/>
|
|
75
|
+
)}
|
|
76
|
+
{['both', 'bottom'].includes(positionToolbarDropZone ?? '') && (
|
|
77
|
+
<MRT_ToolbarDropZone table={table} />
|
|
78
|
+
)}
|
|
79
|
+
<Box className={classes['custom-toolbar-container']}>
|
|
80
|
+
{renderBottomToolbarCustomActions ? (
|
|
81
|
+
renderBottomToolbarCustomActions({ table })
|
|
82
|
+
) : (
|
|
83
|
+
<span />
|
|
84
|
+
)}
|
|
85
|
+
<Box
|
|
86
|
+
className={clsx(
|
|
87
|
+
classes['paginator-container'],
|
|
88
|
+
stackAlertBanner && classes['paginator-container-alert-banner'],
|
|
89
|
+
)}
|
|
90
|
+
>
|
|
91
|
+
{enablePagination &&
|
|
92
|
+
['both', 'bottom'].includes(positionPagination ?? '') && (
|
|
93
|
+
<MRT_TablePagination position="bottom" table={table} />
|
|
94
|
+
)}
|
|
95
|
+
</Box>
|
|
96
|
+
</Box>
|
|
97
|
+
</Box>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
|
|
5
|
+
import classes from './MRT_ProgressBar.module.css';
|
|
6
|
+
|
|
7
|
+
import { Collapse, Progress, type ProgressProps } from '@mantine/core';
|
|
8
|
+
|
|
9
|
+
import { type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
10
|
+
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
11
|
+
|
|
12
|
+
interface Props<TData extends MRT_RowData> extends Partial<ProgressProps> {
|
|
13
|
+
isTopToolbar: boolean;
|
|
14
|
+
table: MRT_TableInstance<TData>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const MRT_ProgressBar = <TData extends MRT_RowData>({
|
|
18
|
+
isTopToolbar,
|
|
19
|
+
table,
|
|
20
|
+
...rest
|
|
21
|
+
}: Props<TData>) => {
|
|
22
|
+
const {
|
|
23
|
+
getState,
|
|
24
|
+
options: { mantineProgressProps },
|
|
25
|
+
} = table;
|
|
26
|
+
const { isSaving, showProgressBars } = getState();
|
|
27
|
+
|
|
28
|
+
const linearProgressProps = {
|
|
29
|
+
...parseFromValuesOrFunc(mantineProgressProps, {
|
|
30
|
+
isTopToolbar,
|
|
31
|
+
table,
|
|
32
|
+
}),
|
|
33
|
+
...rest,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Collapse
|
|
38
|
+
className={clsx(
|
|
39
|
+
classes.collapse,
|
|
40
|
+
isTopToolbar && classes['collapse-top'],
|
|
41
|
+
)}
|
|
42
|
+
expanded={isSaving || showProgressBars}
|
|
43
|
+
>
|
|
44
|
+
<Progress
|
|
45
|
+
animated
|
|
46
|
+
aria-busy="true"
|
|
47
|
+
aria-label="Loading"
|
|
48
|
+
radius={0}
|
|
49
|
+
value={100}
|
|
50
|
+
{...linearProgressProps}
|
|
51
|
+
/>
|
|
52
|
+
</Collapse>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.root {
|
|
2
|
+
display: flex;
|
|
3
|
+
z-index: 2;
|
|
4
|
+
gap: var(--mantine-spacing-lg);
|
|
5
|
+
align-items: center;
|
|
6
|
+
justify-content: space-between;
|
|
7
|
+
padding-right: var(--mantine-spacing-sm);
|
|
8
|
+
padding-left: var(--mantine-spacing-sm);
|
|
9
|
+
padding-top: var(--mantine-spacing-xs);
|
|
10
|
+
padding-bottom: var(--mantine-spacing-xs);
|
|
11
|
+
.pagesize {
|
|
12
|
+
input {
|
|
13
|
+
width: calc(5rem * var(--mantine-scale));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.with-top-margin {
|
|
19
|
+
margin-top: 3rem;
|
|
20
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
|
|
5
|
+
import classes from './MRT_TablePagination.module.css';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
ActionIcon,
|
|
9
|
+
Box,
|
|
10
|
+
extractStyleProps,
|
|
11
|
+
Group,
|
|
12
|
+
Pagination,
|
|
13
|
+
type PaginationProps,
|
|
14
|
+
Select,
|
|
15
|
+
Text,
|
|
16
|
+
} from '@mantine/core';
|
|
17
|
+
|
|
18
|
+
import { type MRT_RowData, type MRT_TableInstance } from '../../types';
|
|
19
|
+
import { parseFromValuesOrFunc } from '../../utils/utils';
|
|
20
|
+
|
|
21
|
+
const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100].map((x) =>
|
|
22
|
+
x.toString(),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
interface Props<TData extends MRT_RowData> extends Partial<PaginationProps> {
|
|
26
|
+
position?: 'bottom' | 'top';
|
|
27
|
+
table: MRT_TableInstance<TData>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
31
|
+
position = 'bottom',
|
|
32
|
+
table,
|
|
33
|
+
...props
|
|
34
|
+
}: Props<TData>) => {
|
|
35
|
+
const {
|
|
36
|
+
getPrePaginationRowModel,
|
|
37
|
+
getState,
|
|
38
|
+
options: {
|
|
39
|
+
enableToolbarInternalActions,
|
|
40
|
+
icons: {
|
|
41
|
+
IconChevronLeft,
|
|
42
|
+
IconChevronLeftPipe,
|
|
43
|
+
IconChevronRight,
|
|
44
|
+
IconChevronRightPipe,
|
|
45
|
+
},
|
|
46
|
+
localization,
|
|
47
|
+
mantinePaginationProps,
|
|
48
|
+
paginationDisplayMode,
|
|
49
|
+
rowCount,
|
|
50
|
+
},
|
|
51
|
+
setPageIndex,
|
|
52
|
+
setPageSize,
|
|
53
|
+
} = table;
|
|
54
|
+
const {
|
|
55
|
+
pagination: { pageIndex = 0, pageSize = 10 },
|
|
56
|
+
showGlobalFilter,
|
|
57
|
+
} = getState();
|
|
58
|
+
|
|
59
|
+
const paginationProps = {
|
|
60
|
+
...parseFromValuesOrFunc(mantinePaginationProps, {
|
|
61
|
+
table,
|
|
62
|
+
}),
|
|
63
|
+
...props,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
|
|
67
|
+
const numberOfPages = Math.ceil(totalRowCount / pageSize);
|
|
68
|
+
const showFirstLastPageButtons = numberOfPages > 2;
|
|
69
|
+
const firstRowIndex = pageIndex * pageSize;
|
|
70
|
+
const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount);
|
|
71
|
+
|
|
72
|
+
const {
|
|
73
|
+
rowsPerPageOptions = defaultRowsPerPage,
|
|
74
|
+
showRowsPerPage = true,
|
|
75
|
+
withEdges = showFirstLastPageButtons,
|
|
76
|
+
...rest
|
|
77
|
+
} = paginationProps ?? {};
|
|
78
|
+
|
|
79
|
+
const needsTopMargin =
|
|
80
|
+
position === 'top' && enableToolbarInternalActions && !showGlobalFilter;
|
|
81
|
+
|
|
82
|
+
//the 'pages' mode passes these to the Mantine Pagination component instead
|
|
83
|
+
const isDefaultDisplayMode = paginationDisplayMode === 'default';
|
|
84
|
+
const { styleProps } = extractStyleProps(rest);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<Box
|
|
88
|
+
{...(isDefaultDisplayMode ? styleProps : undefined)}
|
|
89
|
+
className={clsx(
|
|
90
|
+
'mrt-table-pagination',
|
|
91
|
+
classes.root,
|
|
92
|
+
needsTopMargin && classes['with-top-margin'],
|
|
93
|
+
isDefaultDisplayMode && rest.className,
|
|
94
|
+
)}
|
|
95
|
+
style={isDefaultDisplayMode ? rest.style : undefined}
|
|
96
|
+
>
|
|
97
|
+
{paginationProps?.showRowsPerPage !== false && (
|
|
98
|
+
<Group gap="xs">
|
|
99
|
+
<Text id="rpp-label">{localization.rowsPerPage}</Text>
|
|
100
|
+
<Select
|
|
101
|
+
allowDeselect={false}
|
|
102
|
+
aria-labelledby="rpp-label"
|
|
103
|
+
className={classes.pagesize}
|
|
104
|
+
data={paginationProps?.rowsPerPageOptions ?? defaultRowsPerPage}
|
|
105
|
+
onChange={(value: null | string) => setPageSize(+(value as string))}
|
|
106
|
+
value={pageSize.toString()}
|
|
107
|
+
/>
|
|
108
|
+
</Group>
|
|
109
|
+
)}
|
|
110
|
+
{paginationDisplayMode === 'pages' ? (
|
|
111
|
+
<Pagination
|
|
112
|
+
firstIcon={IconChevronLeftPipe}
|
|
113
|
+
lastIcon={IconChevronRightPipe}
|
|
114
|
+
nextIcon={IconChevronRight}
|
|
115
|
+
onChange={(newPageIndex) => setPageIndex(newPageIndex - 1)}
|
|
116
|
+
previousIcon={IconChevronLeft}
|
|
117
|
+
total={numberOfPages}
|
|
118
|
+
value={pageIndex + 1}
|
|
119
|
+
withEdges={withEdges}
|
|
120
|
+
{...rest}
|
|
121
|
+
/>
|
|
122
|
+
) : paginationDisplayMode === 'default' ? (
|
|
123
|
+
<>
|
|
124
|
+
<Text>{`${
|
|
125
|
+
lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString()
|
|
126
|
+
}-${lastRowIndex.toLocaleString()} ${
|
|
127
|
+
localization.of
|
|
128
|
+
} ${totalRowCount.toLocaleString()}`}</Text>
|
|
129
|
+
<Group gap={6}>
|
|
130
|
+
{withEdges && (
|
|
131
|
+
<ActionIcon
|
|
132
|
+
aria-label={localization.goToFirstPage}
|
|
133
|
+
color="gray"
|
|
134
|
+
disabled={pageIndex <= 0}
|
|
135
|
+
onClick={() => setPageIndex(0)}
|
|
136
|
+
variant="subtle"
|
|
137
|
+
>
|
|
138
|
+
<IconChevronLeftPipe />
|
|
139
|
+
</ActionIcon>
|
|
140
|
+
)}
|
|
141
|
+
<ActionIcon
|
|
142
|
+
aria-label={localization.goToPreviousPage}
|
|
143
|
+
color="gray"
|
|
144
|
+
disabled={pageIndex <= 0}
|
|
145
|
+
onClick={() => setPageIndex(pageIndex - 1)}
|
|
146
|
+
variant="subtle"
|
|
147
|
+
>
|
|
148
|
+
<IconChevronLeft />
|
|
149
|
+
</ActionIcon>
|
|
150
|
+
<ActionIcon
|
|
151
|
+
aria-label={localization.goToNextPage}
|
|
152
|
+
color="gray"
|
|
153
|
+
disabled={lastRowIndex >= totalRowCount}
|
|
154
|
+
onClick={() => setPageIndex(pageIndex + 1)}
|
|
155
|
+
variant="subtle"
|
|
156
|
+
>
|
|
157
|
+
<IconChevronRight />
|
|
158
|
+
</ActionIcon>
|
|
159
|
+
{withEdges && (
|
|
160
|
+
<ActionIcon
|
|
161
|
+
aria-label={localization.goToLastPage}
|
|
162
|
+
color="gray"
|
|
163
|
+
disabled={lastRowIndex >= totalRowCount}
|
|
164
|
+
onClick={() => setPageIndex(numberOfPages - 1)}
|
|
165
|
+
variant="subtle"
|
|
166
|
+
>
|
|
167
|
+
<IconChevronRightPipe />
|
|
168
|
+
</ActionIcon>
|
|
169
|
+
)}
|
|
170
|
+
</Group>
|
|
171
|
+
</>
|
|
172
|
+
) : null}
|
|
173
|
+
</Box>
|
|
174
|
+
);
|
|
175
|
+
};
|