@etsoo/react 1.5.76 → 1.5.79

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.
Files changed (83) hide show
  1. package/lib/app/CommonApp.d.ts +2 -2
  2. package/lib/app/Labels.d.ts +1 -1
  3. package/lib/app/ServiceApp.d.ts +2 -2
  4. package/lib/components/GridColumn.d.ts +10 -10
  5. package/lib/components/GridLoader.d.ts +7 -8
  6. package/lib/components/ScrollerGrid.d.ts +7 -7
  7. package/lib/components/ScrollerList.d.ts +2 -2
  8. package/lib/mu/AutocompleteExtendedProps.d.ts +4 -4
  9. package/lib/mu/ComboBox.d.ts +5 -5
  10. package/lib/mu/ComboBox.js +1 -1
  11. package/lib/mu/DataGridEx.d.ts +6 -5
  12. package/lib/mu/DataGridRenderers.d.ts +1 -1
  13. package/lib/mu/DnDList.d.ts +2 -2
  14. package/lib/mu/ItemList.d.ts +6 -5
  15. package/lib/mu/ItemList.js +4 -12
  16. package/lib/mu/ListMoreDisplay.d.ts +2 -2
  17. package/lib/mu/MUGlobal.d.ts +5 -5
  18. package/lib/mu/OptionGroup.d.ts +10 -11
  19. package/lib/mu/ResponsibleContainer.d.ts +6 -6
  20. package/lib/mu/ScrollerListEx.d.ts +11 -9
  21. package/lib/mu/ScrollerListEx.js +1 -1
  22. package/lib/mu/SearchOptionGroup.d.ts +2 -3
  23. package/lib/mu/SelectBool.d.ts +2 -3
  24. package/lib/mu/SelectBool.js +1 -1
  25. package/lib/mu/SelectEx.d.ts +6 -6
  26. package/lib/mu/SelectEx.js +1 -1
  27. package/lib/mu/TableEx.d.ts +5 -4
  28. package/lib/mu/TableEx.js +1 -2
  29. package/lib/mu/Tiplist.d.ts +4 -4
  30. package/lib/mu/Tiplist.js +2 -4
  31. package/lib/mu/pages/CommonPageProps.d.ts +1 -1
  32. package/lib/mu/pages/DataGridPage.d.ts +2 -2
  33. package/lib/mu/pages/DataGridPageProps.d.ts +3 -3
  34. package/lib/mu/pages/FixedListPage.d.ts +2 -2
  35. package/lib/mu/pages/ListPage.d.ts +2 -2
  36. package/lib/mu/pages/ListPageProps.d.ts +1 -2
  37. package/lib/mu/pages/ResponsivePage.d.ts +2 -2
  38. package/lib/mu/pages/ResponsivePageProps.d.ts +3 -3
  39. package/lib/mu/pages/SearchPageProps.d.ts +2 -2
  40. package/lib/mu/pages/TablePage.d.ts +2 -2
  41. package/lib/mu/pages/TablePageProps.d.ts +1 -2
  42. package/lib/mu/pages/ViewPage.d.ts +5 -4
  43. package/lib/states/IState.d.ts +1 -1
  44. package/lib/uses/useCombinedRefs.d.ts +1 -1
  45. package/package.json +11 -11
  46. package/src/app/CommonApp.ts +2 -2
  47. package/src/app/Labels.ts +1 -1
  48. package/src/app/ServiceApp.ts +2 -2
  49. package/src/components/GridColumn.ts +10 -11
  50. package/src/components/GridLoader.ts +7 -7
  51. package/src/components/ScrollerGrid.tsx +66 -59
  52. package/src/components/ScrollerList.tsx +2 -4
  53. package/src/mu/AutocompleteExtendedProps.ts +9 -9
  54. package/src/mu/ComboBox.tsx +21 -13
  55. package/src/mu/DataGridEx.tsx +19 -18
  56. package/src/mu/DataGridRenderers.tsx +1 -1
  57. package/src/mu/DnDList.tsx +2 -2
  58. package/src/mu/ItemList.tsx +28 -25
  59. package/src/mu/ListMoreDisplay.tsx +2 -2
  60. package/src/mu/MUGlobal.ts +5 -5
  61. package/src/mu/OptionGroup.tsx +30 -23
  62. package/src/mu/ResponsibleContainer.tsx +19 -22
  63. package/src/mu/ScrollerListEx.tsx +25 -21
  64. package/src/mu/SearchOptionGroup.tsx +11 -6
  65. package/src/mu/SelectBool.tsx +7 -12
  66. package/src/mu/SelectEx.tsx +21 -13
  67. package/src/mu/TableEx.tsx +61 -60
  68. package/src/mu/Tiplist.tsx +15 -12
  69. package/src/mu/pages/CommonPageProps.ts +1 -1
  70. package/src/mu/pages/DataGridPage.tsx +15 -11
  71. package/src/mu/pages/DataGridPageProps.ts +17 -14
  72. package/src/mu/pages/FixedListPage.tsx +6 -5
  73. package/src/mu/pages/ListPage.tsx +6 -5
  74. package/src/mu/pages/ListPageProps.ts +5 -3
  75. package/src/mu/pages/ResponsivePage.tsx +6 -5
  76. package/src/mu/pages/ResponsivePageProps.ts +10 -7
  77. package/src/mu/pages/SearchPageProps.ts +5 -3
  78. package/src/mu/pages/TablePage.tsx +6 -5
  79. package/src/mu/pages/TablePageProps.ts +5 -3
  80. package/src/mu/pages/ViewPage.tsx +8 -6
  81. package/src/states/IState.ts +1 -1
  82. package/src/states/UserState.ts +1 -1
  83. package/src/uses/useCombinedRefs.ts +3 -3
@@ -1,5 +1,10 @@
1
- import { IdLabelDto } from '@etsoo/appscript';
2
- import { DataTypes, Utils } from '@etsoo/shared';
1
+ import {
2
+ DataTypes,
3
+ IdDefaultType,
4
+ LabelDefaultType,
5
+ ListType,
6
+ Utils
7
+ } from '@etsoo/shared';
3
8
  import {
4
9
  Checkbox,
5
10
  FormControl,
@@ -15,14 +20,15 @@ import React from 'react';
15
20
  /**
16
21
  * OptionGroup props
17
22
  */
18
- export interface OptionGroupProps<
19
- T extends Record<string, any> = IdLabelDto,
20
- D extends DataTypes.IdType = string
21
- > extends Omit<FormControlProps<'fieldset'>, 'defaultValue'> {
23
+ export type OptionGroupProps<
24
+ T extends object,
25
+ D extends DataTypes.Keys<T>,
26
+ L extends DataTypes.Keys<T, string>
27
+ > = Omit<FormControlProps<'fieldset'>, 'defaultValue'> & {
22
28
  /**
23
29
  * Default value
24
30
  */
25
- defaultValue?: D | D[];
31
+ defaultValue?: T[D] | T[D][];
26
32
 
27
33
  /**
28
34
  * Get option label function
@@ -30,9 +36,9 @@ export interface OptionGroupProps<
30
36
  getOptionLabel?: (option: T) => string;
31
37
 
32
38
  /**
33
- * Id field, default is id
39
+ * Id field
34
40
  */
35
- idField?: string & keyof T;
41
+ idField?: D;
36
42
 
37
43
  /**
38
44
  * Label
@@ -40,9 +46,9 @@ export interface OptionGroupProps<
40
46
  label?: string;
41
47
 
42
48
  /**
43
- * Label field, default is label
49
+ * Label field
44
50
  */
45
- labelField?: string & keyof T;
51
+ labelField?: L;
46
52
 
47
53
  /**
48
54
  * Multiple choose item
@@ -57,7 +63,7 @@ export interface OptionGroupProps<
57
63
  /**
58
64
  * On value change handler
59
65
  */
60
- onValueChange?: (value: D | D[] | undefined) => void;
66
+ onValueChange?: (value: T[D] | T[D][] | undefined) => void;
61
67
 
62
68
  /**
63
69
  * Array of options.
@@ -73,7 +79,7 @@ export interface OptionGroupProps<
73
79
  * Display group of elements in a compact row
74
80
  */
75
81
  row?: boolean;
76
- }
82
+ };
77
83
 
78
84
  /**
79
85
  * OptionGroup
@@ -81,16 +87,17 @@ export interface OptionGroupProps<
81
87
  * @returns Component
82
88
  */
83
89
  export function OptionGroup<
84
- T extends Record<string, unknown> = IdLabelDto,
85
- D extends DataTypes.IdType = string
86
- >(props: OptionGroupProps<T, D>) {
90
+ T extends object = ListType,
91
+ D extends DataTypes.Keys<T> = IdDefaultType<T>,
92
+ L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
93
+ >(props: OptionGroupProps<T, D, L>) {
87
94
  // Destruct
88
95
  const {
89
96
  getOptionLabel,
90
97
  defaultValue,
91
- idField = 'id',
98
+ idField = 'id' as D,
92
99
  label,
93
- labelField = 'label',
100
+ labelField = 'label' as L,
94
101
  multiple = false,
95
102
  name,
96
103
  onValueChange,
@@ -103,10 +110,10 @@ export function OptionGroup<
103
110
 
104
111
  // Get option value
105
112
  // D type should be the source id type
106
- const getOptionValue = (option: T): D | null => {
113
+ const getOptionValue = (option: T): T[D] | null => {
107
114
  const value = DataTypes.getValue(option, idField);
108
115
  if (value == null) return null;
109
- return value as D;
116
+ return value as T[D];
110
117
  };
111
118
 
112
119
  // Checkbox values
@@ -142,7 +149,7 @@ export function OptionGroup<
142
149
  onChange={(event) => {
143
150
  if (firstOptionValue == null) return;
144
151
 
145
- const typeValue = Utils.parseString<D>(
152
+ const typeValue = Utils.parseString(
146
153
  event.target.value,
147
154
  firstOptionValue
148
155
  );
@@ -175,7 +182,7 @@ export function OptionGroup<
175
182
 
176
183
  // Value, convert to string
177
184
  // Will fail when type is number
178
- const value = getOptionValue(option);
185
+ const value = getOptionValue(option) as unknown as React.Key;
179
186
 
180
187
  return (
181
188
  <FormControlLabel
@@ -197,7 +204,7 @@ export function OptionGroup<
197
204
  value={values[0]}
198
205
  onChange={(_event, value) => {
199
206
  if (firstOptionValue == null) return;
200
- const typeValue = Utils.parseString<D>(value, firstOptionValue);
207
+ const typeValue = Utils.parseString(value, firstOptionValue);
201
208
  if (onValueChange) onValueChange(typeValue);
202
209
  setValues([typeValue]);
203
210
  }}
@@ -1,4 +1,4 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
2
  import { Box, Stack, SxProps, Theme } from '@mui/material';
3
3
  import React from 'react';
4
4
  import { ListChildComponentProps } from 'react-window';
@@ -30,18 +30,14 @@ import { SearchBar } from './SearchBar';
30
30
  /**
31
31
  * ResponsibleContainer props
32
32
  */
33
- export interface ResponsibleContainerProps<
34
- T extends {},
35
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate
36
- > extends Omit<
37
- DataGridExProps<T>,
38
- | 'height'
39
- | 'itemKey'
40
- | 'loadData'
41
- | 'mRef'
42
- | 'onScroll'
43
- | 'onItemsRendered'
44
- > {
33
+ export type ResponsibleContainerProps<
34
+ T extends object,
35
+ F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
36
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
37
+ > = Omit<
38
+ DataGridExProps<T, D>,
39
+ 'height' | 'itemKey' | 'loadData' | 'mRef' | 'onScroll' | 'onItemsRendered'
40
+ > & {
45
41
  /**
46
42
  * Height will be deducted
47
43
  * @param height Current calcuated height
@@ -57,7 +53,7 @@ export interface ResponsibleContainerProps<
57
53
  * Container box SX (dataGrid determines the case)
58
54
  */
59
55
  containerBoxSx?: (
60
- paddings: {},
56
+ paddings: Record<string, string | number>,
61
57
  hasFields: boolean,
62
58
  dataGrid?: boolean
63
59
  ) => SxProps<Theme>;
@@ -119,7 +115,7 @@ export interface ResponsibleContainerProps<
119
115
  /**
120
116
  * Paddings
121
117
  */
122
- paddings?: {};
118
+ paddings?: Record<string, string | number>;
123
119
 
124
120
  /**
125
121
  * Pull to refresh data
@@ -135,7 +131,7 @@ export interface ResponsibleContainerProps<
135
131
  * Size ready to read miliseconds span
136
132
  */
137
133
  sizeReadyMiliseconds?: number;
138
- }
134
+ };
139
135
 
140
136
  interface LocalRefs {
141
137
  rect?: DOMRect;
@@ -144,7 +140,7 @@ interface LocalRefs {
144
140
  }
145
141
 
146
142
  function defaultContainerBoxSx(
147
- paddings: {},
143
+ paddings: object,
148
144
  hasField: boolean,
149
145
  _dataGrid?: boolean
150
146
  ): SxProps<Theme> {
@@ -162,9 +158,10 @@ function defaultContainerBoxSx(
162
158
  * @returns Layout
163
159
  */
164
160
  export function ResponsibleContainer<
165
- T extends {},
166
- F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate
167
- >(props: ResponsibleContainerProps<T, F>) {
161
+ T extends object,
162
+ F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
163
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
164
+ >(props: ResponsibleContainerProps<T, F, D>) {
168
165
  // Destruct
169
166
  const {
170
167
  adjustHeight,
@@ -286,7 +283,7 @@ export function ResponsibleContainer<
286
283
 
287
284
  return [
288
285
  <Box className="DataGridBox">
289
- <DataGridEx<T>
286
+ <DataGridEx<T, D>
290
287
  autoLoad={!hasFields}
291
288
  height={heightLocal}
292
289
  width={rect.width}
@@ -319,7 +316,7 @@ export function ResponsibleContainer<
319
316
 
320
317
  return [
321
318
  <Box className="ListBox" sx={{ height: heightLocal }}>
322
- <ScrollerListEx<T>
319
+ <ScrollerListEx<T, D>
323
320
  autoLoad={!hasFields}
324
321
  height={heightLocal}
325
322
  loadData={localLoadData}
@@ -1,5 +1,5 @@
1
1
  import { css } from '@emotion/css';
2
- import { DataTypes, Utils } from '@etsoo/shared';
2
+ import { DataTypes, IdDefaultType, Utils } from '@etsoo/shared';
3
3
  import { useTheme } from '@mui/material';
4
4
  import React from 'react';
5
5
  import { ListChildComponentProps } from 'react-window';
@@ -47,7 +47,7 @@ const createGridStyle = (
47
47
  };
48
48
 
49
49
  // Default margin
50
- const defaultMargin = (margin: {}, isNarrow?: boolean) => {
50
+ const defaultMargin = (margin: object, isNarrow?: boolean) => {
51
51
  const half = MUGlobal.half(margin);
52
52
 
53
53
  if (isNarrow == null) {
@@ -100,7 +100,7 @@ export interface ScrollerListExInnerItemRendererProps<T>
100
100
  /**
101
101
  * Default margins
102
102
  */
103
- margins: {};
103
+ margins: object;
104
104
  }
105
105
 
106
106
  /**
@@ -110,25 +110,22 @@ export interface ScrollerListExInnerItemRendererProps<T>
110
110
  * 3. Dynamic calculation
111
111
  */
112
112
  export type ScrollerListExItemSize =
113
- | ((index: number) => [number, number] | [number, number, {}])
113
+ | ((index: number) => [number, number] | [number, number, object])
114
114
  | [number, number]
115
- | [number, {}, boolean?];
115
+ | [number, object, boolean?];
116
116
 
117
117
  /**
118
118
  * Extended ScrollerList Props
119
119
  */
120
- export interface ScrollerListExProps<T>
121
- extends Omit<ScrollerListProps<T>, 'itemRenderer' | 'itemSize'> {
120
+ export type ScrollerListExProps<
121
+ T extends object,
122
+ D extends DataTypes.Keys<T>
123
+ > = Omit<ScrollerListProps<T>, 'itemRenderer' | 'itemSize'> & {
122
124
  /**
123
125
  * Alternating colors for odd/even rows
124
126
  */
125
127
  alternatingColors?: [string?, string?];
126
128
 
127
- /**
128
- * Id field
129
- */
130
- idField?: string & keyof T;
131
-
132
129
  /**
133
130
  * Inner item renderer
134
131
  */
@@ -141,6 +138,12 @@ export interface ScrollerListExProps<T>
141
138
  */
142
139
  itemRenderer?: (props: ListChildComponentProps<T>) => React.ReactElement;
143
140
 
141
+ /**
142
+ * Id field
143
+ * Failed: D extends { id: DataTypes.IdType } ? { idField?: D } : { idField: D }
144
+ */
145
+ idField?: D;
146
+
144
147
  /**
145
148
  * Item size, a function indicates its a variable size list
146
149
  */
@@ -165,7 +168,7 @@ export interface ScrollerListExProps<T>
165
168
  * Selected color
166
169
  */
167
170
  selectedColor?: string;
168
- }
171
+ };
169
172
 
170
173
  interface defaultItemRendererProps<T> extends ListChildComponentProps<T> {
171
174
  /**
@@ -203,7 +206,7 @@ interface defaultItemRendererProps<T> extends ListChildComponentProps<T> {
203
206
  /**
204
207
  * Default margins
205
208
  */
206
- margins: {};
209
+ margins: object;
207
210
 
208
211
  /**
209
212
  * Item selected
@@ -260,9 +263,10 @@ function defaultItemRenderer<T>({
260
263
  * @param props Props
261
264
  * @returns Component
262
265
  */
263
- export function ScrollerListEx<T extends Record<string, unknown>>(
264
- props: ScrollerListExProps<T>
265
- ) {
266
+ export function ScrollerListEx<
267
+ T extends object,
268
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
269
+ >(props: ScrollerListExProps<T, D>) {
266
270
  // Selected item ref
267
271
  const selectedItem = React.useRef<[HTMLDivElement, T]>();
268
272
 
@@ -295,11 +299,11 @@ export function ScrollerListEx<T extends Record<string, unknown>>(
295
299
  const {
296
300
  alternatingColors = [undefined, undefined],
297
301
  className,
298
- idField = 'id',
302
+ idField = 'id' as D,
299
303
  innerItemRenderer,
300
304
  itemSize,
301
305
  itemKey = (index: number, data: T) =>
302
- DataTypes.getValue(data, idField) ?? index,
306
+ DataTypes.getIdValue1(data, idField) ?? index,
303
307
  itemRenderer = (itemProps) => {
304
308
  const [itemHeight, space, margins] = calculateItemSize(
305
309
  itemProps.index
@@ -328,7 +332,7 @@ export function ScrollerListEx<T extends Record<string, unknown>>(
328
332
 
329
333
  // Cache calculation
330
334
  const itemSizeResult = React.useMemo(():
331
- | [number, number, {}]
335
+ | [number, number, object]
332
336
  | undefined => {
333
337
  if (typeof itemSize === 'function') return undefined;
334
338
  const [size, spaces, isNarrow] = itemSize;
@@ -347,7 +351,7 @@ export function ScrollerListEx<T extends Record<string, unknown>>(
347
351
  }, [itemSize]);
348
352
 
349
353
  // Calculate size
350
- const calculateItemSize = (index: number): [number, number, {}] => {
354
+ const calculateItemSize = (index: number): [number, number, object] => {
351
355
  // Callback function
352
356
  if (typeof itemSize === 'function') {
353
357
  const result = itemSize(index);
@@ -1,5 +1,9 @@
1
- import { IdLabelDto } from '@etsoo/appscript';
2
- import { DataTypes } from '@etsoo/shared';
1
+ import {
2
+ DataTypes,
3
+ IdDefaultType,
4
+ LabelDefaultType,
5
+ ListType
6
+ } from '@etsoo/shared';
3
7
  import React from 'react';
4
8
  import { MUGlobal } from './MUGlobal';
5
9
  import { OptionGroup, OptionGroupProps } from './OptionGroup';
@@ -10,9 +14,10 @@ import { OptionGroup, OptionGroupProps } from './OptionGroup';
10
14
  * @returns Component
11
15
  */
12
16
  export function SearchOptionGroup<
13
- T extends Record<string, any> = IdLabelDto,
14
- D extends DataTypes.IdType = string
15
- >(props: OptionGroupProps<T, D>) {
17
+ T extends object = ListType,
18
+ D extends DataTypes.Keys<T> = IdDefaultType<T>,
19
+ L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
20
+ >(props: OptionGroupProps<T, D, L>) {
16
21
  // Destruct
17
22
  const {
18
23
  row = true,
@@ -22,5 +27,5 @@ export function SearchOptionGroup<
22
27
  } = props;
23
28
 
24
29
  // Layout
25
- return <OptionGroup<T, D> row={row} size={size} sx={sx} {...rest} />;
30
+ return <OptionGroup<T, D, L> row={row} size={size} sx={sx} {...rest} />;
26
31
  }
@@ -1,5 +1,4 @@
1
- import { IdLabelDto } from '@etsoo/appscript';
2
- import { Utils } from '@etsoo/shared';
1
+ import { ListType1, Utils } from '@etsoo/shared';
3
2
  import React from 'react';
4
3
  import { globalApp } from '..';
5
4
  import { SelectEx, SelectExProps } from './SelectEx';
@@ -7,8 +6,10 @@ import { SelectEx, SelectExProps } from './SelectEx';
7
6
  /**
8
7
  * SelectBool props
9
8
  */
10
- export interface SelectBoolProps
11
- extends Omit<SelectExProps<IdLabelDto<string>>, 'options' | 'loadData'> {}
9
+ export type SelectBoolProps = Omit<
10
+ SelectExProps<ListType1>,
11
+ 'options' | 'loadData'
12
+ >;
12
13
 
13
14
  /**
14
15
  * SelectBool (yes/no)
@@ -20,7 +21,7 @@ export function SelectBool(props: SelectBoolProps) {
20
21
  const { search = true, autoAddBlankItem = search, ...rest } = props;
21
22
 
22
23
  // Options
23
- const options: IdLabelDto<string>[] = [
24
+ const options: ListType1[] = [
24
25
  { id: 'false', label: globalApp.get('no')! },
25
26
  { id: 'true', label: globalApp.get('yes')! }
26
27
  ];
@@ -28,11 +29,5 @@ export function SelectBool(props: SelectBoolProps) {
28
29
  if (autoAddBlankItem) Utils.addBlankItem(options);
29
30
 
30
31
  // Layout
31
- return (
32
- <SelectEx<IdLabelDto<string>>
33
- options={options}
34
- search={search}
35
- {...rest}
36
- />
37
- );
32
+ return <SelectEx<ListType1> options={options} search={search} {...rest} />;
38
33
  }
@@ -12,16 +12,23 @@ import {
12
12
  import React from 'react';
13
13
  import { MUGlobal } from './MUGlobal';
14
14
  import { ListItemRightIcon } from './ListItemRightIcon';
15
- import { DataTypes, Utils } from '@etsoo/shared';
15
+ import {
16
+ DataTypes,
17
+ IdDefaultType,
18
+ LabelDefaultType,
19
+ ListType,
20
+ Utils
21
+ } from '@etsoo/shared';
16
22
  import { ReactUtils } from '../app/ReactUtils';
17
23
 
18
24
  /**
19
25
  * Extended select component props
20
26
  */
21
- export interface SelectExProps<
22
- T extends {},
23
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
24
- > extends Omit<SelectProps, 'labelId' | 'input' | 'native'> {
27
+ export type SelectExProps<
28
+ T extends object,
29
+ D extends DataTypes.Keys<T> = IdDefaultType<T>,
30
+ L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
31
+ > = Omit<SelectProps, 'labelId' | 'input' | 'native'> & {
25
32
  /**
26
33
  * Auto add blank item
27
34
  */
@@ -30,7 +37,7 @@ export interface SelectExProps<
30
37
  /**
31
38
  * Id field
32
39
  */
33
- idField: D;
40
+ idField?: D;
34
41
 
35
42
  /**
36
43
  * Item icon renderer
@@ -40,7 +47,7 @@ export interface SelectExProps<
40
47
  /**
41
48
  * Label field
42
49
  */
43
- labelField: ((option: T) => string) | D;
50
+ labelField?: L | ((option: T) => string);
44
51
 
45
52
  /**
46
53
  * Load data callback
@@ -66,7 +73,7 @@ export interface SelectExProps<
66
73
  * Is search case?
67
74
  */
68
75
  search?: boolean;
69
- }
76
+ };
70
77
 
71
78
  /**
72
79
  * Extended select component
@@ -74,16 +81,17 @@ export interface SelectExProps<
74
81
  * @returns Component
75
82
  */
76
83
  export function SelectEx<
77
- T extends {} = DataTypes.IdLabelItem,
78
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
79
- >(props: SelectExProps<T, D>) {
84
+ T extends object = ListType,
85
+ D extends DataTypes.Keys<T> = IdDefaultType<T>,
86
+ L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
87
+ >(props: SelectExProps<T, D, L>) {
80
88
  // Destruct
81
89
  const {
82
90
  defaultValue,
83
- idField,
91
+ idField = 'id' as D,
84
92
  itemIconRenderer,
85
93
  label,
86
- labelField,
94
+ labelField = 'label' as L,
87
95
  loadData,
88
96
  onItemClick,
89
97
  onLoadData,
@@ -1,4 +1,4 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { DataTypes, IdDefaultType } from '@etsoo/shared';
2
2
  import {
3
3
  Checkbox,
4
4
  Paper,
@@ -47,68 +47,69 @@ export interface TableExMethodRef extends GridMethodRef {
47
47
  /**
48
48
  * Extended table props
49
49
  */
50
- export interface TableExProps<T extends Record<string, any>>
51
- extends TableProps,
52
- GridLoader<T> {
53
- /**
54
- * Alternating colors for odd/even rows
55
- */
56
- alternatingColors?: [string?, string?];
57
-
58
- /**
59
- * Columns
60
- */
61
- columns: GridColumn<T>[];
62
-
63
- /**
64
- * Header cells background color and font color
65
- */
66
- headerColors?: [string?, string?];
67
-
68
- /**
69
- * Id field
70
- */
71
- idField?: string & keyof T;
72
-
73
- /**
74
- * Max height
75
- */
76
- maxHeight?: number;
77
-
78
- /**
79
- * Methods
80
- */
81
- mRef?: React.Ref<TableExMethodRef>;
82
-
83
- /**
84
- * On items select change
85
- */
86
- onSelectChange?: (selectedItems: T[]) => void;
87
-
88
- /**
89
- * Row height
90
- */
91
- rowHeight?: number;
92
-
93
- /**
94
- * Header and bottom height
95
- */
96
- otherHeight?: number;
97
- }
50
+ export type TableExProps<
51
+ T extends object,
52
+ D extends DataTypes.Keys<T>
53
+ > = TableProps &
54
+ GridLoader<T> & {
55
+ /**
56
+ * Alternating colors for odd/even rows
57
+ */
58
+ alternatingColors?: [string?, string?];
59
+
60
+ /**
61
+ * Columns
62
+ */
63
+ columns: GridColumn<T>[];
64
+
65
+ /**
66
+ * Header cells background color and font color
67
+ */
68
+ headerColors?: [string?, string?];
69
+
70
+ /**
71
+ * Id field
72
+ */
73
+ idField?: D;
74
+
75
+ /**
76
+ * Max height
77
+ */
78
+ maxHeight?: number;
79
+
80
+ /**
81
+ * Methods
82
+ */
83
+ mRef?: React.Ref<TableExMethodRef>;
84
+
85
+ /**
86
+ * On items select change
87
+ */
88
+ onSelectChange?: (selectedItems: T[]) => void;
89
+
90
+ /**
91
+ * Row height
92
+ */
93
+ rowHeight?: number;
94
+
95
+ /**
96
+ * Header and bottom height
97
+ */
98
+ otherHeight?: number;
99
+ };
98
100
 
99
101
  /**
100
102
  * Extended Table
101
103
  * @param props Props
102
104
  * @returns Component
103
105
  */
104
- export function TableEx<T extends Record<string, unknown>>(
105
- props: TableExProps<T>
106
- ) {
106
+ export function TableEx<
107
+ T extends object,
108
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
109
+ >(props: TableExProps<T, D>) {
107
110
  // Theme
108
111
  const theme = useTheme();
109
112
 
110
- type keyType = string & keyof T;
111
-
112
113
  // Destruct
113
114
  const {
114
115
  alternatingColors = [theme.palette.action.hover, undefined],
@@ -116,7 +117,7 @@ export function TableEx<T extends Record<string, unknown>>(
116
117
  columns,
117
118
  defaultOrderBy,
118
119
  headerColors = [undefined, undefined],
119
- idField = 'id' as keyType,
120
+ idField = 'id' as D,
120
121
  loadBatchSize,
121
122
  loadData,
122
123
  maxHeight,
@@ -451,7 +452,10 @@ export function TableEx<T extends Record<string, unknown>>(
451
452
  : false;
452
453
 
453
454
  return (
454
- <TableRow key={rowId} selected={isItemSelected}>
455
+ <TableRow
456
+ key={rowId as unknown as React.Key}
457
+ selected={isItemSelected}
458
+ >
455
459
  {selectable && (
456
460
  <TableCell padding="checkbox">
457
461
  {row && (
@@ -522,10 +526,7 @@ export function TableEx<T extends Record<string, unknown>>(
522
526
 
523
527
  return (
524
528
  <TableCell
525
- key={
526
- rowId.toString() +
527
- columnIndex
528
- }
529
+ key={`${rowId}${columnIndex}`}
529
530
  {...cellProps}
530
531
  >
531
532
  {child}