@via-profit/ui-kit 0.1.0-rc.51 → 0.1.0-rc.52
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.
|
@@ -3,7 +3,9 @@ import { Value, OnRequestClose, GetOptionSelected } from '../Menu';
|
|
|
3
3
|
import { TextFieldProps } from '../TextField';
|
|
4
4
|
import type { AnchorPos } from '../Popper';
|
|
5
5
|
import type { MenuItemCommonProps } from '../Menu/MenuItem';
|
|
6
|
-
|
|
6
|
+
type NativeInputProps = React.InputHTMLAttributes<HTMLInputElement>;
|
|
7
|
+
type AutocompleteInputProps = Omit<NativeInputProps, 'onChange' | 'value' | 'children'>;
|
|
8
|
+
export interface AutocompleteProps<T, Multiple extends boolean | undefined = undefined> extends AutocompleteInputProps {
|
|
7
9
|
readonly items: readonly T[];
|
|
8
10
|
readonly value: Value<T, Multiple>;
|
|
9
11
|
/**
|
|
@@ -22,6 +22,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
25
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
38
|
};
|
|
@@ -34,7 +45,7 @@ const Spinner_1 = __importDefault(require("../LoadingIndicator/Spinner"));
|
|
|
34
45
|
const IconClear_1 = __importDefault(require("./IconClear"));
|
|
35
46
|
const context_1 = __importStar(require("./context"));
|
|
36
47
|
const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
37
|
-
const { items, value, multiple, isOpen = false, isLoading = false, clearIfNotSelected = true, anchorPos = 'auto-start-end', requiredAsterisk, startIcon, fullWidth, placeholder, label, error, errorText, inputRef, filterItems, children, onChange, selectedItemToString, onInputChange, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined
|
|
48
|
+
const { items, value, multiple, isOpen = false, isLoading = false, clearIfNotSelected = true, anchorPos = 'auto-start-end', requiredAsterisk, startIcon, fullWidth, placeholder, label, error, errorText, inputRef, filterItems, children, onChange, selectedItemToString, onInputChange, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined } = props, nativeInputProps = __rest(props, ["items", "value", "multiple", "isOpen", "isLoading", "clearIfNotSelected", "anchorPos", "requiredAsterisk", "startIcon", "fullWidth", "placeholder", "label", "error", "errorText", "inputRef", "filterItems", "children", "onChange", "selectedItemToString", "onInputChange", "getOptionSelected", "onRequestOpen", "onRequestClose"]);
|
|
38
49
|
const menuRef = react_1.default.useRef(null);
|
|
39
50
|
const fieldInputRef = react_1.default.useRef(null);
|
|
40
51
|
const isFocusedRef = react_1.default.useRef(false);
|
|
@@ -144,7 +155,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
144
155
|
dispatch((0, context_1.actionSetPartial)({ currentOpen: isOpen, currentLoading: isLoading, filteredItems: items }));
|
|
145
156
|
}, [isOpen, isLoading, items, dispatch]);
|
|
146
157
|
return (react_1.default.createElement("div", null,
|
|
147
|
-
react_1.default.useMemo(() => (react_1.default.createElement(TextField_1.default, { placeholder: placeholder, label: label, error: error, requiredAsterisk: requiredAsterisk, errorText: errorText, fullWidth: fullWidth, startIcon: startIcon, endIcon: react_1.default.createElement(Button_1.default, { iconOnly: true, type: "button", onClick: () => (currentLoading ? 'undefined' : clear()) }, currentLoading ? react_1.default.createElement(Spinner_1.default, null) : react_1.default.createElement(IconClear_1.default, null)), onKeyDown: inputKeydownEvent, ref: el => {
|
|
158
|
+
react_1.default.useMemo(() => (react_1.default.createElement(TextField_1.default, Object.assign({}, nativeInputProps, { placeholder: placeholder, label: label, error: error, requiredAsterisk: requiredAsterisk, errorText: errorText, fullWidth: fullWidth, startIcon: startIcon, endIcon: react_1.default.createElement(Button_1.default, { iconOnly: true, type: "button", onClick: () => (currentLoading ? 'undefined' : clear()) }, currentLoading ? react_1.default.createElement(Spinner_1.default, null) : react_1.default.createElement(IconClear_1.default, null)), onKeyDown: inputKeydownEvent, ref: el => {
|
|
148
159
|
if (anchorElement !== el) {
|
|
149
160
|
dispatch((0, context_1.actionSetPartial)({ anchorElement: el }));
|
|
150
161
|
}
|
|
@@ -187,7 +198,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
187
198
|
dispatch((0, context_1.actionSetPartial)({
|
|
188
199
|
filteredItems: newItems,
|
|
189
200
|
}));
|
|
190
|
-
} })), [
|
|
201
|
+
} }))), [
|
|
191
202
|
placeholder,
|
|
192
203
|
label,
|
|
193
204
|
error,
|
|
@@ -204,6 +215,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
204
215
|
inputRef,
|
|
205
216
|
clearIfNotSelected,
|
|
206
217
|
multiple,
|
|
218
|
+
nativeInputProps,
|
|
207
219
|
value,
|
|
208
220
|
selectedItemToString,
|
|
209
221
|
onRequestOpen,
|