@scheels-softdev/kendoreact-generics 2.4.2 → 2.4.3
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/GenericDropdown.d.ts +4 -2
- package/GenericDropdown.js +17 -27
- package/package.json +1 -1
package/GenericDropdown.d.ts
CHANGED
@@ -5,7 +5,7 @@ import { CSSProperties } from "react";
|
|
5
5
|
* @param {object} props - The component props.
|
6
6
|
* @returns {JSX.Element}
|
7
7
|
*/
|
8
|
-
|
8
|
+
type GenericDDProps<T> = {
|
9
9
|
data: T[];
|
10
10
|
/** The ID of the currently selected item. (optional)*/
|
11
11
|
selectedId?: number;
|
@@ -27,4 +27,6 @@ export declare function GenericDropdown<T>({ data, selectedId, selectedData, onC
|
|
27
27
|
hideClearButton?: boolean;
|
28
28
|
/** Custom CSS properties for the component. (optional)*/
|
29
29
|
style?: CSSProperties;
|
30
|
-
}
|
30
|
+
};
|
31
|
+
export declare function GenericDropdown<T>({ data, selectedId, selectedData, onChange, textFields, separator, disabled, idField, title, hideClearButton, style, }: GenericDDProps<T>): import("react/jsx-runtime").JSX.Element;
|
32
|
+
export {};
|
package/GenericDropdown.js
CHANGED
@@ -4,27 +4,13 @@ import { filterBy } from "@progress/kendo-data-query";
|
|
4
4
|
import { useEffect, useRef, useState } from "react";
|
5
5
|
import { getTextValue } from "./Utility";
|
6
6
|
import { Skeleton } from "@progress/kendo-react-indicators";
|
7
|
-
//TODO add a style property
|
8
|
-
//TODO add metadata documentation
|
9
|
-
// component that renders a dropdown with a search filter
|
10
|
-
/**
|
11
|
-
* JSX Component for displaying items in a virtualized combobox
|
12
|
-
* @template T - The type of the data objects in the dropdown.
|
13
|
-
* @param {object} props - The component props.
|
14
|
-
* @returns {JSX.Element}
|
15
|
-
*/
|
16
7
|
export function GenericDropdown({ data, selectedId, selectedData, onChange, textFields, separator, disabled, idField, title, hideClearButton, style, }) {
|
17
8
|
if (selectedId !== undefined && selectedData !== undefined) {
|
18
9
|
throw new Error("You cannot provide both selectedData and selectedId to GenericDropdown.");
|
19
10
|
}
|
20
|
-
useEffect(() => {
|
21
|
-
console.log(selectedId);
|
22
|
-
}, [selectedId]);
|
23
11
|
//local state
|
24
12
|
const pageSize = 8;
|
25
|
-
const [dataList, setDataList] = useState(
|
26
|
-
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
27
|
-
}));
|
13
|
+
const [dataList, setDataList] = useState([]);
|
28
14
|
const [state, setState] = useState({
|
29
15
|
skip: 0,
|
30
16
|
total: dataList.length,
|
@@ -56,9 +42,14 @@ export function GenericDropdown({ data, selectedId, selectedData, onChange, text
|
|
56
42
|
};
|
57
43
|
//change event listeners
|
58
44
|
useEffect(() => {
|
59
|
-
|
60
|
-
|
61
|
-
|
45
|
+
if (data.length) {
|
46
|
+
setDataList(data.map((x) => {
|
47
|
+
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
48
|
+
}));
|
49
|
+
setState(Object.assign(Object.assign({}, state), { subsetData: data.map((x) => {
|
50
|
+
return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
|
51
|
+
}) }));
|
52
|
+
}
|
62
53
|
}, [data, textFields, separator]);
|
63
54
|
const findByIndex = (id, idKey) => {
|
64
55
|
console.log(id, data, idField);
|
@@ -72,13 +63,12 @@ export function GenericDropdown({ data, selectedId, selectedData, onChange, text
|
|
72
63
|
console.log(returnVal);
|
73
64
|
return returnVal;
|
74
65
|
};
|
75
|
-
return (_jsx("div", Object.assign({ "data-testid": "dropdown" }, { children:
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}, onChange: (e) => onChange(e), onBlur: (e) => e.nativeEvent.preventDefault(), clearButton: !hideClearButton, value: !selectedId && !selectedData ? null : findByIndex(selectedId, idField) || findByValue(selectedData) || null }) : _jsx(Skeleton, { shape: "rectangle", style: style ? style : { height: "40px", width: "100%" } }) })));
|
66
|
+
return (_jsx("div", Object.assign({ "data-testid": "dropdown" }, { children: dataList.length ? (_jsx(ComboBox, { style: style, label: title, disabled: disabled, data: state.subsetData, textField: "textValue", virtual: {
|
67
|
+
// enable virtualization for large datasets
|
68
|
+
total: state.total,
|
69
|
+
pageSize: pageSize,
|
70
|
+
skip: state.skip,
|
71
|
+
}, suggest: true, onPageChange: pageChange, filterable: true, onFilterChange: onFilterChange, popupSettings: {
|
72
|
+
height: "210px",
|
73
|
+
}, onChange: (e) => onChange(e), onBlur: (e) => e.nativeEvent.preventDefault(), clearButton: !hideClearButton, value: !selectedId && !selectedData ? null : findByIndex(selectedId, idField) || findByValue(selectedData) || null })) : (_jsx(Skeleton, { shape: "rectangle", style: style ? style : { height: "40px", width: "100%" } })) })));
|
84
74
|
}
|