material-react-table 2.0.0-beta.13 → 2.0.0-beta.15

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.
@@ -1,5 +1,5 @@
1
1
  const MRT_Localization_ZH_HANS = {
2
- actions: '动作',
2
+ actions: '操作',
3
3
  and: '与',
4
4
  cancel: '取消',
5
5
  changeFilterMode: '更改过滤模式',
@@ -10,7 +10,7 @@ const MRT_Localization_ZH_HANS = {
10
10
  clickToCopy: '点击以复制',
11
11
  collapse: '折叠',
12
12
  collapseAll: '全部折叠',
13
- columnActions: '列动作',
13
+ columnActions: '列操作',
14
14
  copiedToClipboard: '已复制至剪贴板',
15
15
  dropToGroupBy: '拖放以按 {column} 分组',
16
16
  edit: '编辑',
@@ -62,7 +62,7 @@ const MRT_Localization_ZH_HANS = {
62
62
  pinToRight: '固定至右边',
63
63
  resetColumnSize: '重置列大小',
64
64
  resetOrder: '重置排序',
65
- rowActions: '行动作',
65
+ rowActions: '行操作',
66
66
  rowNumber: '#',
67
67
  rowNumbers: '行号码',
68
68
  rowsPerPage: '每页行数',
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const MRT_Localization_ZH_HANS = {
6
- actions: '动作',
6
+ actions: '操作',
7
7
  and: '与',
8
8
  cancel: '取消',
9
9
  changeFilterMode: '更改过滤模式',
@@ -14,7 +14,7 @@ const MRT_Localization_ZH_HANS = {
14
14
  clickToCopy: '点击以复制',
15
15
  collapse: '折叠',
16
16
  collapseAll: '全部折叠',
17
- columnActions: '列动作',
17
+ columnActions: '列操作',
18
18
  copiedToClipboard: '已复制至剪贴板',
19
19
  dropToGroupBy: '拖放以按 {column} 分组',
20
20
  edit: '编辑',
@@ -66,7 +66,7 @@ const MRT_Localization_ZH_HANS = {
66
66
  pinToRight: '固定至右边',
67
67
  resetColumnSize: '重置列大小',
68
68
  resetOrder: '重置排序',
69
- rowActions: '行动作',
69
+ rowActions: '行操作',
70
70
  rowNumber: '#',
71
71
  rowNumbers: '行号码',
72
72
  rowsPerPage: '每页行数',
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.0-beta.13",
2
+ "version": "2.0.0-beta.15",
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.",
@@ -348,3 +348,20 @@ export function createMRTColumnHelper<
348
348
  group: (column) => column as MRT_GroupColumnDef<TData>,
349
349
  };
350
350
  }
351
+
352
+ export const getValueAndLabel = (
353
+ option: { label?: string; text?: string; value: string } | string,
354
+ ): { label: string; value: string } => {
355
+ let label: string = '';
356
+ let value: string = '';
357
+ if (option) {
358
+ if (typeof option !== 'object') {
359
+ label = option;
360
+ value = option;
361
+ } else {
362
+ label = option.label ?? option.text ?? option.value;
363
+ value = option.value ?? label;
364
+ }
365
+ }
366
+ return { label, value };
367
+ };
@@ -0,0 +1,4 @@
1
+ export * from './useMRT_DisplayColumns';
2
+ export * from './useMRT_Effects';
3
+ export * from './useMRT_TableInstance';
4
+ export * from './useMRT_TableOptions';
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from './column.utils';
6
6
  export * from './filterFns';
7
7
  export * from './footer';
8
8
  export * from './head';
9
+ export * from './hooks';
9
10
  export * from './inputs';
10
11
  export * from './menus';
11
12
  export * from './modals';
@@ -7,7 +7,7 @@ import {
7
7
  import MenuItem from '@mui/material/MenuItem';
8
8
  import TextField from '@mui/material/TextField';
9
9
  import { type TextFieldProps } from '@mui/material/TextField';
10
- import { parseFromValuesOrFunc } from '../column.utils';
10
+ import { getValueAndLabel, parseFromValuesOrFunc } from '../column.utils';
11
11
  import {
12
12
  type MRT_Cell,
13
13
  type MRT_RowData,
@@ -62,9 +62,9 @@ export const MRT_EditCellTextField = <TData extends MRT_RowData>({
62
62
  //@ts-ignore
63
63
  row._valuesCache[column.id] = newValue;
64
64
  if (isCreating) {
65
- setCreatingRow({ ...row });
65
+ setCreatingRow(row);
66
66
  } else if (isEditing) {
67
- setEditingRow({ ...row });
67
+ setEditingRow(row);
68
68
  }
69
69
  };
70
70
 
@@ -150,33 +150,23 @@ export const MRT_EditCellTextField = <TData extends MRT_RowData>({
150
150
  onKeyDown={handleEnterKeyDown}
151
151
  >
152
152
  {textFieldProps.children ??
153
- columnDef?.editSelectOptions?.map(
154
- (option: { text: string; value: string } | string) => {
155
- let value: string;
156
- let text: string;
157
- if (typeof option !== 'object') {
158
- value = option;
159
- text = option;
160
- } else {
161
- value = option.value;
162
- text = option.text;
163
- }
164
- return (
165
- <MenuItem
166
- key={value}
167
- sx={{
168
- alignItems: 'center',
169
- display: 'flex',
170
- gap: '0.5rem',
171
- m: 0,
172
- }}
173
- value={value}
174
- >
175
- {text}
176
- </MenuItem>
177
- );
178
- },
179
- )}
153
+ columnDef?.editSelectOptions?.map((option) => {
154
+ const { label, value } = getValueAndLabel(option);
155
+ return (
156
+ <MenuItem
157
+ key={value}
158
+ sx={{
159
+ alignItems: 'center',
160
+ display: 'flex',
161
+ gap: '0.5rem',
162
+ m: 0,
163
+ }}
164
+ value={value}
165
+ >
166
+ {label}
167
+ </MenuItem>
168
+ );
169
+ })}
180
170
  </TextField>
181
171
  );
182
172
  };
@@ -21,7 +21,7 @@ import {
21
21
  DatePicker,
22
22
  type DatePickerProps,
23
23
  } from '@mui/x-date-pickers/DatePicker';
24
- import { parseFromValuesOrFunc } from '../column.utils';
24
+ import { getValueAndLabel, parseFromValuesOrFunc } from '../column.utils';
25
25
  import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
26
26
  import {
27
27
  type MRT_Header,
@@ -309,6 +309,7 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
309
309
  </label>
310
310
  ) : null,
311
311
  inputProps: {
312
+ 'aria-label': filterPlaceholder,
312
313
  autoComplete: 'new-password', // disable autocomplete and autofill
313
314
  disabled: !!filterChipLabel,
314
315
  sx: {
@@ -373,9 +374,13 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
373
374
  ) : isAutocompleteFilter ? (
374
375
  <Autocomplete
375
376
  freeSolo
376
- getOptionLabel={(option) => option}
377
- onChange={(_e, newValue) => handleChange(newValue)}
378
- options={dropdownOptions ?? []}
377
+ getOptionLabel={(option) => getValueAndLabel(option).label}
378
+ onChange={(_e, newValue) =>
379
+ handleChange(getValueAndLabel(newValue).value)
380
+ }
381
+ options={
382
+ dropdownOptions?.map((option) => getValueAndLabel(option)) ?? []
383
+ }
379
384
  {...autocompleteProps}
380
385
  renderInput={(builtinTextFieldProps) => (
381
386
  <TextField
@@ -407,19 +412,13 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
407
412
  ) : (
408
413
  <Box sx={{ display: 'flex', flexWrap: 'wrap', gap: '2px' }}>
409
414
  {(selected as string[])?.map((value) => {
410
- const selectedValue = dropdownOptions?.find((option) =>
411
- option instanceof Object
412
- ? option.value === value
413
- : option === value,
415
+ const selectedValue = dropdownOptions?.find(
416
+ (option) => getValueAndLabel(option).value === value,
414
417
  );
415
418
  return (
416
419
  <Chip
417
420
  key={value}
418
- label={
419
- selectedValue instanceof Object
420
- ? selectedValue.text
421
- : selectedValue
422
- }
421
+ label={getValueAndLabel(selectedValue).label}
423
422
  />
424
423
  );
425
424
  })}
@@ -438,44 +437,33 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
438
437
  </MenuItem>,
439
438
  ...[
440
439
  textFieldProps.children ??
441
- dropdownOptions?.map(
442
- (option: { text: string; value: string } | string, index) => {
443
- if (!option) return '';
444
- let value: string;
445
- let text: string;
446
- if (typeof option !== 'object') {
447
- value = option;
448
- text = option;
449
- } else {
450
- value = option.value;
451
- text = option.text;
452
- }
453
- return (
454
- <MenuItem
455
- key={`${index}-${value}`}
456
- sx={{
457
- alignItems: 'center',
458
- display: 'flex',
459
- gap: '0.5rem',
460
- m: 0,
461
- }}
462
- value={value}
463
- >
464
- {isMultiSelectFilter && (
465
- <Checkbox
466
- checked={(
467
- (column.getFilterValue() ?? []) as string[]
468
- ).includes(value)}
469
- sx={{ mr: '0.5rem' }}
470
- />
471
- )}
472
- {text}{' '}
473
- {!columnDef.filterSelectOptions &&
474
- `(${facetedUniqueValues.get(value)})`}
475
- </MenuItem>
476
- );
477
- },
478
- ),
440
+ dropdownOptions?.map((option, index) => {
441
+ const { label, value } = getValueAndLabel(option);
442
+ return (
443
+ <MenuItem
444
+ key={`${index}-${value}`}
445
+ sx={{
446
+ alignItems: 'center',
447
+ display: 'flex',
448
+ gap: '0.5rem',
449
+ m: 0,
450
+ }}
451
+ value={value}
452
+ >
453
+ {isMultiSelectFilter && (
454
+ <Checkbox
455
+ checked={(
456
+ (column.getFilterValue() ?? []) as string[]
457
+ ).includes(value)}
458
+ sx={{ mr: '0.5rem' }}
459
+ />
460
+ )}
461
+ {label}{' '}
462
+ {!columnDef.filterSelectOptions &&
463
+ `(${facetedUniqueValues.get(value)})`}
464
+ </MenuItem>
465
+ );
466
+ }),
479
467
  ],
480
468
  ]}
481
469
  </TextField>
@@ -1,7 +1,7 @@
1
1
  import { type MRT_Localization } from '..';
2
2
 
3
3
  export const MRT_Localization_ZH_HANS: MRT_Localization = {
4
- actions: '动作',
4
+ actions: '操作',
5
5
  and: '与',
6
6
  cancel: '取消',
7
7
  changeFilterMode: '更改过滤模式',
@@ -12,7 +12,7 @@ export const MRT_Localization_ZH_HANS: MRT_Localization = {
12
12
  clickToCopy: '点击以复制',
13
13
  collapse: '折叠',
14
14
  collapseAll: '全部折叠',
15
- columnActions: '列动作',
15
+ columnActions: '列操作',
16
16
  copiedToClipboard: '已复制至剪贴板',
17
17
  dropToGroupBy: '拖放以按 {column} 分组',
18
18
  edit: '编辑',
@@ -64,7 +64,7 @@ export const MRT_Localization_ZH_HANS: MRT_Localization = {
64
64
  pinToRight: '固定至右边',
65
65
  resetColumnSize: '重置列大小',
66
66
  resetOrder: '重置排序',
67
- rowActions: '行动作',
67
+ rowActions: '行操作',
68
68
  rowNumber: '#',
69
69
  rowNumbers: '行号码',
70
70
  rowsPerPage: '每页行数',
@@ -27,7 +27,7 @@ export const MRT_TablePaper = <TData extends MRT_RowData>({
27
27
  } = table;
28
28
  const { isFullScreen } = getState();
29
29
 
30
- const tablePaperProps = {
30
+ const paperProps = {
31
31
  ...parseFromValuesOrFunc(muiTablePaperProps, { table }),
32
32
  ...rest,
33
33
  };
@@ -35,12 +35,12 @@ export const MRT_TablePaper = <TData extends MRT_RowData>({
35
35
  return (
36
36
  <Paper
37
37
  elevation={2}
38
- {...tablePaperProps}
38
+ {...paperProps}
39
39
  ref={(ref: HTMLDivElement) => {
40
40
  tablePaperRef.current = ref;
41
- if (tablePaperProps?.ref) {
41
+ if (paperProps?.ref) {
42
42
  //@ts-ignore
43
- tablePaperProps.ref.current = ref;
43
+ paperProps.ref.current = ref;
44
44
  }
45
45
  }}
46
46
  style={{
@@ -60,14 +60,14 @@ export const MRT_TablePaper = <TData extends MRT_RowData>({
60
60
  zIndex: 999,
61
61
  }
62
62
  : {}),
63
- ...tablePaperProps?.style,
63
+ ...paperProps?.style,
64
64
  }}
65
65
  sx={(theme) => ({
66
66
  backgroundColor: getMRTTheme(table, theme).baseBackgroundColor,
67
67
  backgroundImage: 'unset',
68
68
  overflow: 'hidden',
69
69
  transition: 'all 100ms ease-in-out',
70
- ...(parseFromValuesOrFunc(tablePaperProps?.sx, theme) as any),
70
+ ...(parseFromValuesOrFunc(paperProps?.sx, theme) as any),
71
71
  })}
72
72
  >
73
73
  {enableTopToolbar &&
package/src/types.ts CHANGED
@@ -424,7 +424,17 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
424
424
  LiteralUnion<string & MRT_FilterOption>
425
425
  > | null;
426
426
  columns?: MRT_ColumnDef<TData, TValue>[];
427
- editSelectOptions?: ({ text: string; value: any } | string)[];
427
+ editSelectOptions?: (
428
+ | {
429
+ label?: string;
430
+ /**
431
+ * @deprecated use `label` instead
432
+ */
433
+ text?: string;
434
+ value: any;
435
+ }
436
+ | string
437
+ )[];
428
438
  editVariant?: 'select' | 'text';
429
439
  enableClickToCopy?: boolean;
430
440
  enableColumnActions?: boolean;
@@ -434,7 +444,17 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
434
444
  enableEditing?: ((row: MRT_Row<TData>) => boolean) | boolean;
435
445
  enableFilterMatchHighlighting?: boolean;
436
446
  filterFn?: MRT_FilterFn<TData>;
437
- filterSelectOptions?: ({ text: string; value: any } | string)[];
447
+ filterSelectOptions?: (
448
+ | {
449
+ label?: string;
450
+ /**
451
+ * @deprecated use `label` instead
452
+ */
453
+ text?: string;
454
+ value: any;
455
+ }
456
+ | string
457
+ )[];
438
458
  filterVariant?:
439
459
  | 'autocomplete'
440
460
  | 'checkbox'
@@ -1113,7 +1133,6 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
1113
1133
  }) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>)
1114
1134
  | Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>;
1115
1135
  selectAllMode?: 'all' | 'page';
1116
- selectDisplayMode?: 'checkbox' | 'radio' | 'switch';
1117
1136
  /**
1118
1137
  * Manage state externally any way you want, then pass it back into MRT.
1119
1138
  */