@etsoo/materialui 1.1.27 → 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 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?: string, id?: T[D]) => PromiseLike<T[] | null | undefined>;
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, ...rest })));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.1.27",
3
+ "version": "1.1.29",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,9 +50,9 @@
50
50
  "@emotion/css": "^11.10.5",
51
51
  "@emotion/react": "^11.10.5",
52
52
  "@emotion/styled": "^11.10.5",
53
- "@etsoo/appscript": "^1.3.61",
53
+ "@etsoo/appscript": "^1.3.62",
54
54
  "@etsoo/notificationbase": "^1.1.23",
55
- "@etsoo/react": "^1.6.45",
55
+ "@etsoo/react": "^1.6.46",
56
56
  "@etsoo/shared": "^1.1.88",
57
57
  "@mui/icons-material": "^5.11.0",
58
58
  "@mui/material": "^5.11.7",
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?: string,
22
- id?: T[D]
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>