@etsoo/materialui 1.1.28 → 1.1.29
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/Tiplist.d.ts +5 -1
- package/lib/Tiplist.js +22 -4
- package/package.json +1 -1
- package/src/Tiplist.tsx +31 -4
package/lib/Tiplist.d.ts
CHANGED
|
@@ -8,7 +8,11 @@ export type TiplistProps<T extends object, D extends DataTypes.Keys<T>> = Omit<A
|
|
|
8
8
|
/**
|
|
9
9
|
* Load data callback
|
|
10
10
|
*/
|
|
11
|
-
loadData: (keyword
|
|
11
|
+
loadData: (keyword: string | undefined, id: T[D] | undefined, maxItems: number) => PromiseLike<T[] | null | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Max items to read and display
|
|
14
|
+
*/
|
|
15
|
+
maxItems?: number;
|
|
12
16
|
};
|
|
13
17
|
/**
|
|
14
18
|
* Tiplist
|
package/lib/Tiplist.js
CHANGED
|
@@ -12,9 +12,9 @@ import { SearchField } from "./SearchField";
|
|
|
12
12
|
*/
|
|
13
13
|
export function Tiplist(props) {
|
|
14
14
|
// Labels
|
|
15
|
-
const labels = globalApp === null || globalApp === void 0 ? void 0 : globalApp.getLabels("noOptions", "loading");
|
|
15
|
+
const labels = globalApp === null || globalApp === void 0 ? void 0 : globalApp.getLabels("noOptions", "loading", "more");
|
|
16
16
|
// Destruct
|
|
17
|
-
const { search = false, idField = "id", idValue, inputAutoComplete = "new-password", inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, label, loadData, defaultValue, value, name, readOnly, onChange, openOnFocus = true, sx = { minWidth: "180px" }, noOptionsText = labels === null || labels === void 0 ? void 0 : labels.noOptions, loadingText = labels === null || labels === void 0 ? void 0 : labels.loading, ...rest } = props;
|
|
17
|
+
const { search = false, idField = "id", idValue, inputAutoComplete = "new-password", inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, label, loadData, defaultValue, value, maxItems = 16, name, readOnly, onChange, openOnFocus = true, sx = { minWidth: "180px" }, noOptionsText = labels === null || labels === void 0 ? void 0 : labels.noOptions, loadingText = labels === null || labels === void 0 ? void 0 : labels.loading, getOptionLabel, getOptionDisabled, ...rest } = props;
|
|
18
18
|
// Value input ref
|
|
19
19
|
const inputRef = React.createRef();
|
|
20
20
|
// Local value
|
|
@@ -81,9 +81,12 @@ export function Tiplist(props) {
|
|
|
81
81
|
if (!states.loading)
|
|
82
82
|
stateUpdate({ loading: true });
|
|
83
83
|
// Load list
|
|
84
|
-
loadData(keyword, id).then((options) => {
|
|
84
|
+
loadData(keyword, id, maxItems).then((options) => {
|
|
85
85
|
if (!isMounted.current)
|
|
86
86
|
return;
|
|
87
|
+
if (options != null && options.length >= maxItems) {
|
|
88
|
+
options.push({ [idField]: "n/a" });
|
|
89
|
+
}
|
|
87
90
|
// Indicates loading completed
|
|
88
91
|
stateUpdate({
|
|
89
92
|
loading: false,
|
|
@@ -152,5 +155,20 @@ export function Tiplist(props) {
|
|
|
152
155
|
open: false,
|
|
153
156
|
...(!states.value && { options: [] })
|
|
154
157
|
});
|
|
155
|
-
}, loading: states.loading, sx: sx, renderInput: (params) => search ? (React.createElement(SearchField, { onChange: changeHandle, ...addReadOnly(params), readOnly: readOnly, label: label, name: name + "Input", margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })) : (React.createElement(InputField, { onChange: changeHandle, ...addReadOnly(params), label: label, name: name + "Input", margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })), isOptionEqualToValue: (option, value) => option[idField] === value[idField], noOptionsText: noOptionsText, loadingText: loadingText,
|
|
158
|
+
}, loading: states.loading, sx: sx, renderInput: (params) => search ? (React.createElement(SearchField, { onChange: changeHandle, ...addReadOnly(params), readOnly: readOnly, label: label, name: name + "Input", margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })) : (React.createElement(InputField, { onChange: changeHandle, ...addReadOnly(params), label: label, name: name + "Input", margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })), isOptionEqualToValue: (option, value) => option[idField] === value[idField], noOptionsText: noOptionsText, loadingText: loadingText, getOptionDisabled: (item) => {
|
|
159
|
+
if (item[idField] === "n/a")
|
|
160
|
+
return true;
|
|
161
|
+
return getOptionDisabled ? getOptionDisabled(item) : false;
|
|
162
|
+
}, getOptionLabel: (item) => {
|
|
163
|
+
var _a;
|
|
164
|
+
if (item[idField] === "n/a")
|
|
165
|
+
return ((_a = labels.more) !== null && _a !== void 0 ? _a : "More") + "...";
|
|
166
|
+
return getOptionLabel
|
|
167
|
+
? getOptionLabel(item)
|
|
168
|
+
: "label" in item
|
|
169
|
+
? `${item.label}`
|
|
170
|
+
: "name" in item
|
|
171
|
+
? `${item.name}`
|
|
172
|
+
: `${item}`;
|
|
173
|
+
}, ...rest })));
|
|
156
174
|
}
|
package/package.json
CHANGED
package/src/Tiplist.tsx
CHANGED
|
@@ -18,9 +18,15 @@ export type TiplistProps<T extends object, D extends DataTypes.Keys<T>> = Omit<
|
|
|
18
18
|
* Load data callback
|
|
19
19
|
*/
|
|
20
20
|
loadData: (
|
|
21
|
-
keyword
|
|
22
|
-
id
|
|
21
|
+
keyword: string | undefined,
|
|
22
|
+
id: T[D] | undefined,
|
|
23
|
+
maxItems: number
|
|
23
24
|
) => PromiseLike<T[] | null | undefined>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Max items to read and display
|
|
28
|
+
*/
|
|
29
|
+
maxItems?: number;
|
|
24
30
|
};
|
|
25
31
|
|
|
26
32
|
// Multiple states
|
|
@@ -41,7 +47,7 @@ export function Tiplist<
|
|
|
41
47
|
D extends DataTypes.Keys<T> = IdDefaultType<T>
|
|
42
48
|
>(props: TiplistProps<T, D>) {
|
|
43
49
|
// Labels
|
|
44
|
-
const labels = globalApp?.getLabels("noOptions", "loading");
|
|
50
|
+
const labels = globalApp?.getLabels("noOptions", "loading", "more");
|
|
45
51
|
|
|
46
52
|
// Destruct
|
|
47
53
|
const {
|
|
@@ -59,6 +65,7 @@ export function Tiplist<
|
|
|
59
65
|
loadData,
|
|
60
66
|
defaultValue,
|
|
61
67
|
value,
|
|
68
|
+
maxItems = 16,
|
|
62
69
|
name,
|
|
63
70
|
readOnly,
|
|
64
71
|
onChange,
|
|
@@ -66,6 +73,8 @@ export function Tiplist<
|
|
|
66
73
|
sx = { minWidth: "180px" },
|
|
67
74
|
noOptionsText = labels?.noOptions,
|
|
68
75
|
loadingText = labels?.loading,
|
|
76
|
+
getOptionLabel,
|
|
77
|
+
getOptionDisabled,
|
|
69
78
|
...rest
|
|
70
79
|
} = props;
|
|
71
80
|
|
|
@@ -161,9 +170,13 @@ export function Tiplist<
|
|
|
161
170
|
if (!states.loading) stateUpdate({ loading: true });
|
|
162
171
|
|
|
163
172
|
// Load list
|
|
164
|
-
loadData(keyword, id).then((options) => {
|
|
173
|
+
loadData(keyword, id, maxItems).then((options) => {
|
|
165
174
|
if (!isMounted.current) return;
|
|
166
175
|
|
|
176
|
+
if (options != null && options.length >= maxItems) {
|
|
177
|
+
options.push({ [idField]: "n/a" } as T);
|
|
178
|
+
}
|
|
179
|
+
|
|
167
180
|
// Indicates loading completed
|
|
168
181
|
stateUpdate({
|
|
169
182
|
loading: false,
|
|
@@ -299,6 +312,20 @@ export function Tiplist<
|
|
|
299
312
|
}
|
|
300
313
|
noOptionsText={noOptionsText}
|
|
301
314
|
loadingText={loadingText}
|
|
315
|
+
getOptionDisabled={(item) => {
|
|
316
|
+
if (item[idField] === "n/a") return true;
|
|
317
|
+
return getOptionDisabled ? getOptionDisabled(item) : false;
|
|
318
|
+
}}
|
|
319
|
+
getOptionLabel={(item) => {
|
|
320
|
+
if (item[idField] === "n/a") return (labels.more ?? "More") + "...";
|
|
321
|
+
return getOptionLabel
|
|
322
|
+
? getOptionLabel(item)
|
|
323
|
+
: "label" in item
|
|
324
|
+
? `${item.label}`
|
|
325
|
+
: "name" in item
|
|
326
|
+
? `${item.name}`
|
|
327
|
+
: `${item}`;
|
|
328
|
+
}}
|
|
302
329
|
{...rest}
|
|
303
330
|
/>
|
|
304
331
|
</div>
|