material-react-table 1.0.0-beta.11 → 1.0.0-beta.14
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/MaterialReactTable.d.ts +15 -4
- package/dist/cjs/index.js +51 -10
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/inputs/MRT_FilterCheckbox.d.ts +8 -0
- package/dist/cjs/table/MRT_TableRoot.d.ts +4 -0
- package/dist/esm/MaterialReactTable.d.ts +15 -4
- package/dist/esm/inputs/MRT_FilterCheckbox.d.ts +8 -0
- package/dist/esm/material-react-table.esm.js +51 -10
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/table/MRT_TableRoot.d.ts +4 -0
- package/dist/index.d.ts +16 -5
- package/{dist → locales}/en.cjs +0 -0
- package/{dist → locales}/en.cjs.d.ts +0 -0
- package/{dist → locales}/en.cjs.map +0 -0
- package/{dist → locales}/en.esm.d.ts +0 -0
- package/{dist → locales}/en.esm.js +0 -0
- package/{dist → locales}/en.esm.js.map +0 -0
- package/package.json +3 -2
- package/src/MaterialReactTable.tsx +26 -2
- package/src/body/MRT_TableBodyCell.tsx +1 -1
- package/src/column.utils.ts +5 -1
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +7 -3
- package/src/inputs/MRT_FilterCheckbox.tsx +96 -0
- package/src/inputs/MRT_FilterTextField.tsx +13 -10
|
@@ -130,6 +130,10 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
|
|
|
130
130
|
table: MRT_TableInstance<TData>;
|
|
131
131
|
column: MRT_Column<TData>;
|
|
132
132
|
}) => import("@mui/material").IconButtonProps<"button", {}>) | undefined;
|
|
133
|
+
muiTableHeadCellFilterCheckboxProps?: import("@mui/material").CheckboxProps | (({ column, table, }: {
|
|
134
|
+
column: MRT_Column<TData>;
|
|
135
|
+
table: MRT_TableInstance<TData>;
|
|
136
|
+
}) => import("@mui/material").CheckboxProps) | undefined;
|
|
133
137
|
muiTableHeadCellFilterTextFieldProps?: import("@mui/material").TextFieldProps | (({ table, column, rangeFilterIndex, }: {
|
|
134
138
|
table: MRT_TableInstance<TData>;
|
|
135
139
|
column: MRT_Column<TData>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MutableRefObject, Dispatch, SetStateAction, ReactNode } from 'react';
|
|
2
|
-
import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, ToolbarProps, LinearProgressProps,
|
|
2
|
+
import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, CheckboxProps, ToolbarProps, LinearProgressProps, SkeletonProps, TableBodyProps, TableRowProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, ChipProps, AlertProps } from '@mui/material';
|
|
3
3
|
import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
|
|
4
4
|
import { Options, VirtualItem } from 'react-virtual';
|
|
5
5
|
import * as _tanstack_table_core from '@tanstack/table-core';
|
|
@@ -296,9 +296,10 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
296
296
|
row: MRT_Row<TData>;
|
|
297
297
|
table: MRT_TableInstance<TData>;
|
|
298
298
|
}) => ReactNode;
|
|
299
|
-
Filter?: ({ column, header, table, }: {
|
|
299
|
+
Filter?: ({ column, header, rangeFilterIndex, table, }: {
|
|
300
300
|
column: MRT_Column<TData>;
|
|
301
301
|
header: MRT_Header<TData>;
|
|
302
|
+
rangeFilterIndex?: number;
|
|
302
303
|
table: MRT_TableInstance<TData>;
|
|
303
304
|
}) => ReactNode;
|
|
304
305
|
Footer?: ReactNode | (({ column, footer, table, }: {
|
|
@@ -355,7 +356,7 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
355
356
|
text: string;
|
|
356
357
|
value: any;
|
|
357
358
|
})[];
|
|
358
|
-
filterVariant?: 'text' | 'select' | 'multi-select' | 'range';
|
|
359
|
+
filterVariant?: 'text' | 'select' | 'multi-select' | 'range' | 'checkbox';
|
|
359
360
|
/**
|
|
360
361
|
* footer must be a string. If you want custom JSX to render the footer, you can also specify a `Footer` option. (Capital F)
|
|
361
362
|
*/
|
|
@@ -386,9 +387,11 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
386
387
|
row: MRT_Row<TData>;
|
|
387
388
|
table: MRT_TableInstance<TData>;
|
|
388
389
|
}) => TextFieldProps);
|
|
389
|
-
muiTableBodyCellProps?: TableCellProps | (({ cell, table, }: {
|
|
390
|
-
table: MRT_TableInstance<TData>;
|
|
390
|
+
muiTableBodyCellProps?: TableCellProps | (({ cell, column, row, table, }: {
|
|
391
391
|
cell: MRT_Cell<TData>;
|
|
392
|
+
column: MRT_Column<TData>;
|
|
393
|
+
row: MRT_Row<TData>;
|
|
394
|
+
table: MRT_TableInstance<TData>;
|
|
392
395
|
}) => TableCellProps);
|
|
393
396
|
muiTableFooterCellProps?: TableCellProps | (({ table, column, }: {
|
|
394
397
|
table: MRT_TableInstance<TData>;
|
|
@@ -402,6 +405,10 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
402
405
|
table: MRT_TableInstance<TData>;
|
|
403
406
|
column: MRT_Column<TData>;
|
|
404
407
|
}) => IconButtonProps);
|
|
408
|
+
muiTableHeadCellFilterCheckboxProps?: CheckboxProps | (({ column, table, }: {
|
|
409
|
+
column: MRT_Column<TData>;
|
|
410
|
+
table: MRT_TableInstance<TData>;
|
|
411
|
+
}) => CheckboxProps);
|
|
405
412
|
muiTableHeadCellFilterTextFieldProps?: TextFieldProps | (({ table, column, rangeFilterIndex, }: {
|
|
406
413
|
table: MRT_TableInstance<TData>;
|
|
407
414
|
column: MRT_Column<TData>;
|
|
@@ -598,6 +605,10 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
598
605
|
table: MRT_TableInstance<TData>;
|
|
599
606
|
column: MRT_Column<TData>;
|
|
600
607
|
}) => IconButtonProps);
|
|
608
|
+
muiTableHeadCellFilterCheckboxProps?: CheckboxProps | (({ column, table, }: {
|
|
609
|
+
column: MRT_Column<TData>;
|
|
610
|
+
table: MRT_TableInstance<TData>;
|
|
611
|
+
}) => CheckboxProps);
|
|
601
612
|
muiTableHeadCellFilterTextFieldProps?: TextFieldProps | (({ table, column, rangeFilterIndex, }: {
|
|
602
613
|
table: MRT_TableInstance<TData>;
|
|
603
614
|
column: MRT_Column<TData>;
|
package/{dist → locales}/en.cjs
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-beta.
|
|
2
|
+
"version": "1.0.0-beta.14",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"typings": "dist/index.d.ts",
|
|
25
25
|
"files": [
|
|
26
26
|
"dist",
|
|
27
|
+
"locales",
|
|
27
28
|
"src"
|
|
28
29
|
],
|
|
29
30
|
"size-limit": [
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
},
|
|
42
43
|
"scripts": {
|
|
43
44
|
"analyze": "size-limit --why",
|
|
44
|
-
"build": "rm -rf dist && rollup -c && size-limit && rm -rf material-react-table-docs/node_modules/material-react-table
|
|
45
|
+
"build": "rm -rf dist locales && rollup -c && size-limit && rm -rf material-react-table-docs/node_modules/material-react-table && cp -r dist material-react-table-docs/node_modules/material-react-table/ && cp -r locales material-react-table-docs/node_modules/material-react-table/ && cp -r src material-react-table-docs/node_modules/material-react-table/ && cp -r package.json material-react-table-docs/node_modules/material-react-table/",
|
|
45
46
|
"build-storybook": "build-storybook",
|
|
46
47
|
"format": "prettier -w .",
|
|
47
48
|
"lint": "eslint .",
|
|
@@ -275,10 +275,12 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
275
275
|
Filter?: ({
|
|
276
276
|
column,
|
|
277
277
|
header,
|
|
278
|
+
rangeFilterIndex,
|
|
278
279
|
table,
|
|
279
280
|
}: {
|
|
280
281
|
column: MRT_Column<TData>;
|
|
281
282
|
header: MRT_Header<TData>;
|
|
283
|
+
rangeFilterIndex?: number;
|
|
282
284
|
table: MRT_TableInstance<TData>;
|
|
283
285
|
}) => ReactNode;
|
|
284
286
|
Footer?:
|
|
@@ -349,7 +351,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
349
351
|
enableEditing?: boolean;
|
|
350
352
|
filterFn?: MRT_FilterFn<TData>;
|
|
351
353
|
filterSelectOptions?: (string | { text: string; value: any })[];
|
|
352
|
-
filterVariant?: 'text' | 'select' | 'multi-select' | 'range';
|
|
354
|
+
filterVariant?: 'text' | 'select' | 'multi-select' | 'range' | 'checkbox';
|
|
353
355
|
/**
|
|
354
356
|
* footer must be a string. If you want custom JSX to render the footer, you can also specify a `Footer` option. (Capital F)
|
|
355
357
|
*/
|
|
@@ -398,10 +400,14 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
398
400
|
| TableCellProps
|
|
399
401
|
| (({
|
|
400
402
|
cell,
|
|
403
|
+
column,
|
|
404
|
+
row,
|
|
401
405
|
table,
|
|
402
406
|
}: {
|
|
403
|
-
table: MRT_TableInstance<TData>;
|
|
404
407
|
cell: MRT_Cell<TData>;
|
|
408
|
+
column: MRT_Column<TData>;
|
|
409
|
+
row: MRT_Row<TData>;
|
|
410
|
+
table: MRT_TableInstance<TData>;
|
|
405
411
|
}) => TableCellProps);
|
|
406
412
|
muiTableFooterCellProps?:
|
|
407
413
|
| TableCellProps
|
|
@@ -430,6 +436,15 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
430
436
|
table: MRT_TableInstance<TData>;
|
|
431
437
|
column: MRT_Column<TData>;
|
|
432
438
|
}) => IconButtonProps);
|
|
439
|
+
muiTableHeadCellFilterCheckboxProps?:
|
|
440
|
+
| CheckboxProps
|
|
441
|
+
| (({
|
|
442
|
+
column,
|
|
443
|
+
table,
|
|
444
|
+
}: {
|
|
445
|
+
column: MRT_Column<TData>;
|
|
446
|
+
table: MRT_TableInstance<TData>;
|
|
447
|
+
}) => CheckboxProps);
|
|
433
448
|
muiTableHeadCellFilterTextFieldProps?:
|
|
434
449
|
| TextFieldProps
|
|
435
450
|
| (({
|
|
@@ -783,6 +798,15 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
783
798
|
table: MRT_TableInstance<TData>;
|
|
784
799
|
column: MRT_Column<TData>;
|
|
785
800
|
}) => IconButtonProps);
|
|
801
|
+
muiTableHeadCellFilterCheckboxProps?:
|
|
802
|
+
| CheckboxProps
|
|
803
|
+
| (({
|
|
804
|
+
column,
|
|
805
|
+
table,
|
|
806
|
+
}: {
|
|
807
|
+
column: MRT_Column<TData>;
|
|
808
|
+
table: MRT_TableInstance<TData>;
|
|
809
|
+
}) => CheckboxProps);
|
|
786
810
|
muiTableHeadCellFilterTextFieldProps?:
|
|
787
811
|
| TextFieldProps
|
|
788
812
|
| (({
|
|
@@ -68,7 +68,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
68
68
|
|
|
69
69
|
const mcTableCellBodyProps =
|
|
70
70
|
columnDef.muiTableBodyCellProps instanceof Function
|
|
71
|
-
? columnDef.muiTableBodyCellProps({ cell, table })
|
|
71
|
+
? columnDef.muiTableBodyCellProps({ cell, column, row, table })
|
|
72
72
|
: columnDef.muiTableBodyCellProps;
|
|
73
73
|
|
|
74
74
|
const tableCellProps = {
|
package/src/column.utils.ts
CHANGED
|
@@ -164,8 +164,12 @@ export const getDefaultColumnFilterFn = <
|
|
|
164
164
|
columnDef: MRT_ColumnDef<TData>,
|
|
165
165
|
): MRT_FilterOption => {
|
|
166
166
|
if (columnDef.filterVariant === 'multi-select') return 'arrIncludesSome';
|
|
167
|
-
if (columnDef.filterVariant === 'select') return 'equals';
|
|
168
167
|
if (columnDef.filterVariant === 'range') return 'betweenInclusive';
|
|
168
|
+
if (
|
|
169
|
+
columnDef.filterVariant === 'select' ||
|
|
170
|
+
columnDef.filterVariant === 'checkbox'
|
|
171
|
+
)
|
|
172
|
+
return 'equals';
|
|
169
173
|
return 'fuzzy';
|
|
170
174
|
};
|
|
171
175
|
|
|
@@ -3,6 +3,7 @@ import { Collapse } from '@mui/material';
|
|
|
3
3
|
import { MRT_FilterRangeFields } from '../inputs/MRT_FilterRangeFields';
|
|
4
4
|
import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
|
|
5
5
|
import { MRT_Header, MRT_TableInstance } from '..';
|
|
6
|
+
import { MRT_FilterCheckbox } from '../inputs/MRT_FilterCheckbox';
|
|
6
7
|
|
|
7
8
|
interface Props {
|
|
8
9
|
header: MRT_Header;
|
|
@@ -20,9 +21,12 @@ export const MRT_TableHeadCellFilterContainer: FC<Props> = ({
|
|
|
20
21
|
|
|
21
22
|
return (
|
|
22
23
|
<Collapse in={showColumnFilters} mountOnEnter unmountOnExit>
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
)
|
|
24
|
+
{columnDef.filterVariant === 'checkbox' ? (
|
|
25
|
+
<MRT_FilterCheckbox column={column} table={table} />
|
|
26
|
+
) : columnDef.filterVariant === 'range' ||
|
|
27
|
+
['between', 'betweenInclusive', 'inNumberRange'].includes(
|
|
28
|
+
columnDef._filterFn,
|
|
29
|
+
) ? (
|
|
26
30
|
<MRT_FilterRangeFields header={header} table={table} />
|
|
27
31
|
) : (
|
|
28
32
|
<MRT_FilterTextField header={header} table={table} />
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Checkbox,
|
|
4
|
+
CheckboxProps,
|
|
5
|
+
FormControlLabel,
|
|
6
|
+
Tooltip,
|
|
7
|
+
} from '@mui/material';
|
|
8
|
+
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
column: MRT_Column;
|
|
12
|
+
table: MRT_TableInstance;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const MRT_FilterCheckbox: FC<Props> = ({ column, table }) => {
|
|
16
|
+
const {
|
|
17
|
+
getState,
|
|
18
|
+
options: { localization, muiTableHeadCellFilterCheckboxProps },
|
|
19
|
+
} = table;
|
|
20
|
+
const { density } = getState();
|
|
21
|
+
const { columnDef } = column;
|
|
22
|
+
|
|
23
|
+
const mTableHeadCellFilterCheckboxProps =
|
|
24
|
+
muiTableHeadCellFilterCheckboxProps instanceof Function
|
|
25
|
+
? muiTableHeadCellFilterCheckboxProps({
|
|
26
|
+
column,
|
|
27
|
+
table,
|
|
28
|
+
})
|
|
29
|
+
: muiTableHeadCellFilterCheckboxProps;
|
|
30
|
+
|
|
31
|
+
const mcTableHeadCellFilterCheckboxProps =
|
|
32
|
+
columnDef.muiTableHeadCellFilterCheckboxProps instanceof Function
|
|
33
|
+
? columnDef.muiTableHeadCellFilterCheckboxProps({
|
|
34
|
+
column,
|
|
35
|
+
table,
|
|
36
|
+
})
|
|
37
|
+
: columnDef.muiTableHeadCellFilterCheckboxProps;
|
|
38
|
+
|
|
39
|
+
const checkboxProps = {
|
|
40
|
+
...mTableHeadCellFilterCheckboxProps,
|
|
41
|
+
...mcTableHeadCellFilterCheckboxProps,
|
|
42
|
+
} as CheckboxProps;
|
|
43
|
+
|
|
44
|
+
const filterLabel = localization.filterByColumn?.replace(
|
|
45
|
+
'{column}',
|
|
46
|
+
columnDef.header,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Tooltip
|
|
51
|
+
arrow
|
|
52
|
+
enterDelay={1000}
|
|
53
|
+
enterNextDelay={1000}
|
|
54
|
+
title={checkboxProps?.title ?? filterLabel}
|
|
55
|
+
>
|
|
56
|
+
<FormControlLabel
|
|
57
|
+
control={
|
|
58
|
+
<Checkbox
|
|
59
|
+
checked={column.getFilterValue() === 'true'}
|
|
60
|
+
indeterminate={column.getFilterValue() === undefined}
|
|
61
|
+
color={
|
|
62
|
+
column.getFilterValue() === undefined ? 'default' : 'primary'
|
|
63
|
+
}
|
|
64
|
+
size={density === 'compact' ? 'small' : 'medium'}
|
|
65
|
+
{...checkboxProps}
|
|
66
|
+
onClick={(e) => {
|
|
67
|
+
e.stopPropagation();
|
|
68
|
+
checkboxProps?.onClick?.(e);
|
|
69
|
+
}}
|
|
70
|
+
onChange={(e, checked) => {
|
|
71
|
+
column.setFilterValue(
|
|
72
|
+
column.getFilterValue() === undefined
|
|
73
|
+
? 'true'
|
|
74
|
+
: column.getFilterValue() === 'true'
|
|
75
|
+
? 'false'
|
|
76
|
+
: undefined,
|
|
77
|
+
);
|
|
78
|
+
checkboxProps?.onChange?.(e, checked);
|
|
79
|
+
}}
|
|
80
|
+
sx={(theme) => ({
|
|
81
|
+
height: '2.5rem',
|
|
82
|
+
width: '2.5rem',
|
|
83
|
+
...(checkboxProps?.sx instanceof Function
|
|
84
|
+
? checkboxProps.sx(theme)
|
|
85
|
+
: (checkboxProps?.sx as any)),
|
|
86
|
+
})}
|
|
87
|
+
/>
|
|
88
|
+
}
|
|
89
|
+
disableTypography
|
|
90
|
+
label={checkboxProps.title ?? filterLabel}
|
|
91
|
+
sx={{ color: 'text.secondary', mt: '-4px', fontWeight: 'normal' }}
|
|
92
|
+
title={undefined}
|
|
93
|
+
/>
|
|
94
|
+
</Tooltip>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
@@ -118,10 +118,12 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
118
118
|
(event: ChangeEvent<HTMLInputElement>) => {
|
|
119
119
|
let value =
|
|
120
120
|
textFieldProps.type === 'date'
|
|
121
|
-
?
|
|
121
|
+
? event.target.valueAsDate
|
|
122
|
+
: textFieldProps.type === 'number'
|
|
123
|
+
? event.target.valueAsNumber
|
|
122
124
|
: event.target.value;
|
|
123
125
|
if (isRangeFilter) {
|
|
124
|
-
column.setFilterValue((old:
|
|
126
|
+
column.setFilterValue((old: Array<string | Date | number | null>) => {
|
|
125
127
|
const newFilterValues = old ?? ['', ''];
|
|
126
128
|
newFilterValues[rangeFilterIndex as number] = value;
|
|
127
129
|
return newFilterValues;
|
|
@@ -177,7 +179,9 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
177
179
|
}, [column.getFilterValue()]);
|
|
178
180
|
|
|
179
181
|
if (columnDef.Filter) {
|
|
180
|
-
return
|
|
182
|
+
return (
|
|
183
|
+
<>{columnDef.Filter?.({ column, header, rangeFilterIndex, table })}</>
|
|
184
|
+
);
|
|
181
185
|
}
|
|
182
186
|
|
|
183
187
|
return (
|
|
@@ -210,7 +214,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
210
214
|
}
|
|
211
215
|
FormHelperTextProps={{
|
|
212
216
|
sx: {
|
|
213
|
-
fontSize: '0.
|
|
217
|
+
fontSize: '0.75rem',
|
|
214
218
|
lineHeight: '0.8rem',
|
|
215
219
|
whiteSpace: 'nowrap',
|
|
216
220
|
},
|
|
@@ -315,12 +319,11 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
315
319
|
}}
|
|
316
320
|
sx={(theme) => ({
|
|
317
321
|
p: 0,
|
|
318
|
-
minWidth:
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
: 'auto',
|
|
322
|
+
minWidth: isRangeFilter
|
|
323
|
+
? '100px'
|
|
324
|
+
: !filterChipLabel
|
|
325
|
+
? '120px'
|
|
326
|
+
: 'auto',
|
|
324
327
|
width: '100%',
|
|
325
328
|
'& .MuiSelect-icon': {
|
|
326
329
|
mr: '1.5rem',
|