@etsoo/react 1.5.74 → 1.5.77
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/lib/components/ScrollerGrid.d.ts +4 -3
- package/lib/components/ScrollerList.d.ts +1 -1
- package/lib/mu/AutocompleteExtendedProps.d.ts +3 -3
- package/lib/mu/ComboBox.d.ts +4 -4
- package/lib/mu/ComboBox.js +6 -6
- package/lib/mu/DataGridEx.d.ts +4 -3
- package/lib/mu/OptionGroup.d.ts +6 -7
- package/lib/mu/ResponsibleContainer.d.ts +2 -2
- package/lib/mu/ScrollerListEx.d.ts +4 -3
- package/lib/mu/ScrollerListEx.js +1 -1
- package/lib/mu/SearchOptionGroup.d.ts +1 -2
- package/lib/mu/SelectBool.d.ts +2 -2
- package/lib/mu/SelectBool.js +1 -1
- package/lib/mu/SelectEx.d.ts +7 -7
- package/lib/mu/SelectEx.js +2 -2
- package/lib/mu/TableEx.d.ts +4 -3
- package/lib/mu/TableEx.js +1 -2
- package/lib/mu/Tiplist.d.ts +3 -4
- package/lib/mu/Tiplist.js +4 -4
- package/package.json +8 -8
- package/src/components/ScrollerGrid.tsx +6 -3
- package/src/components/ScrollerList.tsx +1 -3
- package/src/mu/AutocompleteExtendedProps.ts +6 -4
- package/src/mu/ComboBox.tsx +18 -15
- package/src/mu/DataGridEx.tsx +13 -12
- package/src/mu/MUGlobal.ts +1 -6
- package/src/mu/OptionGroup.tsx +15 -16
- package/src/mu/ResponsibleContainer.tsx +7 -5
- package/src/mu/ScrollerListEx.tsx +11 -8
- package/src/mu/SearchOptionGroup.tsx +2 -3
- package/src/mu/SelectBool.tsx +13 -5
- package/src/mu/SelectEx.tsx +19 -13
- package/src/mu/TableEx.tsx +15 -14
- package/src/mu/Tiplist.tsx +15 -13
package/src/mu/Tiplist.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { IdLabelDto } from '@etsoo/appscript';
|
|
2
1
|
import { DataTypes } from '@etsoo/shared';
|
|
3
2
|
import { Autocomplete, AutocompleteRenderInputParams } from '@mui/material';
|
|
4
3
|
import React from 'react';
|
|
@@ -11,14 +10,14 @@ import { SearchField } from './SearchField';
|
|
|
11
10
|
/**
|
|
12
11
|
* Tiplist props
|
|
13
12
|
*/
|
|
14
|
-
export interface TiplistProps<T extends {}
|
|
15
|
-
extends Omit<AutocompleteExtendedProps<T>, 'open'> {
|
|
13
|
+
export interface TiplistProps<T extends {}, D extends DataTypes.Keys<T>>
|
|
14
|
+
extends Omit<AutocompleteExtendedProps<T, D>, 'open'> {
|
|
16
15
|
/**
|
|
17
16
|
* Load data callback
|
|
18
17
|
*/
|
|
19
18
|
loadData: (
|
|
20
19
|
keyword?: string,
|
|
21
|
-
id?:
|
|
20
|
+
id?: T[D]
|
|
22
21
|
) => PromiseLike<T[] | null | undefined>;
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -35,11 +34,14 @@ interface States<T extends {}> {
|
|
|
35
34
|
* @param props Props
|
|
36
35
|
* @returns Component
|
|
37
36
|
*/
|
|
38
|
-
export function Tiplist<
|
|
37
|
+
export function Tiplist<
|
|
38
|
+
T extends {} = DataTypes.IdLabelItem,
|
|
39
|
+
D extends DataTypes.Keys<T> = DataTypes.Keys<T>
|
|
40
|
+
>(props: TiplistProps<T, D>) {
|
|
39
41
|
// Destruct
|
|
40
42
|
const {
|
|
41
43
|
search = false,
|
|
42
|
-
idField = 'id',
|
|
44
|
+
idField = 'id' as D,
|
|
43
45
|
idValue,
|
|
44
46
|
inputAutoComplete = 'off',
|
|
45
47
|
inputError,
|
|
@@ -69,7 +71,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
|
|
|
69
71
|
|
|
70
72
|
// One time calculation for input's default value (uncontrolled)
|
|
71
73
|
const localIdValue =
|
|
72
|
-
idValue ??
|
|
74
|
+
idValue ?? DataTypes.getValue(localValue, idField ?? 'id');
|
|
73
75
|
|
|
74
76
|
// Changable states
|
|
75
77
|
const [states, stateUpdate] = React.useReducer(
|
|
@@ -86,7 +88,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
|
|
|
86
88
|
|
|
87
89
|
// Input value
|
|
88
90
|
const inputValue = React.useMemo(
|
|
89
|
-
() => states.value &&
|
|
91
|
+
() => states.value && states.value[idField],
|
|
90
92
|
[states.value]
|
|
91
93
|
);
|
|
92
94
|
|
|
@@ -130,7 +132,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
|
|
|
130
132
|
};
|
|
131
133
|
|
|
132
134
|
// Directly load data
|
|
133
|
-
const loadDataDirect = (keyword?: string, id?:
|
|
135
|
+
const loadDataDirect = (keyword?: string, id?: T[D]) => {
|
|
134
136
|
// Reset options
|
|
135
137
|
// setOptions([]);
|
|
136
138
|
|
|
@@ -181,7 +183,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
|
|
|
181
183
|
}
|
|
182
184
|
};
|
|
183
185
|
|
|
184
|
-
if (localIdValue != null && localIdValue !== '') {
|
|
186
|
+
if (localIdValue != null && (localIdValue as any) !== '') {
|
|
185
187
|
if (state.idLoaded) {
|
|
186
188
|
// Set default
|
|
187
189
|
if (!state.idSet && states.options.length == 1) {
|
|
@@ -211,7 +213,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
|
|
|
211
213
|
type="text"
|
|
212
214
|
style={{ display: 'none' }}
|
|
213
215
|
name={name}
|
|
214
|
-
value={inputValue ?? ''}
|
|
216
|
+
value={`${inputValue ?? ''}`}
|
|
215
217
|
readOnly
|
|
216
218
|
onChange={inputOnChange}
|
|
217
219
|
/>
|
|
@@ -250,7 +252,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
|
|
|
250
252
|
undefined,
|
|
251
253
|
states.value == null
|
|
252
254
|
? undefined
|
|
253
|
-
:
|
|
255
|
+
: states.value[idField]
|
|
254
256
|
);
|
|
255
257
|
}}
|
|
256
258
|
onClose={() => {
|
|
@@ -291,7 +293,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
|
|
|
291
293
|
/>
|
|
292
294
|
)
|
|
293
295
|
}
|
|
294
|
-
isOptionEqualToValue={(option:
|
|
296
|
+
isOptionEqualToValue={(option: T, value: T) =>
|
|
295
297
|
option[idField] === value[idField]
|
|
296
298
|
}
|
|
297
299
|
{...rest}
|