material-react-table 2.0.0-alpha.3 → 2.0.0-alpha.4
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/dist/cjs/index.js +58 -33
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/icons.d.ts +4 -0
- package/dist/cjs/types/toolbar/MRT_TablePagination.d.ts +2 -2
- package/dist/cjs/types/types.d.ts +9 -3
- package/dist/esm/material-react-table.esm.js +51 -33
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/icons.d.ts +4 -0
- package/dist/esm/types/toolbar/MRT_TablePagination.d.ts +2 -2
- package/dist/esm/types/types.d.ts +9 -3
- package/dist/index.d.ts +15 -5
- package/package.json +1 -1
- package/src/hooks/useMRT_Effects.ts +13 -2
- package/src/icons.ts +12 -0
- package/src/toolbar/MRT_TablePagination.tsx +124 -67
- package/src/types.ts +14 -6
@@ -2,6 +2,8 @@ export interface MRT_Icons {
|
|
2
2
|
ArrowDownwardIcon: any;
|
3
3
|
ArrowRightIcon: any;
|
4
4
|
CancelIcon: any;
|
5
|
+
ChevronLefIcon: any;
|
6
|
+
ChevronRightIcon: any;
|
5
7
|
ClearAllIcon: any;
|
6
8
|
CloseIcon: any;
|
7
9
|
DensityLargeIcon: any;
|
@@ -14,9 +16,11 @@ export interface MRT_Icons {
|
|
14
16
|
FilterAltIcon: any;
|
15
17
|
FilterListIcon: any;
|
16
18
|
FilterListOffIcon: any;
|
19
|
+
FirstPageIcon?: any;
|
17
20
|
FullscreenExitIcon: any;
|
18
21
|
FullscreenIcon: any;
|
19
22
|
KeyboardDoubleArrowDownIcon: any;
|
23
|
+
LastPageIcon?: any;
|
20
24
|
MoreHorizIcon: any;
|
21
25
|
MoreVertIcon: any;
|
22
26
|
PushPinIcon: any;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { type MRT_TableInstance } from '../types';
|
2
|
-
interface Props<TData extends Record<string, any
|
2
|
+
interface Props<TData extends Record<string, any> = {}> {
|
3
3
|
position?: 'bottom' | 'top';
|
4
4
|
table: MRT_TableInstance<TData>;
|
5
5
|
}
|
6
|
-
export declare const MRT_TablePagination: <TData extends Record<string, any
|
6
|
+
export declare const MRT_TablePagination: <TData extends Record<string, any> = {}>({ position, table, }: Props<TData>) => import("react/jsx-runtime").JSX.Element;
|
7
7
|
export {};
|
@@ -1,14 +1,15 @@
|
|
1
1
|
import { type Dispatch, type MutableRefObject, type ReactNode, type RefObject, type SetStateAction } from 'react';
|
2
2
|
import { type AggregationFn, type Cell, type Column, type ColumnDef, type ColumnFiltersState, type ColumnOrderState, type ColumnPinningState, type ColumnSizingInfoState, type ColumnSizingState, type DeepKeys, type ExpandedState, type FilterFn, type GroupingState, type Header, type HeaderGroup, type OnChangeFn, type PaginationState, type Row, type RowSelectionState, type SortingFn, type SortingState, type Table, type TableOptions, type TableState, type Updater, type VisibilityState } from '@tanstack/react-table';
|
3
3
|
import { type VirtualItem, type Virtualizer, type VirtualizerOptions } from '@tanstack/react-virtual';
|
4
|
-
import { type AutocompleteProps } from '@mui/material';
|
5
4
|
import { type AlertProps } from '@mui/material/Alert';
|
5
|
+
import { type AutocompleteProps } from '@mui/material/Autocomplete';
|
6
6
|
import { type ButtonProps } from '@mui/material/Button';
|
7
7
|
import { type CheckboxProps } from '@mui/material/Checkbox';
|
8
8
|
import { type ChipProps } from '@mui/material/Chip';
|
9
9
|
import { type DialogProps } from '@mui/material/Dialog';
|
10
10
|
import { type IconButtonProps } from '@mui/material/IconButton';
|
11
11
|
import { type LinearProgressProps } from '@mui/material/LinearProgress';
|
12
|
+
import { type PaginationProps } from '@mui/material/Pagination';
|
12
13
|
import { type PaperProps } from '@mui/material/Paper';
|
13
14
|
import { type RadioProps } from '@mui/material/Radio';
|
14
15
|
import { type SkeletonProps } from '@mui/material/Skeleton';
|
@@ -19,7 +20,6 @@ import { type TableCellProps } from '@mui/material/TableCell';
|
|
19
20
|
import { type TableContainerProps } from '@mui/material/TableContainer';
|
20
21
|
import { type TableFooterProps } from '@mui/material/TableFooter';
|
21
22
|
import { type TableHeadProps } from '@mui/material/TableHead';
|
22
|
-
import { type TablePaginationProps } from '@mui/material/TablePagination';
|
23
23
|
import { type TableRowProps } from '@mui/material/TableRow';
|
24
24
|
import { type TextFieldProps } from '@mui/material/TextField';
|
25
25
|
import { type ToolbarProps } from '@mui/material/Toolbar';
|
@@ -675,7 +675,13 @@ export type MRT_TableOptions<TData extends Record<string, any>> = Omit<Partial<T
|
|
675
675
|
}) => TableRowProps) | TableRowProps;
|
676
676
|
muiTablePaginationProps?: ((props: {
|
677
677
|
table: MRT_TableInstance<TData>;
|
678
|
-
}) => Partial<
|
678
|
+
}) => Partial<PaginationProps & {
|
679
|
+
rowsPerPageOptions?: number[];
|
680
|
+
showRowsPerPage?: boolean;
|
681
|
+
}>) | Partial<PaginationProps & {
|
682
|
+
rowsPerPageOptions?: number[];
|
683
|
+
showRowsPerPage?: boolean;
|
684
|
+
}>;
|
679
685
|
muiTablePaperProps?: ((props: {
|
680
686
|
table: MRT_TableInstance<TData>;
|
681
687
|
}) => PaperProps) | PaperProps;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
2
2
|
import Paper from '@mui/material/Paper';
|
3
|
-
import { useState, memo, useEffect, useMemo, useRef, useCallback, useLayoutEffect, Fragment as Fragment$1 } from 'react';
|
3
|
+
import { useState, memo, useEffect, useMemo, useRef, useCallback, useLayoutEffect, Fragment as Fragment$1, useReducer } from 'react';
|
4
4
|
import TableContainer from '@mui/material/TableContainer';
|
5
5
|
import { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';
|
6
6
|
import Table from '@mui/material/Table';
|
@@ -47,7 +47,10 @@ import CircularProgress from '@mui/material/CircularProgress';
|
|
47
47
|
import Toolbar from '@mui/material/Toolbar';
|
48
48
|
import useMediaQuery from '@mui/material/useMediaQuery';
|
49
49
|
import LinearProgress from '@mui/material/LinearProgress';
|
50
|
-
import
|
50
|
+
import InputLabel from '@mui/material/InputLabel';
|
51
|
+
import Pagination from '@mui/material/Pagination';
|
52
|
+
import PaginationItem from '@mui/material/PaginationItem';
|
53
|
+
import Select from '@mui/material/Select';
|
51
54
|
import Alert from '@mui/material/Alert';
|
52
55
|
import AlertTitle from '@mui/material/AlertTitle';
|
53
56
|
import Fade from '@mui/material/Fade';
|
@@ -56,6 +59,8 @@ import Radio from '@mui/material/Radio';
|
|
56
59
|
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
|
57
60
|
import ArrowRightIcon from '@mui/icons-material/ArrowRight';
|
58
61
|
import CancelIcon from '@mui/icons-material/Cancel';
|
62
|
+
import ChevronLefIcon from '@mui/icons-material/ChevronLeft';
|
63
|
+
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
59
64
|
import ClearAllIcon from '@mui/icons-material/ClearAll';
|
60
65
|
import CloseIcon from '@mui/icons-material/Close';
|
61
66
|
import DensityLargeIcon from '@mui/icons-material/DensityLarge';
|
@@ -68,9 +73,11 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
68
73
|
import FilterAltIcon from '@mui/icons-material/FilterAlt';
|
69
74
|
import FilterListIcon from '@mui/icons-material/FilterList';
|
70
75
|
import FilterListOffIcon from '@mui/icons-material/FilterListOff';
|
76
|
+
import FirstPageIcon from '@mui/icons-material/FirstPage';
|
71
77
|
import FullscreenIcon from '@mui/icons-material/Fullscreen';
|
72
78
|
import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
|
73
79
|
import KeyboardDoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
|
80
|
+
import LastPageIcon from '@mui/icons-material/LastPage';
|
74
81
|
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
75
82
|
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
76
83
|
import PushPinIcon from '@mui/icons-material/PushPin';
|
@@ -2230,41 +2237,40 @@ const MRT_LinearProgressBar = ({ isTopToolbar, table, }) => {
|
|
2230
2237
|
}, unmountOnExit: true, children: jsx(LinearProgress, Object.assign({ "aria-busy": "true", "aria-label": "Loading", sx: { position: 'relative' } }, linearProgressProps)) }));
|
2231
2238
|
};
|
2232
2239
|
|
2240
|
+
const defaultPageSizeOptions = [5, 10, 15, 20, 25, 30, 50, 100];
|
2233
2241
|
const MRT_TablePagination = ({ position = 'bottom', table, }) => {
|
2234
|
-
const { getPrePaginationRowModel, getState, options: { enableToolbarInternalActions, localization, muiTablePaginationProps, rowCount, }, setPageIndex, setPageSize, } = table;
|
2242
|
+
const { getPrePaginationRowModel, getState, options: { enableToolbarInternalActions, icons: { ChevronLefIcon, ChevronRightIcon, FirstPageIcon, LastPageIcon }, localization, muiTablePaginationProps, paginationDisplayMode, rowCount, }, setPageIndex, setPageSize, } = table;
|
2235
2243
|
const { pagination: { pageIndex = 0, pageSize = 10 }, showGlobalFilter, } = getState();
|
2236
|
-
const
|
2237
|
-
const showFirstLastPageButtons = totalRowCount / pageSize > 2;
|
2238
|
-
const tablePaginationProps = parseFromValuesOrFunc(muiTablePaginationProps, {
|
2244
|
+
const paginationProps = parseFromValuesOrFunc(muiTablePaginationProps, {
|
2239
2245
|
table,
|
2240
2246
|
});
|
2241
|
-
const
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
}, '& .MuiTablePagination-displayedRows': {
|
2255
|
-
m: '0 1px',
|
2256
|
-
}, '& .MuiTablePagination-selectLabel': {
|
2257
|
-
m: '0 -1px',
|
2258
|
-
}, '& .MuiTablePagination-toolbar': {
|
2259
|
-
alignItems: 'center',
|
2260
|
-
display: 'flex',
|
2261
|
-
}, '&. MuiInputBase-root': {
|
2262
|
-
m: '0 1px',
|
2263
|
-
}, mt: position === 'top' &&
|
2247
|
+
const totalRowCount = rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().rows.length;
|
2248
|
+
const numberOfPages = Math.ceil(totalRowCount / pageSize);
|
2249
|
+
const showFirstLastPageButtons = numberOfPages > 2;
|
2250
|
+
const showFirstButton = showFirstLastPageButtons && (paginationProps === null || paginationProps === void 0 ? void 0 : paginationProps.showFirstButton) !== false;
|
2251
|
+
const showLastButton = showFirstLastPageButtons && (paginationProps === null || paginationProps === void 0 ? void 0 : paginationProps.showLastButton) !== false;
|
2252
|
+
const firstRowIndex = pageIndex * pageSize;
|
2253
|
+
const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount);
|
2254
|
+
return (jsxs(Box, { sx: {
|
2255
|
+
alignItems: 'center',
|
2256
|
+
display: 'flex',
|
2257
|
+
gap: '8px',
|
2258
|
+
justifyContent: 'space-between',
|
2259
|
+
mt: position === 'top' &&
|
2264
2260
|
enableToolbarInternalActions &&
|
2265
2261
|
!showGlobalFilter
|
2266
|
-
? '
|
2267
|
-
: undefined,
|
2262
|
+
? '3rem'
|
2263
|
+
: undefined,
|
2264
|
+
position: 'relative',
|
2265
|
+
px: '4px',
|
2266
|
+
py: '12px',
|
2267
|
+
zIndex: 2,
|
2268
|
+
}, children: [(paginationProps === null || paginationProps === void 0 ? void 0 : paginationProps.showRowsPerPage) !== false && (jsxs(Box, { sx: { alignItems: 'center', display: 'flex', gap: '8px' }, children: [jsx(InputLabel, { htmlFor: "mrt-rows-per-page", sx: { mb: 0 }, children: localization.rowsPerPage }), jsx(Select, { id: "mrt-rows-per-page", label: localization.rowsPerPage, onChange: (event) => setPageSize(+event.target.value), sx: { '&::before': { border: 'none' }, mb: 0 }, value: pageSize, variant: "standard", children: defaultPageSizeOptions.map((value) => (jsx(MenuItem, { sx: { m: 0 }, value: value, children: value }, value))) })] })), paginationDisplayMode === 'pages' ? (jsx(Pagination, Object.assign({ count: numberOfPages, onChange: (_e, newPageIndex) => setPageIndex(newPageIndex - 1), page: pageIndex + 1, renderItem: (item) => (jsx(PaginationItem, Object.assign({ slots: {
|
2269
|
+
first: FirstPageIcon,
|
2270
|
+
last: LastPageIcon,
|
2271
|
+
next: ChevronRightIcon,
|
2272
|
+
previous: ChevronLefIcon,
|
2273
|
+
} }, item))), showFirstButton: showFirstButton, showLastButton: showLastButton }, paginationProps))) : paginationDisplayMode === 'default' ? (jsxs(Fragment, { children: [jsx(Typography, { mb: "0", mx: "8px", variant: "body2", children: `${lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString()}-${lastRowIndex.toLocaleString()} ${localization.of} ${totalRowCount.toLocaleString()}` }), jsxs(Box, { gap: "xs", children: [showFirstButton && (jsx(IconButton, { "aria-label": localization.goToFirstPage, disabled: pageIndex <= 0, onClick: () => setPageIndex(0), size: "small", children: jsx(FirstPageIcon, {}) })), jsx(IconButton, { "aria-label": localization.goToPreviousPage, disabled: pageIndex <= 0, onClick: () => setPageIndex(pageIndex - 1), size: "small", children: jsx(ChevronLefIcon, {}) }), jsx(IconButton, { "aria-label": localization.goToNextPage, disabled: lastRowIndex >= totalRowCount, onClick: () => setPageIndex(pageIndex + 1), size: "small", children: jsx(ChevronRightIcon, {}) }), showLastButton && (jsx(IconButton, { "aria-label": localization.goToLastPage, disabled: lastRowIndex >= totalRowCount, onClick: () => setPageIndex(numberOfPages - 1), size: "small", children: jsx(LastPageIcon, {}) }))] })] })) : null] }));
|
2268
2274
|
};
|
2269
2275
|
|
2270
2276
|
const MRT_ToolbarAlertBanner = ({ stackAlertBanner, table, }) => {
|
@@ -2912,8 +2918,9 @@ const useMRT_DisplayColumns = ({ columnOrder, creatingRow, grouping, tableOption
|
|
2912
2918
|
};
|
2913
2919
|
|
2914
2920
|
const useMRT_Effects = (table) => {
|
2915
|
-
const { getState, options: { enablePagination, rowCount }, } = table;
|
2916
|
-
const { globalFilter, isFullScreen, isLoading, pagination, showSkeletons, sorting, } = getState();
|
2921
|
+
const { getIsSomeRowsPinned, getState, options: { enablePagination, enableRowPinning, rowCount }, } = table;
|
2922
|
+
const { density, globalFilter, isFullScreen, isLoading, pagination, showSkeletons, sorting, } = getState();
|
2923
|
+
const rerender = useReducer(() => ({}), {})[1];
|
2917
2924
|
const isMounted = useRef(false);
|
2918
2925
|
const initialBodyHeight = useRef();
|
2919
2926
|
const previousTop = useRef();
|
@@ -2969,6 +2976,13 @@ const useMRT_Effects = (table) => {
|
|
2969
2976
|
table.setSorting(() => appliedSort.current || []);
|
2970
2977
|
}
|
2971
2978
|
}, [globalFilter]);
|
2979
|
+
useEffect(() => {
|
2980
|
+
if (enableRowPinning && getIsSomeRowsPinned()) {
|
2981
|
+
setTimeout(() => {
|
2982
|
+
rerender();
|
2983
|
+
}, 150);
|
2984
|
+
}
|
2985
|
+
}, [density]);
|
2972
2986
|
};
|
2973
2987
|
|
2974
2988
|
const useMRT_TableInstance = (tableOptions) => {
|
@@ -3237,6 +3251,8 @@ const MRT_Default_Icons = {
|
|
3237
3251
|
ArrowDownwardIcon,
|
3238
3252
|
ArrowRightIcon,
|
3239
3253
|
CancelIcon,
|
3254
|
+
ChevronLefIcon,
|
3255
|
+
ChevronRightIcon,
|
3240
3256
|
ClearAllIcon,
|
3241
3257
|
CloseIcon,
|
3242
3258
|
DensityLargeIcon,
|
@@ -3249,9 +3265,11 @@ const MRT_Default_Icons = {
|
|
3249
3265
|
FilterAltIcon,
|
3250
3266
|
FilterListIcon,
|
3251
3267
|
FilterListOffIcon,
|
3268
|
+
FirstPageIcon,
|
3252
3269
|
FullscreenExitIcon,
|
3253
3270
|
FullscreenIcon,
|
3254
3271
|
KeyboardDoubleArrowDownIcon,
|
3272
|
+
LastPageIcon,
|
3255
3273
|
MoreHorizIcon,
|
3256
3274
|
MoreVertIcon,
|
3257
3275
|
PushPinIcon,
|