@etsoo/react 1.5.77 → 1.5.80

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/__tests__/mu/ComboBox.tsx +30 -0
  2. package/__tests__/mu/NotifierMUTests.tsx +1 -1
  3. package/__tests__/mu/SelectEx.tsx +26 -0
  4. package/lib/app/CommonApp.d.ts +2 -2
  5. package/lib/app/Labels.d.ts +1 -1
  6. package/lib/app/ServiceApp.d.ts +2 -2
  7. package/lib/components/GridColumn.d.ts +10 -10
  8. package/lib/components/GridLoader.d.ts +7 -8
  9. package/lib/components/ScrollerGrid.d.ts +6 -7
  10. package/lib/components/ScrollerList.d.ts +2 -2
  11. package/lib/mu/AutocompleteExtendedProps.d.ts +4 -4
  12. package/lib/mu/ComboBox.d.ts +5 -5
  13. package/lib/mu/DataGridEx.d.ts +6 -6
  14. package/lib/mu/DataGridRenderers.d.ts +1 -1
  15. package/lib/mu/DnDList.d.ts +2 -2
  16. package/lib/mu/ItemList.d.ts +6 -5
  17. package/lib/mu/ItemList.js +4 -12
  18. package/lib/mu/ListMoreDisplay.d.ts +2 -2
  19. package/lib/mu/MUGlobal.d.ts +5 -5
  20. package/lib/mu/OptionGroup.d.ts +8 -8
  21. package/lib/mu/ResponsibleContainer.d.ts +6 -6
  22. package/lib/mu/ScrollerListEx.d.ts +11 -10
  23. package/lib/mu/SearchOptionGroup.d.ts +2 -2
  24. package/lib/mu/SelectBool.d.ts +2 -3
  25. package/lib/mu/SelectBool.js +1 -1
  26. package/lib/mu/SelectEx.d.ts +8 -8
  27. package/lib/mu/SelectEx.js +3 -3
  28. package/lib/mu/TableEx.d.ts +4 -4
  29. package/lib/mu/Tiplist.d.ts +4 -4
  30. package/lib/mu/Tiplist.js +1 -3
  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 +12 -12
  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 -62
  52. package/src/components/ScrollerList.tsx +2 -2
  53. package/src/mu/AutocompleteExtendedProps.ts +9 -9
  54. package/src/mu/ComboBox.tsx +20 -12
  55. package/src/mu/DataGridEx.tsx +15 -15
  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 +22 -14
  62. package/src/mu/ResponsibleContainer.tsx +15 -20
  63. package/src/mu/ScrollerListEx.tsx +21 -20
  64. package/src/mu/SearchOptionGroup.tsx +11 -5
  65. package/src/mu/SelectBool.tsx +7 -14
  66. package/src/mu/SelectEx.tsx +25 -19
  67. package/src/mu/TableEx.tsx +53 -53
  68. package/src/mu/Tiplist.tsx +11 -10
  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,4 +1,10 @@
1
- import { DataTypes, Utils } from '@etsoo/shared';
1
+ import {
2
+ DataTypes,
3
+ IdDefaultType,
4
+ LabelDefaultType,
5
+ ListType,
6
+ Utils
7
+ } from '@etsoo/shared';
2
8
  import {
3
9
  Checkbox,
4
10
  FormControl,
@@ -14,10 +20,11 @@ import React from 'react';
14
20
  /**
15
21
  * OptionGroup props
16
22
  */
17
- export interface OptionGroupProps<
18
- T extends {} = DataTypes.IdLabelItem,
19
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
20
- > 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'> & {
21
28
  /**
22
29
  * Default value
23
30
  */
@@ -29,9 +36,9 @@ export interface OptionGroupProps<
29
36
  getOptionLabel?: (option: T) => string;
30
37
 
31
38
  /**
32
- * Id field, default is id
39
+ * Id field
33
40
  */
34
- idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
41
+ idField?: D;
35
42
 
36
43
  /**
37
44
  * Label
@@ -39,9 +46,9 @@ export interface OptionGroupProps<
39
46
  label?: string;
40
47
 
41
48
  /**
42
- * Label field, default is label
49
+ * Label field
43
50
  */
44
- labelField: T extends DataTypes.IdLabelItem ? D | undefined : D;
51
+ labelField?: L;
45
52
 
46
53
  /**
47
54
  * Multiple choose item
@@ -72,7 +79,7 @@ export interface OptionGroupProps<
72
79
  * Display group of elements in a compact row
73
80
  */
74
81
  row?: boolean;
75
- }
82
+ };
76
83
 
77
84
  /**
78
85
  * OptionGroup
@@ -80,16 +87,17 @@ export interface OptionGroupProps<
80
87
  * @returns Component
81
88
  */
82
89
  export function OptionGroup<
83
- T extends {} = DataTypes.IdLabelItem,
84
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
85
- >(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>) {
86
94
  // Destruct
87
95
  const {
88
96
  getOptionLabel,
89
97
  defaultValue,
90
98
  idField = 'id' as D,
91
99
  label,
92
- labelField = 'label' as D,
100
+ labelField = 'label' as L,
93
101
  multiple = false,
94
102
  name,
95
103
  onValueChange,
@@ -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,19 +30,14 @@ import { SearchBar } from './SearchBar';
30
30
  /**
31
31
  * ResponsibleContainer props
32
32
  */
33
- export interface ResponsibleContainerProps<
34
- T extends {},
33
+ export type ResponsibleContainerProps<
34
+ T extends object,
35
35
  F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
36
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
37
- > extends Omit<
38
- DataGridExProps<T, D>,
39
- | 'height'
40
- | 'itemKey'
41
- | 'loadData'
42
- | 'mRef'
43
- | 'onScroll'
44
- | 'onItemsRendered'
45
- > {
36
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
37
+ > = Omit<
38
+ DataGridExProps<T, D>,
39
+ 'height' | 'itemKey' | 'loadData' | 'mRef' | 'onScroll' | 'onItemsRendered'
40
+ > & {
46
41
  /**
47
42
  * Height will be deducted
48
43
  * @param height Current calcuated height
@@ -58,7 +53,7 @@ export interface ResponsibleContainerProps<
58
53
  * Container box SX (dataGrid determines the case)
59
54
  */
60
55
  containerBoxSx?: (
61
- paddings: {},
56
+ paddings: Record<string, string | number>,
62
57
  hasFields: boolean,
63
58
  dataGrid?: boolean
64
59
  ) => SxProps<Theme>;
@@ -120,7 +115,7 @@ export interface ResponsibleContainerProps<
120
115
  /**
121
116
  * Paddings
122
117
  */
123
- paddings?: {};
118
+ paddings?: Record<string, string | number>;
124
119
 
125
120
  /**
126
121
  * Pull to refresh data
@@ -136,7 +131,7 @@ export interface ResponsibleContainerProps<
136
131
  * Size ready to read miliseconds span
137
132
  */
138
133
  sizeReadyMiliseconds?: number;
139
- }
134
+ };
140
135
 
141
136
  interface LocalRefs {
142
137
  rect?: DOMRect;
@@ -145,7 +140,7 @@ interface LocalRefs {
145
140
  }
146
141
 
147
142
  function defaultContainerBoxSx(
148
- paddings: {},
143
+ paddings: object,
149
144
  hasField: boolean,
150
145
  _dataGrid?: boolean
151
146
  ): SxProps<Theme> {
@@ -163,9 +158,9 @@ function defaultContainerBoxSx(
163
158
  * @returns Layout
164
159
  */
165
160
  export function ResponsibleContainer<
166
- T extends {},
161
+ T extends object,
167
162
  F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate,
168
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
163
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
169
164
  >(props: ResponsibleContainerProps<T, F, D>) {
170
165
  // Destruct
171
166
  const {
@@ -288,7 +283,7 @@ export function ResponsibleContainer<
288
283
 
289
284
  return [
290
285
  <Box className="DataGridBox">
291
- <DataGridEx<T>
286
+ <DataGridEx<T, D>
292
287
  autoLoad={!hasFields}
293
288
  height={heightLocal}
294
289
  width={rect.width}
@@ -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,27 +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<
121
- T extends {},
122
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
123
- > 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'> & {
124
124
  /**
125
125
  * Alternating colors for odd/even rows
126
126
  */
127
127
  alternatingColors?: [string?, string?];
128
128
 
129
- /**
130
- * Id field
131
- */
132
- idField?: D;
133
-
134
129
  /**
135
130
  * Inner item renderer
136
131
  */
@@ -143,6 +138,12 @@ export interface ScrollerListExProps<
143
138
  */
144
139
  itemRenderer?: (props: ListChildComponentProps<T>) => React.ReactElement;
145
140
 
141
+ /**
142
+ * Id field
143
+ * Failed: D extends { id: DataTypes.IdType } ? { idField?: D } : { idField: D }
144
+ */
145
+ idField?: D;
146
+
146
147
  /**
147
148
  * Item size, a function indicates its a variable size list
148
149
  */
@@ -167,7 +168,7 @@ export interface ScrollerListExProps<
167
168
  * Selected color
168
169
  */
169
170
  selectedColor?: string;
170
- }
171
+ };
171
172
 
172
173
  interface defaultItemRendererProps<T> extends ListChildComponentProps<T> {
173
174
  /**
@@ -205,7 +206,7 @@ interface defaultItemRendererProps<T> extends ListChildComponentProps<T> {
205
206
  /**
206
207
  * Default margins
207
208
  */
208
- margins: {};
209
+ margins: object;
209
210
 
210
211
  /**
211
212
  * Item selected
@@ -263,8 +264,8 @@ function defaultItemRenderer<T>({
263
264
  * @returns Component
264
265
  */
265
266
  export function ScrollerListEx<
266
- T extends {},
267
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
267
+ T extends object,
268
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
268
269
  >(props: ScrollerListExProps<T, D>) {
269
270
  // Selected item ref
270
271
  const selectedItem = React.useRef<[HTMLDivElement, T]>();
@@ -331,7 +332,7 @@ export function ScrollerListEx<
331
332
 
332
333
  // Cache calculation
333
334
  const itemSizeResult = React.useMemo(():
334
- | [number, number, {}]
335
+ | [number, number, object]
335
336
  | undefined => {
336
337
  if (typeof itemSize === 'function') return undefined;
337
338
  const [size, spaces, isNarrow] = itemSize;
@@ -350,7 +351,7 @@ export function ScrollerListEx<
350
351
  }, [itemSize]);
351
352
 
352
353
  // Calculate size
353
- const calculateItemSize = (index: number): [number, number, {}] => {
354
+ const calculateItemSize = (index: number): [number, number, object] => {
354
355
  // Callback function
355
356
  if (typeof itemSize === 'function') {
356
357
  const result = itemSize(index);
@@ -1,4 +1,9 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import {
2
+ DataTypes,
3
+ IdDefaultType,
4
+ LabelDefaultType,
5
+ ListType
6
+ } from '@etsoo/shared';
2
7
  import React from 'react';
3
8
  import { MUGlobal } from './MUGlobal';
4
9
  import { OptionGroup, OptionGroupProps } from './OptionGroup';
@@ -9,9 +14,10 @@ import { OptionGroup, OptionGroupProps } from './OptionGroup';
9
14
  * @returns Component
10
15
  */
11
16
  export function SearchOptionGroup<
12
- T extends {} = DataTypes.IdLabelItem,
13
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
14
- >(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>) {
15
21
  // Destruct
16
22
  const {
17
23
  row = true,
@@ -21,5 +27,5 @@ export function SearchOptionGroup<
21
27
  } = props;
22
28
 
23
29
  // Layout
24
- return <OptionGroup<T, D> row={row} size={size} sx={sx} {...rest} />;
30
+ return <OptionGroup<T, D, L> row={row} size={size} sx={sx} {...rest} />;
25
31
  }
@@ -1,4 +1,4 @@
1
- import { DataTypes, Utils } from '@etsoo/shared';
1
+ import { ListType1, Utils } from '@etsoo/shared';
2
2
  import React from 'react';
3
3
  import { globalApp } from '..';
4
4
  import { SelectEx, SelectExProps } from './SelectEx';
@@ -6,11 +6,10 @@ import { SelectEx, SelectExProps } from './SelectEx';
6
6
  /**
7
7
  * SelectBool props
8
8
  */
9
- export interface SelectBoolProps
10
- extends Omit<
11
- SelectExProps<DataTypes.IdLabelItem<string>>,
12
- 'options' | 'loadData'
13
- > {}
9
+ export type SelectBoolProps = Omit<
10
+ SelectExProps<ListType1>,
11
+ 'options' | 'loadData'
12
+ >;
14
13
 
15
14
  /**
16
15
  * SelectBool (yes/no)
@@ -22,7 +21,7 @@ export function SelectBool(props: SelectBoolProps) {
22
21
  const { search = true, autoAddBlankItem = search, ...rest } = props;
23
22
 
24
23
  // Options
25
- const options: DataTypes.IdLabelItem<string>[] = [
24
+ const options: ListType1[] = [
26
25
  { id: 'false', label: globalApp.get('no')! },
27
26
  { id: 'true', label: globalApp.get('yes')! }
28
27
  ];
@@ -30,11 +29,5 @@ export function SelectBool(props: SelectBoolProps) {
30
29
  if (autoAddBlankItem) Utils.addBlankItem(options);
31
30
 
32
31
  // Layout
33
- return (
34
- <SelectEx<DataTypes.IdLabelItem<string>>
35
- options={options}
36
- search={search}
37
- {...rest}
38
- />
39
- );
32
+ return <SelectEx<ListType1> options={options} search={search} {...rest} />;
40
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,19 +37,17 @@ export interface SelectExProps<
30
37
  /**
31
38
  * Id field
32
39
  */
33
- idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
40
+ idField?: D;
34
41
 
35
42
  /**
36
43
  * Item icon renderer
37
44
  */
38
- itemIconRenderer?: (id: unknown) => React.ReactNode;
45
+ itemIconRenderer?: (id: T[D]) => React.ReactNode;
39
46
 
40
47
  /**
41
48
  * Label field
42
49
  */
43
- labelField:
44
- | ((option: T) => string)
45
- | (T extends DataTypes.IdLabelItem ? D | undefined : D);
50
+ labelField?: L | ((option: T) => string);
46
51
 
47
52
  /**
48
53
  * Load data callback
@@ -52,7 +57,7 @@ export interface SelectExProps<
52
57
  /**
53
58
  * Item click handler
54
59
  */
55
- onItemClick?: (event: React.MouseEvent, id: unknown) => void;
60
+ onItemClick?: (event: React.MouseEvent, option: T) => void;
56
61
 
57
62
  /**
58
63
  * On load data handler
@@ -68,7 +73,7 @@ export interface SelectExProps<
68
73
  * Is search case?
69
74
  */
70
75
  search?: boolean;
71
- }
76
+ };
72
77
 
73
78
  /**
74
79
  * Extended select component
@@ -76,16 +81,17 @@ export interface SelectExProps<
76
81
  * @returns Component
77
82
  */
78
83
  export function SelectEx<
79
- T extends {} = DataTypes.IdLabelItem,
80
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
81
- >(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>) {
82
88
  // Destruct
83
89
  const {
84
90
  defaultValue,
85
91
  idField = 'id' as D,
86
92
  itemIconRenderer,
87
93
  label,
88
- labelField = 'label' as D,
94
+ labelField = 'label' as L,
89
95
  loadData,
90
96
  onItemClick,
91
97
  onLoadData,
@@ -166,7 +172,7 @@ export function SelectEx<
166
172
  const getLabel = (option: T) => {
167
173
  return typeof labelField === 'function'
168
174
  ? labelField(option)
169
- : new String(option[labelField]);
175
+ : (option[labelField] as string);
170
176
  };
171
177
 
172
178
  // Refs
@@ -262,7 +268,7 @@ export function SelectEx<
262
268
  value={id}
263
269
  onClick={(event) => {
264
270
  if (onItemClick) {
265
- onItemClick(event, id);
271
+ onItemClick(event, option);
266
272
  if (event.defaultPrevented) return;
267
273
  }
268
274
  if (!multiple) setItemValue(id);
@@ -272,7 +278,7 @@ export function SelectEx<
272
278
  <ListItemText primary={label} />
273
279
  {itemIconRenderer && (
274
280
  <ListItemRightIcon>
275
- {itemIconRenderer(id)}
281
+ {itemIconRenderer(option[idField])}
276
282
  </ListItemRightIcon>
277
283
  )}
278
284
  </MenuItem>
@@ -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,56 +47,56 @@ export interface TableExMethodRef extends GridMethodRef {
47
47
  /**
48
48
  * Extended table props
49
49
  */
50
- export interface TableExProps<
51
- T extends {},
52
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
53
- > extends 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
- }
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
+ };
100
100
 
101
101
  /**
102
102
  * Extended Table
@@ -104,8 +104,8 @@ export interface TableExProps<
104
104
  * @returns Component
105
105
  */
106
106
  export function TableEx<
107
- T extends {},
108
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
107
+ T extends object,
108
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
109
109
  >(props: TableExProps<T, D>) {
110
110
  // Theme
111
111
  const theme = useTheme();
@@ -1,4 +1,4 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { DataTypes, IdDefaultType, ListType } from '@etsoo/shared';
2
2
  import { Autocomplete, AutocompleteRenderInputParams } from '@mui/material';
3
3
  import React from 'react';
4
4
  import { ReactUtils } from '../app/ReactUtils';
@@ -10,8 +10,10 @@ import { SearchField } from './SearchField';
10
10
  /**
11
11
  * Tiplist props
12
12
  */
13
- export interface TiplistProps<T extends {}, D extends DataTypes.Keys<T>>
14
- extends Omit<AutocompleteExtendedProps<T, D>, 'open'> {
13
+ export type TiplistProps<T extends object, D extends DataTypes.Keys<T>> = Omit<
14
+ AutocompleteExtendedProps<T, D>,
15
+ 'open'
16
+ > & {
15
17
  /**
16
18
  * Load data callback
17
19
  */
@@ -19,10 +21,10 @@ export interface TiplistProps<T extends {}, D extends DataTypes.Keys<T>>
19
21
  keyword?: string,
20
22
  id?: T[D]
21
23
  ) => PromiseLike<T[] | null | undefined>;
22
- }
24
+ };
23
25
 
24
26
  // Multiple states
25
- interface States<T extends {}> {
27
+ interface States<T extends object> {
26
28
  open: boolean;
27
29
  options: T[];
28
30
  value?: T | null;
@@ -35,8 +37,8 @@ interface States<T extends {}> {
35
37
  * @returns Component
36
38
  */
37
39
  export function Tiplist<
38
- T extends {} = DataTypes.IdLabelItem,
39
- D extends DataTypes.Keys<T> = DataTypes.Keys<T>
40
+ T extends object = ListType,
41
+ D extends DataTypes.Keys<T> = IdDefaultType<T>
40
42
  >(props: TiplistProps<T, D>) {
41
43
  // Destruct
42
44
  const {
@@ -67,11 +69,10 @@ export function Tiplist<
67
69
 
68
70
  // Local value
69
71
  let localValue = value ?? defaultValue;
70
- if (localValue === undefined) localValue = null;
71
72
 
72
73
  // One time calculation for input's default value (uncontrolled)
73
74
  const localIdValue =
74
- idValue ?? DataTypes.getValue(localValue, idField ?? 'id');
75
+ idValue ?? DataTypes.getValue(localValue, idField as any);
75
76
 
76
77
  // Changable states
77
78
  const [states, stateUpdate] = React.useReducer(
@@ -218,7 +219,7 @@ export function Tiplist<
218
219
  onChange={inputOnChange}
219
220
  />
220
221
  {/* Previous input will reset first with "disableClearable = false", next input trigger change works */}
221
- <Autocomplete
222
+ <Autocomplete<T, undefined, false, false>
222
223
  filterOptions={(options, _state) => options}
223
224
  value={states.value}
224
225
  options={states.options}
@@ -52,7 +52,7 @@ export interface CommonPageProps extends Omit<ContainerProps, 'id'> {
52
52
  /**
53
53
  * Paddings
54
54
  */
55
- paddings?: {};
55
+ paddings?: Record<string, string | number>;
56
56
 
57
57
  /**
58
58
  * Scroll container