@via-profit/ui-kit 0.2.1-alpha.3 → 0.2.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/Autocomplete/AutocompleteContainer.d.ts +5 -4
- package/Autocomplete/AutocompleteContainer.js +146 -152
- package/Autocomplete/AutocompleteItem.js +1 -1
- package/Autocomplete/context.d.ts +3 -5
- package/Autocomplete/context.js +22 -14
- package/CountryFlags/SwiperOverview.d.ts +257 -0
- package/CountryFlags/SwiperOverview.js +524 -0
- package/Highlighted/index.js +10 -5
- package/Highlighted/splitTextIntoParts.d.ts +5 -0
- package/Highlighted/splitTextIntoParts.js +46 -0
- package/MaskedField/index.d.ts +1 -0
- package/MaskedField/index.js +44 -36
- package/MaskedField/useMasked.js +7 -5
- package/Menu/MenuContainer.d.ts +24 -2
- package/Menu/MenuContainer.js +194 -243
- package/Menu/MenuList.d.ts +1 -0
- package/Menu/MenuList.js +15 -16
- package/Popper/Popper.d.ts +3 -2
- package/Popper/Popper.js +9 -7
- package/Popper/PopperContainer.d.ts +0 -1
- package/Popper/PopperContainer.js +8 -3
- package/Popper/index.d.ts +1 -1
- package/Popper/index.js +1 -1
- package/Popper/usePopper.d.ts +111 -0
- package/Popper/usePopper.js +522 -0
- package/Selectbox/SelectboxButton.js +2 -27
- package/Selectbox/SelectboxMenu.d.ts +0 -2
- package/Selectbox/SelectboxMenu.js +13 -5
- package/Selectbox/index.d.ts +5 -3
- package/Selectbox/index.js +4 -4
- package/Swiper/Swiper.d.ts +28 -17
- package/Swiper/Swiper.js +294 -38
- package/Swiper/SwiperContainer.d.ts +3 -3
- package/Swiper/SwiperContainer.js +1 -0
- package/Swiper/SwiperSlide.d.ts +10 -5
- package/Swiper/SwiperSlide.js +6 -3
- package/Swiper/SwiperSlidesRenderer.d.ts +11 -0
- package/Swiper/SwiperSlidesRenderer.js +74 -0
- package/Swiper/SwiperTrack.d.ts +4 -0
- package/Swiper/SwiperTrack.js +4 -7
- package/Swiper/SwiperWrapper.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { TextFieldProps } from '../TextField';
|
|
3
3
|
import { PositionStrategy } from '../Popper';
|
|
4
4
|
import { AnchorPos, GetOptionSelected, MenuItemProps, OnRequestClose, Value } from '../Menu';
|
|
5
|
-
export interface AutocompleteProps<T, Multiple extends boolean | undefined = undefined> extends Omit<
|
|
5
|
+
export interface AutocompleteProps<T, Multiple extends boolean | undefined = undefined> extends Omit<TextFieldProps, 'value' | 'onChange' | 'children' | 'overrides'> {
|
|
6
6
|
readonly items: readonly T[];
|
|
7
7
|
readonly value: Value<T, Multiple>;
|
|
8
8
|
/**
|
|
@@ -21,7 +21,7 @@ export interface AutocompleteProps<T, Multiple extends boolean | undefined = und
|
|
|
21
21
|
/**
|
|
22
22
|
* Anchor position\
|
|
23
23
|
* \
|
|
24
|
-
* Default: `bottom
|
|
24
|
+
* Default: `bottom`
|
|
25
25
|
*/
|
|
26
26
|
readonly anchorPos?: AnchorPos;
|
|
27
27
|
/**
|
|
@@ -43,6 +43,7 @@ export interface AutocompleteProps<T, Multiple extends boolean | undefined = und
|
|
|
43
43
|
* ```
|
|
44
44
|
*/
|
|
45
45
|
readonly positionStrategy?: PositionStrategy;
|
|
46
|
+
readonly alternativePlacements?: readonly AnchorPos[];
|
|
46
47
|
/**
|
|
47
48
|
* Minimum distance (in pixels) that the popper must maintain from the viewport edges.
|
|
48
49
|
* Used to prevent the popper from being positioned too close to the screen boundaries.
|
|
@@ -137,7 +138,7 @@ export interface AutocompleteOverrides {
|
|
|
137
138
|
/**
|
|
138
139
|
* Element wrapper
|
|
139
140
|
*/
|
|
140
|
-
readonly TextField?: React.ComponentType<
|
|
141
|
+
readonly TextField?: React.ComponentType<TextFieldProps & React.RefAttributes<HTMLDivElement>>;
|
|
141
142
|
}
|
|
142
143
|
export type Children<T> = (data: {
|
|
143
144
|
item: T;
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
3
|
var t = {};
|
|
27
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -38,26 +15,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
15
|
};
|
|
39
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
17
|
const react_1 = __importDefault(require("react"));
|
|
41
|
-
const
|
|
18
|
+
const TextField_1 = __importDefault(require("../TextField"));
|
|
42
19
|
const Button_1 = __importDefault(require("../Button"));
|
|
43
|
-
const
|
|
44
|
-
const context_1 =
|
|
20
|
+
const LoadingIndicator_1 = require("../LoadingIndicator");
|
|
21
|
+
const context_1 = require("./context");
|
|
45
22
|
const IconClear_1 = __importDefault(require("./IconClear"));
|
|
46
23
|
const ClickOutside_1 = require("../ClickOutside");
|
|
47
|
-
const OverrideMenuList_1 = __importDefault(require("./OverrideMenuList"));
|
|
48
24
|
const Menu_1 = __importDefault(require("../Menu"));
|
|
49
|
-
//
|
|
50
25
|
const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
51
|
-
const { items, value, multiple, isOpen = false, isLoading = false, clearOnBlur = true, anchorPos = 'bottom-fill', openOnFocus = true, autoFlip, viewportMargin, positionStrategy, requiredAsterisk, startIcon, fullWidth, placeholder, label, error, errorText, inputRef, filterItems, children, onChange, selectedItemToString, clearable = true, onInputChange, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined, overrides } = props, nativeInputProps = __rest(props, ["items", "value", "multiple", "isOpen", "isLoading", "clearOnBlur", "anchorPos", "openOnFocus", "autoFlip", "viewportMargin", "positionStrategy", "requiredAsterisk", "startIcon", "fullWidth", "placeholder", "label", "error", "errorText", "inputRef", "filterItems", "children", "onChange", "selectedItemToString", "clearable", "onInputChange", "getOptionSelected", "onRequestOpen", "onRequestClose", "overrides"]);
|
|
52
|
-
const [actualPlacement, setActualPlacement] = react_1.default.useState(anchorPos);
|
|
26
|
+
const { items, value, multiple, isOpen = false, isLoading = false, clearOnBlur = true, anchorPos = 'bottom-fill', alternativePlacements = ['bottom-fill', 'top-fill'], openOnFocus = true, autoFlip = true, viewportMargin, positionStrategy, requiredAsterisk, startIcon, fullWidth, placeholder, label, error, errorText, inputRef, filterItems, children, onChange, selectedItemToString, clearable = true, onInputChange, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined, overrides } = props, nativeInputProps = __rest(props, ["items", "value", "multiple", "isOpen", "isLoading", "clearOnBlur", "anchorPos", "alternativePlacements", "openOnFocus", "autoFlip", "viewportMargin", "positionStrategy", "requiredAsterisk", "startIcon", "fullWidth", "placeholder", "label", "error", "errorText", "inputRef", "filterItems", "children", "onChange", "selectedItemToString", "clearable", "onInputChange", "getOptionSelected", "onRequestOpen", "onRequestClose", "overrides"]);
|
|
53
27
|
const menuRef = react_1.default.useRef(null);
|
|
54
28
|
const fieldInputRef = react_1.default.useRef(null);
|
|
55
29
|
const isFocusedRef = react_1.default.useRef(false);
|
|
56
30
|
const itemsRef = react_1.default.useRef(items);
|
|
57
|
-
const {
|
|
58
|
-
const
|
|
31
|
+
const { currentOpen, filteredItems, inputValue, currentValue, anchorElement, currentLoading } = (0, context_1.useContextState)();
|
|
32
|
+
const dispatch = (0, context_1.useContextDispatch)();
|
|
59
33
|
const overridesMap = react_1.default.useMemo(() => ({
|
|
60
|
-
TextField: (overrides === null || overrides === void 0 ? void 0 : overrides.TextField) ||
|
|
34
|
+
TextField: (overrides === null || overrides === void 0 ? void 0 : overrides.TextField) || TextField_1.default,
|
|
61
35
|
}), [overrides]);
|
|
62
36
|
const clear = react_1.default.useCallback(() => {
|
|
63
37
|
if (onChange) {
|
|
@@ -142,6 +116,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
142
116
|
? itemList
|
|
143
117
|
: filterItems(itemList, { query, inputValue });
|
|
144
118
|
}, [filterItems]);
|
|
119
|
+
const renderChildren = react_1.default.useCallback(({ index, item }, itemProps) => children({ index, item: item, inputValue }, itemProps), [children, inputValue]);
|
|
145
120
|
/**
|
|
146
121
|
* Only affected value change action
|
|
147
122
|
*/
|
|
@@ -168,20 +143,26 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
168
143
|
}
|
|
169
144
|
}, [filteredItems]);
|
|
170
145
|
react_1.default.useEffect(() => {
|
|
171
|
-
if (currentOpen !== isOpen
|
|
172
|
-
dispatch((0, context_1.actionSetPartial)({ currentOpen: isOpen
|
|
146
|
+
if (currentOpen !== isOpen) {
|
|
147
|
+
dispatch((0, context_1.actionSetPartial)({ currentOpen: isOpen }));
|
|
173
148
|
}
|
|
174
|
-
}, [isOpen,
|
|
149
|
+
}, [isOpen, currentOpen, dispatch]);
|
|
175
150
|
react_1.default.useEffect(() => {
|
|
176
|
-
if (
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
151
|
+
if (currentLoading !== isLoading) {
|
|
152
|
+
dispatch((0, context_1.actionSetPartial)({ currentLoading: isLoading }));
|
|
153
|
+
}
|
|
154
|
+
}, [isLoading, currentLoading, dispatch]);
|
|
155
|
+
react_1.default.useEffect(() => {
|
|
156
|
+
if (itemsRef.current === items) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
itemsRef.current = items;
|
|
160
|
+
const newFilteredItems = applyFilterForItems(inputValue, items);
|
|
161
|
+
dispatch((0, context_1.actionSetPartial)({ filteredItems: newFilteredItems }));
|
|
162
|
+
if (!newFilteredItems.length && currentOpen) {
|
|
163
|
+
onRequestClose();
|
|
183
164
|
}
|
|
184
|
-
}, [items, inputValue, applyFilterForItems, dispatch, onRequestClose]);
|
|
165
|
+
}, [items, inputValue, applyFilterForItems, dispatch, onRequestClose, currentOpen]);
|
|
185
166
|
react_1.default.useEffect(() => {
|
|
186
167
|
const mouseDownEvent = (event) => {
|
|
187
168
|
var _a;
|
|
@@ -233,119 +214,137 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
233
214
|
inputValue,
|
|
234
215
|
multiple,
|
|
235
216
|
]);
|
|
217
|
+
const onSelectMenuItem = react_1.default.useCallback(item => {
|
|
218
|
+
if (!multiple) {
|
|
219
|
+
dispatch({
|
|
220
|
+
type: 'setPartial',
|
|
221
|
+
payload: {
|
|
222
|
+
filteredItems: applyFilterForItems(selectedItemToString(item), items),
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
if (typeof onChange === 'function') {
|
|
227
|
+
onChange(item);
|
|
228
|
+
}
|
|
229
|
+
}, [applyFilterForItems, dispatch, items, multiple, onChange, selectedItemToString]);
|
|
230
|
+
const endIconMemo = react_1.default.useMemo(() => {
|
|
231
|
+
if (currentLoading) {
|
|
232
|
+
return (react_1.default.createElement(Button_1.default, { iconOnly: true, type: "button", variant: "plain", disabled: true },
|
|
233
|
+
react_1.default.createElement(LoadingIndicator_1.StaticLoadingIndicator, null)));
|
|
234
|
+
}
|
|
235
|
+
if (!clearable) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
return (react_1.default.createElement(Button_1.default, { iconOnly: true, type: "button", variant: "plain", onClick: clear, "aria-label": "Clear" },
|
|
239
|
+
react_1.default.createElement(IconClear_1.default, null)));
|
|
240
|
+
}, [clear, clearable, currentLoading]);
|
|
241
|
+
const textFieldOnKeyDown = react_1.default.useCallback(event => {
|
|
242
|
+
inputKeydownEvent(event);
|
|
243
|
+
if (typeof nativeInputProps.onKeyDown === 'function') {
|
|
244
|
+
nativeInputProps.onKeyDown(event);
|
|
245
|
+
}
|
|
246
|
+
}, [inputKeydownEvent, nativeInputProps]);
|
|
247
|
+
const textFieldOnChange = react_1.default.useCallback(event => {
|
|
248
|
+
if (typeof onInputChange === 'function') {
|
|
249
|
+
onInputChange(event);
|
|
250
|
+
}
|
|
251
|
+
// If openOnFocus is false, but value is not empty
|
|
252
|
+
// we should open menu list if is not opened
|
|
253
|
+
if (!openOnFocus && isFocusedRef.current && !currentOpen && filteredItems.length > 0) {
|
|
254
|
+
onRequestOpen(event);
|
|
255
|
+
}
|
|
256
|
+
const newFilteredItems = applyFilterForItems(event.currentTarget.value, items);
|
|
257
|
+
if (newFilteredItems.length === 0 && currentOpen) {
|
|
258
|
+
onRequestClose();
|
|
259
|
+
}
|
|
260
|
+
if (newFilteredItems.length > 0 && !currentOpen) {
|
|
261
|
+
onRequestOpen(event);
|
|
262
|
+
}
|
|
263
|
+
dispatch((0, context_1.actionSetPartial)({
|
|
264
|
+
filteredItems: newFilteredItems,
|
|
265
|
+
inputValue: event.currentTarget.value,
|
|
266
|
+
}));
|
|
267
|
+
}, [
|
|
268
|
+
applyFilterForItems,
|
|
269
|
+
currentOpen,
|
|
270
|
+
dispatch,
|
|
271
|
+
filteredItems.length,
|
|
272
|
+
items,
|
|
273
|
+
onInputChange,
|
|
274
|
+
onRequestClose,
|
|
275
|
+
onRequestOpen,
|
|
276
|
+
openOnFocus,
|
|
277
|
+
]);
|
|
278
|
+
const textFieldClick = react_1.default.useCallback(event => {
|
|
279
|
+
if (typeof nativeInputProps.onClick === 'function') {
|
|
280
|
+
nativeInputProps.onClick(event);
|
|
281
|
+
}
|
|
282
|
+
if (isFocusedRef.current &&
|
|
283
|
+
!currentOpen &&
|
|
284
|
+
filteredItems.length > 0
|
|
285
|
+
// && inputValue.trim() !== ''
|
|
286
|
+
) {
|
|
287
|
+
onRequestOpen(event);
|
|
288
|
+
}
|
|
289
|
+
}, [currentOpen, filteredItems.length, nativeInputProps, onRequestOpen]);
|
|
290
|
+
const textFieldFocus = react_1.default.useCallback(event => {
|
|
291
|
+
isFocusedRef.current = true;
|
|
292
|
+
if (openOnFocus && !currentOpen && filteredItems.length > 0) {
|
|
293
|
+
onRequestOpen(event);
|
|
294
|
+
}
|
|
295
|
+
if (typeof nativeInputProps.onFocus === 'function') {
|
|
296
|
+
nativeInputProps.onFocus(event);
|
|
297
|
+
}
|
|
298
|
+
}, [currentOpen, filteredItems.length, nativeInputProps, onRequestOpen, openOnFocus]);
|
|
299
|
+
const textFieldBlur = react_1.default.useCallback(event => {
|
|
300
|
+
isFocusedRef.current = false;
|
|
301
|
+
if (typeof nativeInputProps.onBlur === 'function') {
|
|
302
|
+
nativeInputProps.onBlur(event);
|
|
303
|
+
}
|
|
304
|
+
}, [nativeInputProps]);
|
|
305
|
+
const setAnchorElementRef = react_1.default.useCallback((el) => {
|
|
306
|
+
if (anchorElement !== el) {
|
|
307
|
+
dispatch((0, context_1.actionSetPartial)({ anchorElement: el }));
|
|
308
|
+
}
|
|
309
|
+
}, [anchorElement, dispatch]);
|
|
310
|
+
const inputRefRef = react_1.default.useRef(inputRef);
|
|
311
|
+
react_1.default.useEffect(() => {
|
|
312
|
+
inputRefRef.current = inputRef;
|
|
313
|
+
}, [inputRef]);
|
|
314
|
+
const setInputElementRef = react_1.default.useCallback((el) => {
|
|
315
|
+
fieldInputRef.current = el;
|
|
316
|
+
const currentInputRef = inputRefRef.current;
|
|
317
|
+
if (typeof currentInputRef === 'function') {
|
|
318
|
+
currentInputRef(el);
|
|
319
|
+
}
|
|
320
|
+
else if (currentInputRef && typeof currentInputRef === 'object') {
|
|
321
|
+
currentInputRef.current = el;
|
|
322
|
+
}
|
|
323
|
+
}, []);
|
|
236
324
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
237
|
-
react_1.default.useMemo(() => (react_1.default.createElement(overridesMap.TextField, Object.assign({ placeholder: placeholder,
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
nativeInputProps.onKeyDown(event);
|
|
241
|
-
}
|
|
242
|
-
}, ref: el => {
|
|
243
|
-
if (anchorElement !== el) {
|
|
244
|
-
dispatch((0, context_1.actionSetPartial)({ anchorElement: el }));
|
|
245
|
-
}
|
|
246
|
-
}, inputRef: el => {
|
|
247
|
-
fieldInputRef.current = el;
|
|
248
|
-
if (typeof inputRef === 'function') {
|
|
249
|
-
inputRef(el);
|
|
250
|
-
}
|
|
251
|
-
if (inputRef && typeof inputRef === 'object') {
|
|
252
|
-
inputRef.current = el;
|
|
253
|
-
}
|
|
254
|
-
}, value: inputValue, onBlur: event => {
|
|
255
|
-
isFocusedRef.current = false;
|
|
256
|
-
if (typeof nativeInputProps.onBlur === 'function') {
|
|
257
|
-
nativeInputProps.onBlur(event);
|
|
258
|
-
}
|
|
259
|
-
}, onFocus: event => {
|
|
260
|
-
isFocusedRef.current = true;
|
|
261
|
-
if (openOnFocus && !currentOpen && filteredItems.length > 0) {
|
|
262
|
-
onRequestOpen(event);
|
|
263
|
-
}
|
|
264
|
-
// if (!openOnFocus && !currentOpen && inputValue !== '' && filteredItems.length > 0) {
|
|
265
|
-
// onRequestOpen(event);
|
|
266
|
-
// }
|
|
267
|
-
if (typeof nativeInputProps.onFocus === 'function') {
|
|
268
|
-
nativeInputProps.onFocus(event);
|
|
269
|
-
}
|
|
270
|
-
}, onClick: event => {
|
|
271
|
-
if (typeof nativeInputProps.onClick === 'function') {
|
|
272
|
-
nativeInputProps.onClick(event);
|
|
273
|
-
}
|
|
274
|
-
if (isFocusedRef.current &&
|
|
275
|
-
!currentOpen &&
|
|
276
|
-
filteredItems.length > 0
|
|
277
|
-
// && inputValue.trim() !== ''
|
|
278
|
-
) {
|
|
279
|
-
onRequestOpen(event);
|
|
280
|
-
}
|
|
281
|
-
}, onChange: event => {
|
|
282
|
-
if (typeof onInputChange === 'function') {
|
|
283
|
-
onInputChange(event);
|
|
284
|
-
}
|
|
285
|
-
// If openOnFocus is false, but value is not empty
|
|
286
|
-
// we should open menu list if is not opened
|
|
287
|
-
if (!openOnFocus &&
|
|
288
|
-
isFocusedRef.current &&
|
|
289
|
-
!currentOpen &&
|
|
290
|
-
filteredItems.length > 0) {
|
|
291
|
-
onRequestOpen(event);
|
|
292
|
-
}
|
|
293
|
-
// console.debug('set filteredItems');
|
|
294
|
-
const newFilteredItems = applyFilterForItems(event.currentTarget.value, items);
|
|
295
|
-
if (newFilteredItems.length === 0 && currentOpen) {
|
|
296
|
-
onRequestClose();
|
|
297
|
-
}
|
|
298
|
-
if (newFilteredItems.length > 0 && !currentOpen) {
|
|
299
|
-
onRequestOpen(event);
|
|
300
|
-
}
|
|
301
|
-
dispatch((0, context_1.actionSetPartial)({
|
|
302
|
-
filteredItems: newFilteredItems,
|
|
303
|
-
inputValue: event.currentTarget.value,
|
|
304
|
-
}));
|
|
305
|
-
} }))), [
|
|
325
|
+
react_1.default.useMemo(() => (react_1.default.createElement(overridesMap.TextField, Object.assign({ placeholder: placeholder, label: label, error: error, requiredAsterisk: requiredAsterisk, errorText: errorText, fullWidth: fullWidth, startIcon: startIcon, endIcon: endIconMemo }, nativeInputProps, { onKeyDown: textFieldOnKeyDown, ref: setAnchorElementRef, inputRef: setInputElementRef, value: inputValue, onBlur: textFieldBlur, onFocus: textFieldFocus, onClick: textFieldClick, onChange: textFieldOnChange }))), [
|
|
326
|
+
setAnchorElementRef,
|
|
327
|
+
setInputElementRef,
|
|
306
328
|
overridesMap,
|
|
307
329
|
placeholder,
|
|
308
|
-
actualPlacement,
|
|
309
|
-
currentOpen,
|
|
310
330
|
label,
|
|
311
331
|
error,
|
|
312
332
|
requiredAsterisk,
|
|
313
333
|
errorText,
|
|
314
334
|
fullWidth,
|
|
315
335
|
startIcon,
|
|
316
|
-
|
|
317
|
-
clearable,
|
|
336
|
+
endIconMemo,
|
|
318
337
|
nativeInputProps,
|
|
338
|
+
textFieldOnKeyDown,
|
|
319
339
|
inputValue,
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
inputRef,
|
|
325
|
-
openOnFocus,
|
|
326
|
-
filteredItems.length,
|
|
327
|
-
onRequestOpen,
|
|
328
|
-
onInputChange,
|
|
329
|
-
applyFilterForItems,
|
|
330
|
-
items,
|
|
331
|
-
onRequestClose,
|
|
340
|
+
textFieldBlur,
|
|
341
|
+
textFieldFocus,
|
|
342
|
+
textFieldClick,
|
|
343
|
+
textFieldOnChange,
|
|
332
344
|
]),
|
|
333
|
-
react_1.default.useMemo(() => (react_1.default.createElement(Menu_1.default, { ref: menuRef,
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (!multiple) {
|
|
337
|
-
dispatch({
|
|
338
|
-
type: 'setPartial',
|
|
339
|
-
payload: {
|
|
340
|
-
filteredItems: applyFilterForItems(selectedItemToString(item), items),
|
|
341
|
-
},
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
if (typeof onChange === 'function') {
|
|
345
|
-
onChange(item);
|
|
346
|
-
}
|
|
347
|
-
} }, ({ index, item }, itemProps) => children({ index, item: item, inputValue }, itemProps))), [
|
|
348
|
-
actualPlacement,
|
|
345
|
+
react_1.default.useMemo(() => (react_1.default.createElement(Menu_1.default, { ref: menuRef, anchorPos: anchorPos, alternativePlacements: alternativePlacements, multiple: multiple, items: filteredItems, value: currentValue, isOpen: currentOpen, autofocus: false, autoFlip: autoFlip, viewportMargin: viewportMargin, offset: 0, positionStrategy: positionStrategy, anchorElement: anchorElement, closeOutsideClick: false, getOptionSelected: getOptionSelected, onRequestClose: onRequestClose, closeOnSelect: !multiple, onSelectItem: onSelectMenuItem }, renderChildren)), [
|
|
346
|
+
anchorPos,
|
|
347
|
+
alternativePlacements,
|
|
349
348
|
multiple,
|
|
350
349
|
filteredItems,
|
|
351
350
|
currentValue,
|
|
@@ -356,13 +355,8 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
356
355
|
anchorElement,
|
|
357
356
|
getOptionSelected,
|
|
358
357
|
onRequestClose,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
applyFilterForItems,
|
|
362
|
-
selectedItemToString,
|
|
363
|
-
items,
|
|
364
|
-
children,
|
|
365
|
-
inputValue,
|
|
358
|
+
onSelectMenuItem,
|
|
359
|
+
renderChildren,
|
|
366
360
|
])));
|
|
367
361
|
});
|
|
368
362
|
Autocomplete.displayName = 'Autocomplete';
|
|
@@ -20,7 +20,7 @@ const styled_1 = __importDefault(require("@emotion/styled"));
|
|
|
20
20
|
const react_2 = require("@emotion/react");
|
|
21
21
|
const MenuItem_1 = __importDefault(require("../Menu/MenuItem"));
|
|
22
22
|
const StyeldMenuItem = (0, styled_1.default)(MenuItem_1.default, {
|
|
23
|
-
shouldForwardProp: p => !['
|
|
23
|
+
shouldForwardProp: p => !['variant'].includes(p),
|
|
24
24
|
}) `
|
|
25
25
|
${({ $variant, theme }) => $variant === 'virtual' &&
|
|
26
26
|
(0, react_2.css) `
|
|
@@ -29,8 +29,6 @@ interface ContextProviderProps {
|
|
|
29
29
|
readonly initialState?: Partial<State>;
|
|
30
30
|
}
|
|
31
31
|
export declare const ContextProvider: React.FC<ContextProviderProps>;
|
|
32
|
-
export declare const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
export default useContext;
|
|
32
|
+
export declare const useContextState: () => State;
|
|
33
|
+
export declare const useContextDispatch: () => React.Dispatch<Action>;
|
|
34
|
+
export {};
|
package/Autocomplete/context.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.useContextDispatch = exports.useContextState = exports.ContextProvider = exports.createInitialState = exports.reducer = exports.defaultState = exports.actionSetPartial = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const actionSetPartial = (payload) => ({
|
|
9
9
|
type: 'setPartial',
|
|
@@ -41,22 +41,30 @@ const createInitialState = (params) => {
|
|
|
41
41
|
inputValue, currentValue: value, currentOpen: Boolean(isOpen) });
|
|
42
42
|
};
|
|
43
43
|
exports.createInitialState = createInitialState;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
dispatch: () => undefined,
|
|
47
|
-
});
|
|
44
|
+
const StateContext = react_1.default.createContext(exports.defaultState);
|
|
45
|
+
const DispatchContext = react_1.default.createContext(() => undefined);
|
|
48
46
|
const ContextProvider = props => {
|
|
49
47
|
const { children, initialState } = props;
|
|
50
48
|
const [state, dispatch] = react_1.default.useReducer(exports.reducer, Object.assign(Object.assign({}, exports.defaultState), initialState));
|
|
51
|
-
|
|
49
|
+
const stateValue = react_1.default.useMemo(() => state, [state]);
|
|
50
|
+
const dispatchValue = react_1.default.useMemo(() => dispatch, []);
|
|
51
|
+
return (react_1.default.createElement(DispatchContext.Provider, { value: dispatchValue },
|
|
52
|
+
react_1.default.createElement(StateContext.Provider, { value: stateValue }, children)));
|
|
52
53
|
};
|
|
53
54
|
exports.ContextProvider = ContextProvider;
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
const useContextState = () => {
|
|
56
|
+
const context = react_1.default.useContext(StateContext);
|
|
57
|
+
if (context === undefined) {
|
|
58
|
+
throw new Error('useContextState must be used within a ContextProvider');
|
|
59
|
+
}
|
|
60
|
+
return context;
|
|
61
|
+
};
|
|
62
|
+
exports.useContextState = useContextState;
|
|
63
|
+
const useContextDispatch = () => {
|
|
64
|
+
const context = react_1.default.useContext(DispatchContext);
|
|
65
|
+
if (context === undefined) {
|
|
66
|
+
throw new Error('useContextDispatch must be used within a ContextProvider');
|
|
67
|
+
}
|
|
68
|
+
return context;
|
|
60
69
|
};
|
|
61
|
-
exports.
|
|
62
|
-
exports.default = exports.useContext;
|
|
70
|
+
exports.useContextDispatch = useContextDispatch;
|