material-react-table 1.0.0-beta.6 → 1.0.0-beta.9

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/README.md CHANGED
@@ -48,10 +48,12 @@ See all [Props and Options](https://www.material-react-table.com/docs/api)
48
48
 
49
49
  View additional [storybook examples](https://www.material-react-table.dev/)
50
50
 
51
- ## Features (All Features work and are MVP, but are still being polished)
51
+ ## Features
52
52
 
53
53
  _All features can easily be enabled/disabled_
54
54
 
55
+ _**Fully Fleshed out [Docs](https://www.material-react-table.com/docs/guides#guides) are available for all features**_
56
+
55
57
  - [x] < 37kb gzipped - [Bundlephobia](https://bundlephobia.com/package/material-react-table)
56
58
  - [x] Advanced TypeScript Generics Support (TypeScript Optional)
57
59
  - [x] Aggregation and Grouping (Sum, Average, Count, etc.)
@@ -63,7 +65,7 @@ _All features can easily be enabled/disabled_
63
65
  - [x] Column Resizing
64
66
  - [x] Customize Icons
65
67
  - [x] Customize Styling of internal Mui Components
66
- - [x] Data Editing (3 different editing modes)
68
+ - [x] Data Editing (4 different editing modes)
67
69
  - [x] Density Toggle
68
70
  - [x] Detail Panels (Expansion)
69
71
  - [x] Filtering (supports client-side and server-side)
@@ -71,7 +73,7 @@ _All features can easily be enabled/disabled_
71
73
  - [x] Global Filtering (Search across all columns, rank by best match)
72
74
  - [x] Header Groups & Footers
73
75
  - [x] Localization (i18n) support
74
- - [x] Manage your own state
76
+ - [x] Manage your own state or let the table manage it internally for you
75
77
  - [x] Pagination (supports client-side and server-side)
76
78
  - [x] Row Actions (Your Custom Action Buttons)
77
79
  - [x] Row Numbers
@@ -112,33 +114,31 @@ npm install material-react-table
112
114
  import React, { useMemo, useRef, useState, useEffect } from 'react';
113
115
  import MaterialReactTable from 'material-react-table';
114
116
 
117
+ const data = [
118
+ {
119
+ name: 'John',
120
+ age: 30,
121
+ },
122
+ {
123
+ name: 'Sara',
124
+ age: 25,
125
+ },
126
+ ]
127
+
115
128
  export default function App() {
116
129
  const columns = useMemo(
117
130
  () => [
118
131
  {
119
132
  accessorKey: 'name', //simple recommended way to define a column
120
133
  header: 'Name',
121
- muiTableHeadCellProps: { sx: { color: 'green' } }, //custom props
134
+ muiTableHeadCellProps: { sx: { color: 'green' } }, //optional custom props
135
+ Cell: ({ cell}) => <span>{cell.getValue()}</span>, //optional custom cell render
122
136
  },
123
137
  {
124
138
  accessorFn: (row) => row.age, //alternate way
125
139
  id: 'age', //id required if you use accessorFn instead of accessorKey
126
140
  header: 'Age',
127
- Header: <i>Age</i>, //optional custom markup
128
- },
129
- ],
130
- [],
131
- );
132
-
133
- const data = useMemo(
134
- () => [
135
- {
136
- name: 'John',
137
- age: 30,
138
- },
139
- {
140
- name: 'Sara',
141
- age: 25,
141
+ Header: () => <i>Age</i>, //optional custom header render
142
142
  },
143
143
  ],
144
144
  [],
@@ -170,7 +170,7 @@ export default function App() {
170
170
  state={{ rowSelection }} //manage your own state, pass it back to the table (optional)
171
171
  tableInstanceRef={tableInstanceRef} //get a reference to the underlying table instance (optional)
172
172
  />
173
- );
173
+ );
174
174
  }
175
175
  ```
176
176
 
@@ -467,6 +467,9 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
467
467
  positionPagination?: 'bottom' | 'top' | 'both';
468
468
  positionToolbarAlertBanner?: 'bottom' | 'top' | 'none';
469
469
  positionToolbarDropZone?: 'bottom' | 'top' | 'none' | 'both';
470
+ renderBottomToolbar?: ({ table, }: {
471
+ table: MRT_TableInstance<TData>;
472
+ }) => ReactNode | ReactNode[];
470
473
  renderBottomToolbarCustomActions?: ({ table, }: {
471
474
  table: MRT_TableInstance<TData>;
472
475
  }) => ReactNode;
@@ -503,6 +506,9 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
503
506
  renderToolbarInternalActions?: ({ table, }: {
504
507
  table: MRT_TableInstance<TData>;
505
508
  }) => ReactNode;
509
+ renderTopToolbar?: ({ table, }: {
510
+ table: MRT_TableInstance<TData>;
511
+ }) => ReactNode | ReactNode[];
506
512
  renderTopToolbarCustomActions?: ({ table, }: {
507
513
  table: MRT_TableInstance<TData>;
508
514
  }) => ReactNode;
package/dist/cjs/index.js CHANGED
@@ -393,7 +393,7 @@ const mrtFilterOptions = (localization) => [
393
393
  divider: false,
394
394
  },
395
395
  ];
396
- const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, table, }) => {
396
+ const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, setFilterValue, table, }) => {
397
397
  var _a, _b, _c, _d;
398
398
  const { getState, options: { columnFilterModeOptions, globalFilterModeOptions, localization, renderColumnFilterModeMenuItems, renderGlobalFilterModeMenuItems, }, setColumnFilterFns, setGlobalFilterFn, } = table;
399
399
  const { globalFilterFn, density } = getState();
@@ -412,11 +412,19 @@ const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, table,
412
412
  if (['empty', 'notEmpty'].includes(option)) {
413
413
  column.setFilterValue(' ');
414
414
  }
415
- else if (option === 'between') {
415
+ else if ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.filterVariant) === 'multi-select' ||
416
+ ['arrIncludesSome', 'arrIncludesAll', 'arrIncludes'].includes(option)) {
417
+ column.setFilterValue([]);
418
+ setFilterValue === null || setFilterValue === void 0 ? void 0 : setFilterValue([]);
419
+ }
420
+ else if ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.filterVariant) === 'range' ||
421
+ ['between', 'betweenInclusive', 'inNumberRange'].includes(option)) {
416
422
  column.setFilterValue(['', '']);
423
+ setFilterValue === null || setFilterValue === void 0 ? void 0 : setFilterValue('');
417
424
  }
418
425
  else {
419
426
  column.setFilterValue('');
427
+ setFilterValue === null || setFilterValue === void 0 ? void 0 : setFilterValue('');
420
428
  }
421
429
  }
422
430
  else {
@@ -1080,7 +1088,7 @@ const MRT_GlobalFilterTextField = ({ table, }) => {
1080
1088
  textFieldProps.inputRef = inputRef;
1081
1089
  }
1082
1090
  } })),
1083
- React__default["default"].createElement(MRT_FilterOptionMenu, { anchorEl: anchorEl, setAnchorEl: setAnchorEl, table: table })));
1091
+ React__default["default"].createElement(MRT_FilterOptionMenu, { anchorEl: anchorEl, setAnchorEl: setAnchorEl, table: table, onSelect: handleClear })));
1084
1092
  };
1085
1093
 
1086
1094
  const MRT_LinearProgressBar = ({ isTopToolbar, table }) => {
@@ -1217,13 +1225,13 @@ const MRT_ToggleGlobalFilterButton = (_a) => {
1217
1225
  var _b;
1218
1226
  var { table } = _a, rest = __rest(_a, ["table"]);
1219
1227
  const { getState, options: { icons: { SearchIcon, SearchOffIcon }, localization, }, refs: { searchInputRef }, setShowGlobalFilter, } = table;
1220
- const { showGlobalFilter } = getState();
1228
+ const { globalFilter, showGlobalFilter } = getState();
1221
1229
  const handleToggleSearch = () => {
1222
1230
  setShowGlobalFilter(!showGlobalFilter);
1223
1231
  queueMicrotask(() => { var _a; return (_a = searchInputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); });
1224
1232
  };
1225
1233
  return (React__default["default"].createElement(material.Tooltip, { arrow: true, title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.showHideSearch },
1226
- React__default["default"].createElement(material.IconButton, Object.assign({ onClick: handleToggleSearch }, rest, { title: undefined }), showGlobalFilter ? React__default["default"].createElement(SearchOffIcon, null) : React__default["default"].createElement(SearchIcon, null))));
1234
+ React__default["default"].createElement(material.IconButton, Object.assign({ disabled: !!globalFilter, onClick: handleToggleSearch }, rest, { title: undefined }), showGlobalFilter ? React__default["default"].createElement(SearchOffIcon, null) : React__default["default"].createElement(SearchIcon, null))));
1227
1235
  };
1228
1236
 
1229
1237
  const MRT_ToolbarInternalButtons = ({ table }) => {
@@ -1494,9 +1502,6 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1494
1502
  const handleFilterMenuOpen = (event) => {
1495
1503
  setAnchorEl(event.currentTarget);
1496
1504
  };
1497
- React.useEffect(() => {
1498
- handleClear();
1499
- }, [columnDef._filterFn]);
1500
1505
  if (columnDef.Filter) {
1501
1506
  return React__default["default"].createElement(React__default["default"].Fragment, null, (_e = columnDef.Filter) === null || _e === void 0 ? void 0 : _e.call(columnDef, { column, header, table }));
1502
1507
  }
@@ -1586,7 +1591,7 @@ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1586
1591
  isMultiSelectFilter && (React__default["default"].createElement(material.Checkbox, { checked: ((_a = column.getFilterValue()) !== null && _a !== void 0 ? _a : []).includes(value), sx: { mr: '0.5rem' } })),
1587
1592
  text));
1588
1593
  })),
1589
- React__default["default"].createElement(MRT_FilterOptionMenu, { anchorEl: anchorEl, header: header, setAnchorEl: setAnchorEl, table: table })));
1594
+ React__default["default"].createElement(MRT_FilterOptionMenu, { anchorEl: anchorEl, header: header, setAnchorEl: setAnchorEl, table: table, setFilterValue: setFilterValue })));
1590
1595
  };
1591
1596
 
1592
1597
  const MRT_FilterRangeFields = ({ header, table }) => {
@@ -1608,11 +1613,8 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1608
1613
  const { options: { icons: { FilterAltIcon }, localization, }, } = table;
1609
1614
  const { column } = header;
1610
1615
  const { columnDef } = column;
1611
- const isRangeFilter = [
1612
- 'between',
1613
- 'betweenInclusive',
1614
- 'inNumberRange',
1615
- ].includes(columnDef._filterFn);
1616
+ const isRangeFilter = columnDef.filterVariant === 'range' ||
1617
+ ['between', 'betweenInclusive', 'inNumberRange'].includes(columnDef._filterFn);
1616
1618
  const currentFilterOption = columnDef._filterFn;
1617
1619
  const filterTooltip = localization.filteringByColumn
1618
1620
  .replace('{column}', String(columnDef.header))
@@ -1624,8 +1626,8 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1624
1626
  ? column.getFilterValue().join(`" ${isRangeFilter ? localization.and : localization.or} "`)
1625
1627
  : column.getFilterValue()}"`)
1626
1628
  .replace('" "', '');
1627
- return (React__default["default"].createElement(material.Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && isRangeFilter) ||
1628
- (!isRangeFilter && // @ts-ignore
1629
+ return (React__default["default"].createElement(material.Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && !isRangeFilter) ||
1630
+ (isRangeFilter && // @ts-ignore
1629
1631
  (!!((_b = column.getFilterValue()) === null || _b === void 0 ? void 0 : _b[0]) || !!((_c = column.getFilterValue()) === null || _c === void 0 ? void 0 : _c[1]))) },
1630
1632
  React__default["default"].createElement("span", null,
1631
1633
  React__default["default"].createElement(material.Tooltip, { arrow: true, placement: "top", title: filterTooltip },
@@ -2309,11 +2311,11 @@ const MRT_TableFooter = ({ table }) => {
2309
2311
  ? muiTableFooterProps({ table })
2310
2312
  : muiTableFooterProps;
2311
2313
  const stickFooter = (isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
2312
- return (React__default["default"].createElement(material.TableFooter, Object.assign({}, tableFooterProps, { sx: (theme) => (Object.assign({ position: stickFooter ? 'sticky' : undefined, bottom: stickFooter ? 0 : undefined, opacity: stickFooter ? 0.95 : undefined, outline: stickFooter
2314
+ return (React__default["default"].createElement(material.TableFooter, Object.assign({}, tableFooterProps, { sx: (theme) => (Object.assign({ backgroundColor: material.lighten(theme.palette.background.default, 0.06), bottom: stickFooter ? 0 : undefined, opacity: stickFooter ? 0.95 : undefined, outline: stickFooter
2313
2315
  ? theme.palette.mode === 'light'
2314
2316
  ? `1px solid ${theme.palette.grey[300]}`
2315
2317
  : `1px solid ${theme.palette.grey[700]}`
2316
- : undefined }, ((tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx) instanceof Function
2318
+ : undefined, position: stickFooter ? 'sticky' : undefined }, ((tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx) instanceof Function
2317
2319
  ? tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx(theme)
2318
2320
  : tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx))) }), getFooterGroups().map((footerGroup) => (React__default["default"].createElement(MRT_TableFooterRow, { footerGroup: footerGroup, key: footerGroup.id, table: table })))));
2319
2321
  };
@@ -2367,18 +2369,9 @@ const MRT_TableContainer = ({ table }) => {
2367
2369
  };
2368
2370
 
2369
2371
  const MRT_TablePaper = ({ table }) => {
2370
- const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, refs: { tablePaperRef }, } = table;
2372
+ var _a, _b;
2373
+ const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps, renderBottomToolbar, renderTopToolbar, }, refs: { tablePaperRef }, } = table;
2371
2374
  const { isFullScreen } = getState();
2372
- React.useEffect(() => {
2373
- if (typeof window !== 'undefined') {
2374
- if (isFullScreen) {
2375
- document.body.style.height = '100vh';
2376
- }
2377
- else {
2378
- document.body.style.height = 'auto';
2379
- }
2380
- }
2381
- }, [isFullScreen]);
2382
2375
  const tablePaperProps = muiTablePaperProps instanceof Function
2383
2376
  ? muiTablePaperProps({ table })
2384
2377
  : muiTablePaperProps;
@@ -2390,10 +2383,17 @@ const MRT_TablePaper = ({ table }) => {
2390
2383
  }
2391
2384
  }, sx: (theme) => (Object.assign({ transition: 'all 0.2s ease-in-out' }, ((tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx) instanceof Function
2392
2385
  ? tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx(theme)
2393
- : tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx))), style: Object.assign(Object.assign({}, tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.style), { height: isFullScreen ? '100vh' : undefined, margin: isFullScreen ? '0' : undefined, maxHeight: isFullScreen ? '100vh' : undefined, maxWidth: isFullScreen ? '100vw' : undefined, padding: isFullScreen ? '0' : undefined, width: isFullScreen ? '100vw' : undefined }) }),
2394
- enableTopToolbar && React__default["default"].createElement(MRT_TopToolbar, { table: table }),
2395
- React__default["default"].createElement(MRT_TableContainer, { table: table }),
2396
- enableBottomToolbar && React__default["default"].createElement(MRT_BottomToolbar, { table: table })));
2386
+ : tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx))), style: Object.assign(Object.assign({}, tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.style), (isFullScreen
2387
+ ? {
2388
+ height: '100vh',
2389
+ margin: 0,
2390
+ maxHeight: '100vh',
2391
+ maxWidth: '100vw',
2392
+ padding: 0,
2393
+ width: '100vw',
2394
+ }
2395
+ : {})) }), (_a = (enableTopToolbar && (renderTopToolbar === null || renderTopToolbar === void 0 ? void 0 : renderTopToolbar({ table })))) !== null && _a !== void 0 ? _a : (React__default["default"].createElement(MRT_TopToolbar, { table: table })),
2396
+ React__default["default"].createElement(MRT_TableContainer, { table: table }), (_b = (enableBottomToolbar && (renderBottomToolbar === null || renderBottomToolbar === void 0 ? void 0 : renderBottomToolbar({ table })))) !== null && _b !== void 0 ? _b : (React__default["default"].createElement(MRT_BottomToolbar, { table: table }))));
2397
2397
  };
2398
2398
 
2399
2399
  const MRT_EditRowModal = ({ open, row, table, }) => {
@@ -2548,6 +2548,22 @@ const MRT_TableRoot = (props) => {
2548
2548
  if (props.tableInstanceRef) {
2549
2549
  props.tableInstanceRef.current = table;
2550
2550
  }
2551
+ const initialBodyHeight = React.useRef();
2552
+ React.useEffect(() => {
2553
+ if (typeof window !== 'undefined') {
2554
+ initialBodyHeight.current = document.body.style.height;
2555
+ }
2556
+ }, []);
2557
+ React.useEffect(() => {
2558
+ if (typeof window !== 'undefined') {
2559
+ if (table.getState().isFullScreen) {
2560
+ document.body.style.height = '100vh';
2561
+ }
2562
+ else {
2563
+ document.body.style.height = initialBodyHeight.current;
2564
+ }
2565
+ }
2566
+ }, [table.getState().isFullScreen]);
2551
2567
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
2552
2568
  React__default["default"].createElement(material.Dialog, { PaperComponent: material.Box, TransitionComponent: material.Grow, disablePortal: true, fullScreen: true, keepMounted: false, onClose: () => table.setIsFullScreen(false), open: table.getState().isFullScreen, transitionDuration: 400 },
2553
2569
  React__default["default"].createElement(MRT_TablePaper, { table: table })),