@via-profit/ui-kit 0.2.1-alpha.1 → 0.2.2

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.
Files changed (143) hide show
  1. package/Autocomplete/AutocompleteContainer.d.ts +33 -6
  2. package/Autocomplete/AutocompleteContainer.js +48 -36
  3. package/Autocomplete/AutocompleteItem.d.ts +1 -1
  4. package/Autocomplete/AutocompleteTextField.d.ts +3 -0
  5. package/Autocomplete/AutocompleteTextField.js +63 -1
  6. package/Autocomplete/OverrideMenuList.d.ts +4 -0
  7. package/Autocomplete/OverrideMenuList.js +39 -0
  8. package/Autocomplete/context.d.ts +9 -1
  9. package/Autocomplete/context.js +15 -1
  10. package/Autocomplete/index.js +9 -10
  11. package/Autocomplete2/Autocomplete2.d.ts +12 -0
  12. package/Autocomplete2/Autocomplete2.js +83 -0
  13. package/Autocomplete2/Autocomplete2TextField.d.ts +7 -0
  14. package/Autocomplete2/Autocomplete2TextField.js +39 -0
  15. package/Autocomplete2/index.d.ts +2 -0
  16. package/Autocomplete2/index.js +7 -0
  17. package/Avatar/index.js +1 -1
  18. package/Badge/BadgeDeleteButton.js +6 -6
  19. package/Badge/BadgeOutlined.js +2 -2
  20. package/Badge/BadgeStandard.js +1 -1
  21. package/Button/ButtonOutlined.js +1 -1
  22. package/Button/ButtonPlain.js +1 -1
  23. package/Button/ButtonStandard.js +4 -11
  24. package/Calendar/CalendarCell.js +6 -2
  25. package/Calendar/CalendarComponent.d.ts +226 -0
  26. package/Calendar/CalendarComponent.js +572 -0
  27. package/Calendar/CalendarControlButton.js +16 -9
  28. package/Calendar/CalendarDayBadge.js +1 -1
  29. package/Calendar/CalendarEmptyCell.d.ts +2 -2
  30. package/Calendar/CalendarEmptyCell.js +8 -3
  31. package/Calendar/CalendarHeading.js +2 -1
  32. package/Calendar/CalendarSubheading.js +3 -2
  33. package/Calendar/CalendarWeekDayCell.d.ts +10 -0
  34. package/Calendar/CalendarWeekDayCell.js +32 -0
  35. package/Calendar/CalendarWeekDayWeekNumber.d.ts +7 -0
  36. package/Calendar/CalendarWeekDayWeekNumber.js +38 -0
  37. package/Calendar/CalendarWeekRow.d.ts +2 -2
  38. package/Calendar/CalendarWeekRow.js +2 -1
  39. package/Calendar/CalendarWeekRowButton.d.ts +13 -0
  40. package/Calendar/CalendarWeekRowButton.js +31 -0
  41. package/Calendar/CalendarYearsSelector.d.ts +39 -1
  42. package/Calendar/CalendarYearsSelector.js +52 -16
  43. package/Calendar/IconChevronDown.d.ts +3 -0
  44. package/Calendar/IconChevronDown.js +31 -0
  45. package/Calendar/index.d.ts +7 -224
  46. package/Calendar/index.js +19 -281
  47. package/Calendar/use-calendar.d.ts +1 -1
  48. package/Color/Color.d.ts +138 -0
  49. package/Color/Color.js +324 -0
  50. package/Color/ColorGenerator.d.ts +29 -0
  51. package/Color/ColorGenerator.js +141 -0
  52. package/Color/ColorParser.d.ts +20 -0
  53. package/Color/ColorParser.js +284 -0
  54. package/Color/index.d.ts +4 -122
  55. package/Color/index.js +18 -473
  56. package/CountryFlags/SwiperOverview.d.ts +257 -0
  57. package/CountryFlags/SwiperOverview.js +524 -0
  58. package/DatePicker/index.d.ts +2 -17
  59. package/DatePicker/index.js +47 -61
  60. package/DatePicker/useDatePickerFormat.js +5 -5
  61. package/ErrorBoundary/Fallback.d.ts +3 -0
  62. package/ErrorBoundary/Fallback.js +51 -0
  63. package/ErrorBoundary/RenderError.d.ts +6 -0
  64. package/ErrorBoundary/RenderError.js +80 -0
  65. package/ErrorBoundary/index.d.ts +7 -11
  66. package/ErrorBoundary/index.js +4 -51
  67. package/LoadingIndicator/Spinner.d.ts +5 -3
  68. package/LoadingIndicator/Spinner.js +61 -32
  69. package/LoadingIndicator/index.d.ts +3 -3
  70. package/LoadingIndicator/index.js +15 -2
  71. package/MaskedField/index.d.ts +2 -1
  72. package/MaskedField/index.js +52 -43
  73. package/MaskedField/useMasked.js +7 -5
  74. package/Menu/AutoHeightWrapper.d.ts +6 -0
  75. package/Menu/AutoHeightWrapper.js +43 -0
  76. package/Menu/MeasuredItem.d.ts +10 -0
  77. package/Menu/MeasuredItem.js +51 -0
  78. package/Menu/MenuContainer.d.ts +51 -18
  79. package/Menu/MenuContainer.js +19 -12
  80. package/Menu/MenuItem.d.ts +24 -7
  81. package/Menu/MenuItem.js +13 -6
  82. package/Menu/MenuList.d.ts +4 -2
  83. package/Menu/MenuList.js +26 -6
  84. package/Menu/VirtualizedItem.d.ts +22 -0
  85. package/Menu/VirtualizedItem.js +69 -0
  86. package/Menu/VirtualizedList.d.ts +18 -0
  87. package/Menu/VirtualizedList.js +28 -0
  88. package/Menu/VirtualizedListComponent.d.ts +20 -0
  89. package/Menu/VirtualizedListComponent.js +305 -0
  90. package/Menu/index.d.ts +3 -1
  91. package/Menu/index.js +2 -0
  92. package/Popper/Popper.d.ts +7 -80
  93. package/Popper/Popper.js +26 -12
  94. package/Popper/PopperContainer.js +1 -1
  95. package/Popper/usePopprer.d.ts +88 -3
  96. package/Popper/usePopprer.js +240 -65
  97. package/Selectbox/SelectboxButton.d.ts +5 -0
  98. package/Selectbox/SelectboxButton.js +48 -8
  99. package/Selectbox/SelectboxButtonWrapper.d.ts +2 -0
  100. package/Selectbox/SelectboxButtonWrapper.js +1 -17
  101. package/Selectbox/SelectboxMenu.d.ts +12 -0
  102. package/Selectbox/SelectboxMenu.js +50 -0
  103. package/Selectbox/index.d.ts +5 -5
  104. package/Selectbox/index.js +115 -97
  105. package/Surface/index.js +1 -1
  106. package/Swiper/Swiper.d.ts +57 -0
  107. package/Swiper/Swiper.js +412 -0
  108. package/Swiper/SwiperContainer.d.ts +7 -0
  109. package/Swiper/SwiperContainer.js +15 -0
  110. package/Swiper/SwiperSlide.d.ts +12 -0
  111. package/Swiper/SwiperSlide.js +58 -0
  112. package/Swiper/SwiperSlidesRenderer.d.ts +11 -0
  113. package/Swiper/SwiperSlidesRenderer.js +74 -0
  114. package/Swiper/SwiperTrack.d.ts +18 -0
  115. package/Swiper/SwiperTrack.js +55 -0
  116. package/Swiper/SwiperWrapper.d.ts +16 -0
  117. package/Swiper/SwiperWrapper.js +60 -0
  118. package/Swiper/index.d.ts +7 -0
  119. package/Swiper/index.js +26 -0
  120. package/Switch/SwitchDot.js +1 -1
  121. package/Switch/SwitchTrack.js +1 -1
  122. package/TextField/TextFieldContainer.d.ts +2 -2
  123. package/TextField/TextFieldContainer.js +5 -3
  124. package/TextField/TextFieldErrorText.d.ts +2 -2
  125. package/TextField/TextFieldErrorText.js +5 -4
  126. package/TextField/TextFieldIconWrapper.d.ts +3 -3
  127. package/TextField/TextFieldIconWrapper.js +5 -3
  128. package/TextField/TextFieldInput.d.ts +2 -2
  129. package/TextField/TextFieldInput.js +6 -4
  130. package/TextField/TextFieldInputWrapper.d.ts +2 -2
  131. package/TextField/TextFieldInputWrapper.js +5 -3
  132. package/TextField/TextFieldLabel.d.ts +2 -2
  133. package/TextField/TextFieldLabel.js +5 -3
  134. package/TextField/TextFieldLabelAsterisk.d.ts +2 -2
  135. package/TextField/TextFieldLabelAsterisk.js +5 -3
  136. package/TextField/index.d.ts +8 -1
  137. package/TextField/index.js +49 -22
  138. package/ThemeProvider/createTheme.js +2 -2
  139. package/package.json +1 -1
  140. package/Calendar/reducer.d.ts +0 -17
  141. package/Calendar/reducer.js +0 -50
  142. /package/Calendar/{IconChevronRight.d.ts → CalendarIconNext.d.ts} +0 -0
  143. /package/Calendar/{IconChevronRight.js → CalendarIconNext.js} +0 -0
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
- import { Value, OnRequestClose, GetOptionSelected } from '../Menu';
3
2
  import { AutocompleteTextFieldProps } from './AutocompleteTextField';
4
- import type { AnchorPos } from '../Popper';
5
- import type { MenuItemCommonProps } from '../Menu/MenuItem';
3
+ import { PositionStrategy } from '../Popper';
4
+ import { AnchorPos, GetOptionSelected, MenuItemProps, OnRequestClose, Value } from '../Menu';
6
5
  export interface AutocompleteProps<T, Multiple extends boolean | undefined = undefined> extends Omit<AutocompleteTextFieldProps, 'value' | 'onChange' | 'children' | 'overrides'> {
7
6
  readonly items: readonly T[];
8
7
  readonly value: Value<T, Multiple>;
@@ -16,15 +15,43 @@ export interface AutocompleteProps<T, Multiple extends boolean | undefined = und
16
15
  */
17
16
  readonly isOpen?: boolean;
18
17
  /**
19
- * Loading indicator visiblility\
18
+ * Loading indicator visibility\
20
19
  * If `true` then visible, otherwise - hidden
21
20
  */
22
21
  /**
23
22
  * Anchor position\
24
23
  * \
25
- * Default: `auto-start-end`
24
+ * Default: `bottom-fill`
26
25
  */
27
26
  readonly anchorPos?: AnchorPos;
27
+ /**
28
+ * When enabled, the popper will automatically try to find the best placement
29
+ * if the preferred placement doesn't fit in the viewport.
30
+ * The component will iterate through possible placements until it finds one that fits.
31
+ *
32
+ * **Default**: `true`
33
+ * ```
34
+ */
35
+ readonly autoFlip?: boolean;
36
+ /**
37
+ * The positioning strategy to use.
38
+ * - `'fixed'`: Positions relative to the viewport. Works reliably in all cases.
39
+ * - `'absolute'`: Positions relative to the nearest positioned ancestor.
40
+ * When using 'absolute', make sure a parent element has `position: relative`.
41
+ *
42
+ * **Default**: `fixed`
43
+ * ```
44
+ */
45
+ readonly positionStrategy?: PositionStrategy;
46
+ /**
47
+ * Minimum distance (in pixels) that the popper must maintain from the viewport edges.
48
+ * Used to prevent the popper from being positioned too close to the screen boundaries.
49
+ * The popper will try to flip to another placement if it cannot maintain this margin.
50
+ *
51
+ * **Default**: `8`
52
+ * ```
53
+ */
54
+ readonly viewportMargin?: number;
28
55
  /**
29
56
  * Text field loading state\
30
57
  * If `true` then text field has been contained the loading indicator, otherwise - nop
@@ -116,7 +143,7 @@ export type Children<T> = (data: {
116
143
  item: T;
117
144
  index: number;
118
145
  inputValue: string;
119
- }, itemProps: MenuItemCommonProps) => React.ReactNode;
146
+ }, itemProps: MenuItemProps) => React.ReactNode;
120
147
  export type ItemToString<T, Multiple extends boolean | undefined = undefined> = (item: Multiple extends undefined ? T : readonly T[]) => string;
121
148
  export type OnChange<T, Multiple extends boolean | undefined = undefined> = (item: Value<T, Multiple>) => void;
122
149
  export type FilterItems<T> = (items: readonly T[], data: {
@@ -38,15 +38,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  const react_1 = __importDefault(require("react"));
41
- const Menu_1 = __importDefault(require("../Menu"));
42
41
  const AutocompleteTextField_1 = __importDefault(require("./AutocompleteTextField"));
43
42
  const Button_1 = __importDefault(require("../Button"));
44
43
  const Spinner_1 = __importDefault(require("../LoadingIndicator/Spinner"));
45
44
  const context_1 = __importStar(require("./context"));
46
45
  const IconClear_1 = __importDefault(require("./IconClear"));
47
46
  const ClickOutside_1 = require("../ClickOutside");
47
+ const OverrideMenuList_1 = __importDefault(require("./OverrideMenuList"));
48
+ const Menu_1 = __importDefault(require("../Menu"));
49
+ //
48
50
  const Autocomplete = react_1.default.forwardRef((props, ref) => {
49
- const { items, value, multiple, isOpen = false, isLoading = false, clearOnBlur = true, anchorPos = 'bottom', openOnFocus = true, 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", "requiredAsterisk", "startIcon", "fullWidth", "placeholder", "label", "error", "errorText", "inputRef", "filterItems", "children", "onChange", "selectedItemToString", "clearable", "onInputChange", "getOptionSelected", "onRequestOpen", "onRequestClose", "overrides"]);
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);
50
53
  const menuRef = react_1.default.useRef(null);
51
54
  const fieldInputRef = react_1.default.useRef(null);
52
55
  const isFocusedRef = react_1.default.useRef(false);
@@ -85,13 +88,13 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
85
88
  case 'NumpadEnter':
86
89
  if (currentOpen) {
87
90
  event.preventDefault();
88
- (_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.selectHightlightedItem();
91
+ (_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.selectHighlightedItem();
89
92
  }
90
93
  break;
91
94
  case 'ArrowUp':
92
95
  {
93
96
  event.preventDefault();
94
- (_b = menuRef.current) === null || _b === void 0 ? void 0 : _b.hightlightPrevItem();
97
+ (_b = menuRef.current) === null || _b === void 0 ? void 0 : _b.highlightPrevItem();
95
98
  }
96
99
  break;
97
100
  case 'ArrowDown':
@@ -101,20 +104,20 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
101
104
  onRequestOpen(event);
102
105
  }
103
106
  if (currentOpen) {
104
- (_c = menuRef.current) === null || _c === void 0 ? void 0 : _c.hightlightNextItem();
107
+ (_c = menuRef.current) === null || _c === void 0 ? void 0 : _c.highlightNextItem();
105
108
  }
106
109
  }
107
110
  break;
108
111
  case 'Home':
109
112
  {
110
113
  event.preventDefault();
111
- (_d = menuRef.current) === null || _d === void 0 ? void 0 : _d.hightlightFirstItem();
114
+ (_d = menuRef.current) === null || _d === void 0 ? void 0 : _d.highlightFirstItem();
112
115
  }
113
116
  break;
114
117
  case 'End':
115
118
  {
116
119
  event.preventDefault();
117
- (_e = menuRef.current) === null || _e === void 0 ? void 0 : _e.hightlightLastItem();
120
+ (_e = menuRef.current) === null || _e === void 0 ? void 0 : _e.highlightLastItem();
118
121
  }
119
122
  break;
120
123
  // case 'PageUp':
@@ -135,11 +138,11 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
135
138
  const applyFilterForItems = react_1.default.useCallback((inputValue, itemList) => {
136
139
  const query = inputValue.toLowerCase().trim();
137
140
  // Apply filter
138
- const newItems = typeof filterItems !== 'function' || query.length === 0
141
+ return typeof filterItems !== 'function' || query.length === 0
139
142
  ? itemList
140
143
  : filterItems(itemList, { query, inputValue });
141
- return newItems;
142
144
  }, [filterItems]);
145
+ const renderChildren = react_1.default.useCallback(({ index, item }, itemProps) => children({ index, item: item, inputValue }, itemProps), [children, inputValue]);
143
146
  /**
144
147
  * Only affected value change action
145
148
  */
@@ -166,20 +169,27 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
166
169
  }
167
170
  }, [filteredItems]);
168
171
  react_1.default.useEffect(() => {
169
- if (currentOpen !== isOpen || currentLoading !== isLoading) {
170
- dispatch((0, context_1.actionSetPartial)({ currentOpen: isOpen, currentLoading: isLoading }));
172
+ if (currentOpen !== isOpen) {
173
+ dispatch((0, context_1.actionSetPartial)({ currentOpen: isOpen }));
171
174
  }
172
- }, [isOpen, isLoading, dispatch, currentOpen, currentLoading]);
175
+ }, [isOpen, currentOpen, dispatch]);
173
176
  react_1.default.useEffect(() => {
174
- if (JSON.stringify(items) !== JSON.stringify(itemsRef.current)) {
175
- itemsRef.current = items;
176
- const newFilteredItems = applyFilterForItems(inputValue, items);
177
- dispatch((0, context_1.actionSetPartial)({ filteredItems: newFilteredItems }));
178
- if (!newFilteredItems.length) {
179
- onRequestClose();
180
- }
177
+ if (currentLoading !== isLoading) {
178
+ dispatch((0, context_1.actionSetPartial)({ currentLoading: isLoading }));
181
179
  }
182
- }, [items, inputValue, applyFilterForItems, dispatch, onRequestClose]);
180
+ }, [isLoading, currentLoading, dispatch]);
181
+ react_1.default.useEffect(() => {
182
+ // Сравниваем items более эффективно
183
+ if (itemsRef.current === items) {
184
+ return;
185
+ }
186
+ itemsRef.current = items;
187
+ const newFilteredItems = applyFilterForItems(inputValue, items);
188
+ dispatch((0, context_1.actionSetPartial)({ filteredItems: newFilteredItems }));
189
+ if (!newFilteredItems.length && currentOpen) {
190
+ onRequestClose();
191
+ }
192
+ }, [items, inputValue, applyFilterForItems, dispatch, onRequestClose, currentOpen]);
183
193
  react_1.default.useEffect(() => {
184
194
  const mouseDownEvent = (event) => {
185
195
  var _a;
@@ -232,7 +242,7 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
232
242
  multiple,
233
243
  ]);
234
244
  return (react_1.default.createElement(react_1.default.Fragment, null,
235
- 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, isLoading: currentLoading, endIcon: clearable ? (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))) : undefined }, nativeInputProps, { onKeyDown: event => {
245
+ react_1.default.useMemo(() => (react_1.default.createElement(overridesMap.TextField, Object.assign({ placeholder: placeholder, anchorPos: actualPlacement, isOpen: currentOpen, label: label, error: error, requiredAsterisk: requiredAsterisk, errorText: errorText, fullWidth: fullWidth, startIcon: startIcon, isLoading: currentLoading, endIcon: clearable ? (react_1.default.createElement(Button_1.default, { iconOnly: true, type: "button", variant: "plain", onClick: () => (currentLoading ? 'undefined' : clear()) }, currentLoading ? react_1.default.createElement(Spinner_1.default, null) : react_1.default.createElement(IconClear_1.default, null))) : undefined }, nativeInputProps, { onKeyDown: event => {
236
246
  inputKeydownEvent(event);
237
247
  if (typeof nativeInputProps.onKeyDown === 'function') {
238
248
  nativeInputProps.onKeyDown(event);
@@ -256,16 +266,12 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
256
266
  }
257
267
  }, onFocus: event => {
258
268
  isFocusedRef.current = true;
259
- if (openOnFocus &&
260
- !currentOpen &&
261
- filteredItems.length > 0
262
- // && inputValue.trim() !== ''
263
- ) {
264
- onRequestOpen(event);
265
- }
266
- if (!openOnFocus && !currentOpen && inputValue !== '' && filteredItems.length > 0) {
269
+ if (openOnFocus && !currentOpen && filteredItems.length > 0) {
267
270
  onRequestOpen(event);
268
271
  }
272
+ // if (!openOnFocus && !currentOpen && inputValue !== '' && filteredItems.length > 0) {
273
+ // onRequestOpen(event);
274
+ // }
269
275
  if (typeof nativeInputProps.onFocus === 'function') {
270
276
  nativeInputProps.onFocus(event);
271
277
  }
@@ -307,8 +313,9 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
307
313
  } }))), [
308
314
  overridesMap,
309
315
  placeholder,
316
+ actualPlacement,
317
+ currentOpen,
310
318
  label,
311
- onRequestClose,
312
319
  error,
313
320
  requiredAsterisk,
314
321
  errorText,
@@ -324,14 +331,16 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
324
331
  dispatch,
325
332
  inputRef,
326
333
  openOnFocus,
327
- currentOpen,
328
334
  filteredItems.length,
329
335
  onRequestOpen,
330
336
  onInputChange,
331
- items,
332
337
  applyFilterForItems,
338
+ items,
339
+ onRequestClose,
333
340
  ]),
334
- react_1.default.useMemo(() => (react_1.default.createElement(Menu_1.default, { ref: menuRef, anchorPos: anchorPos, multiple: multiple, items: filteredItems, value: currentValue, isOpen: currentOpen, autofocus: false, anchorElement: anchorElement, closeOutsideClick: false, getOptionSelected: getOptionSelected, onRequestClose: onRequestClose, closeOnSelect: multiple ? false : true, onSelectItem: item => {
341
+ react_1.default.useMemo(() => (react_1.default.createElement(Menu_1.default, { ref: menuRef, onAnchorPosChanged: setActualPlacement, anchorPos: actualPlacement, multiple: multiple, items: filteredItems, value: currentValue, isOpen: currentOpen, autofocus: false, autoFlip: autoFlip, viewportMargin: viewportMargin, offset: 0, overrides: {
342
+ List: OverrideMenuList_1.default,
343
+ }, positionStrategy: positionStrategy, anchorElement: anchorElement, closeOutsideClick: false, getOptionSelected: getOptionSelected, onRequestClose: onRequestClose, closeOnSelect: !multiple, onSelectItem: item => {
335
344
  if (!multiple) {
336
345
  dispatch({
337
346
  type: 'setPartial',
@@ -343,20 +352,23 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
343
352
  if (typeof onChange === 'function') {
344
353
  onChange(item);
345
354
  }
346
- } }, ({ index, item }, itemProps) => children({ index, item: item, inputValue }, itemProps))), [
347
- anchorPos,
355
+ } }, renderChildren)), [
356
+ actualPlacement,
348
357
  multiple,
349
358
  filteredItems,
350
359
  currentValue,
351
360
  currentOpen,
361
+ autoFlip,
362
+ viewportMargin,
363
+ positionStrategy,
352
364
  anchorElement,
353
365
  getOptionSelected,
354
366
  onRequestClose,
367
+ onChange,
355
368
  dispatch,
356
369
  applyFilterForItems,
357
370
  selectedItemToString,
358
371
  items,
359
- onChange,
360
372
  children,
361
373
  inputValue,
362
374
  ])));
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { MenuItemProps } from '../Menu/MenuItem';
3
3
  export interface AutocompleteItemProps extends MenuItemProps {
4
4
  readonly variant?: 'standard' | 'virtual';
5
- readonly startIcon?: JSX.Element;
5
+ readonly startIcon?: React.ReactNode;
6
6
  }
7
7
  export declare const AutocompleteItem: React.ForwardRefExoticComponent<AutocompleteItemProps & React.RefAttributes<HTMLDivElement>>;
8
8
  export default AutocompleteItem;
@@ -1,11 +1,14 @@
1
1
  import React from 'react';
2
2
  import { TextFieldProps } from '../TextField';
3
+ import { AnchorPos } from '../Menu';
3
4
  export interface AutocompleteTextFieldProps extends TextFieldProps {
4
5
  /**
5
6
  * Text field loading state\
6
7
  * If `true` then text field has been contained the loading indicator, otherwise - nop
7
8
  */
8
9
  readonly isLoading?: boolean;
10
+ readonly anchorPos?: AnchorPos;
11
+ readonly isOpen?: boolean;
9
12
  /**
10
13
  * Native <input> element reference
11
14
  */
@@ -1,9 +1,71 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
17
  const react_1 = __importDefault(require("react"));
18
+ const styled_1 = __importDefault(require("@emotion/styled"));
19
+ const react_2 = require("@emotion/react");
7
20
  const TextField_1 = __importDefault(require("../TextField"));
8
- const AutocompleteTextField = (props, ref) => react_1.default.createElement(TextField_1.default, Object.assign({}, props, { ref: ref }));
21
+ const TextFieldInputWrapper_1 = __importDefault(require("../TextField/TextFieldInputWrapper"));
22
+ const StyledTextFieldInputWrapper = (0, styled_1.default)(TextFieldInputWrapper_1.default) `
23
+ ${({ theme, $isOpen, $anchorPos }) => $isOpen &&
24
+ $anchorPos &&
25
+ ['bottom-fill', 'top-fill'].includes($anchorPos) &&
26
+ (0, react_2.css) `
27
+ border-width: 1px;
28
+ border-style: solid;
29
+ border-color: ${theme.isDark
30
+ ? theme.color.textPrimary.darken(100).toString()
31
+ : theme.color.textPrimary.lighten(150).toString()};
32
+ `};
33
+
34
+ ${({ focused, $anchorPos, $isOpen }) => $isOpen &&
35
+ $anchorPos &&
36
+ ['bottom-fill', 'top-fill'].includes($anchorPos) &&
37
+ focused &&
38
+ (0, react_2.css) `
39
+ outline: none;
40
+ `};
41
+
42
+ ${({ $anchorPos, $isOpen }) => $isOpen &&
43
+ $anchorPos === 'bottom-fill' &&
44
+ (0, react_2.css) `
45
+ border-bottom-left-radius: 0;
46
+ border-bottom-right-radius: 0;
47
+ border-bottom: 0;
48
+ `};
49
+
50
+ ${({ $anchorPos, $isOpen }) => $isOpen &&
51
+ $anchorPos === 'top-fill' &&
52
+ (0, react_2.css) `
53
+ border-top-left-radius: 0;
54
+ border-top-right-radius: 0;
55
+ border-top: 0;
56
+ `};
57
+ `;
58
+ const WrapperContext = react_1.default.createContext({ anchorPos: undefined, isOpen: false });
59
+ const InputWrapper = react_1.default.forwardRef(function StyledInputWrapper(props, ref) {
60
+ const ctx = react_1.default.useContext(WrapperContext);
61
+ const { anchorPos, isOpen } = ctx;
62
+ return (react_1.default.createElement(StyledTextFieldInputWrapper, Object.assign({ "$anchorPos": anchorPos, "$isOpen": isOpen, ref: ref }, props)));
63
+ });
64
+ const AutocompleteTextField = (props, ref) => {
65
+ const { anchorPos, isOpen } = props, restProps = __rest(props, ["anchorPos", "isOpen"]);
66
+ return (react_1.default.createElement(WrapperContext.Provider, { value: { anchorPos, isOpen } },
67
+ react_1.default.createElement(TextField_1.default, Object.assign({ overrides: {
68
+ InputWrapper,
69
+ } }, restProps, { ref: ref }))));
70
+ };
9
71
  exports.default = react_1.default.forwardRef(AutocompleteTextField);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { MenuListProps } from '../Menu';
3
+ declare const OverrideMenuList: React.ForwardRefExoticComponent<MenuListProps & React.RefAttributes<HTMLDivElement>>;
4
+ export default OverrideMenuList;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ const styled_1 = __importDefault(require("@emotion/styled"));
8
+ const react_2 = require("@emotion/react");
9
+ const Menu_1 = require("../Menu");
10
+ const StyledMenuList = (0, styled_1.default)(Menu_1.MenuList) `
11
+ &:focus {
12
+ outline: none;
13
+ }
14
+
15
+ --border-color: ${({ theme }) => theme.isDark
16
+ ? theme.color.textPrimary.darken(100).toString()
17
+ : theme.color.textPrimary.lighten(150).toString()};
18
+
19
+ ${({ anchorPos, theme }) => anchorPos === 'top-fill' &&
20
+ (0, react_2.css) `
21
+ border-bottom-left-radius: 0;
22
+ border-bottom-right-radius: 0;
23
+ border: 1px solid var(--border-color);
24
+ border-bottom: 0;
25
+ box-shadow: 0 1em -1.5em ${theme.color.surface.darken(50).alpha(0.6).toString()};
26
+ `};
27
+
28
+ ${({ anchorPos, theme }) => anchorPos === 'bottom-fill' &&
29
+ (0, react_2.css) `
30
+ border-top-left-radius: 0;
31
+ border-top-right-radius: 0;
32
+ border: 1px solid var(--border-color);
33
+ border-top: 0;
34
+ box-shadow: 0 1em 1.5em ${theme.color.surface.darken(50).alpha(0.6).toString()};
35
+ `};
36
+ `;
37
+ const OverrideMenuList = react_1.default.forwardRef((props, ref) => (react_1.default.createElement(StyledMenuList, Object.assign({ "data-anch-po": props.anchorPos }, props, { ref: ref }))));
38
+ OverrideMenuList.displayName = 'OverrideMenuList';
39
+ exports.default = OverrideMenuList;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
- import type { AnchorElement } from '../Menu';
2
+ import type { AnchorElement, Value } from '../Menu';
3
+ import { FilterItems, ItemToString } from './AutocompleteContainer';
3
4
  type State = {
4
5
  readonly currentOpen: boolean;
5
6
  readonly currentLoading: boolean;
@@ -16,6 +17,13 @@ type ActionSetPartial = {
16
17
  export declare const actionSetPartial: (payload: ActionSetPartial['payload']) => ActionSetPartial;
17
18
  export declare const defaultState: State;
18
19
  export declare const reducer: React.Reducer<State, Action>;
20
+ export declare const createInitialState: <T, Multiple extends boolean | undefined = undefined>(params: {
21
+ readonly items: readonly T[];
22
+ readonly value: Value<T, Multiple> | null;
23
+ readonly selectedItemToString: ItemToString<T, Multiple>;
24
+ readonly isOpen?: boolean | undefined;
25
+ readonly filterItems: FilterItems<T> | undefined;
26
+ }) => State;
19
27
  interface ContextProviderProps {
20
28
  readonly children: React.ReactNode | readonly React.ReactNode[];
21
29
  readonly initialState?: Partial<State>;
@@ -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.useContext = exports.ContextProvider = exports.reducer = exports.defaultState = exports.actionSetPartial = void 0;
6
+ exports.useContext = 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',
@@ -27,6 +27,20 @@ const reducer = (state, action) => {
27
27
  }
28
28
  };
29
29
  exports.reducer = reducer;
30
+ const createInitialState = (params) => {
31
+ const { filterItems, isOpen, items, selectedItemToString, value } = params;
32
+ const inputValue = !value
33
+ ? ''
34
+ : selectedItemToString(value);
35
+ const data = {
36
+ inputValue: inputValue,
37
+ query: inputValue.trim().toLocaleLowerCase(),
38
+ };
39
+ const filteredItems = filterItems ? filterItems(items, data) : items;
40
+ return Object.assign(Object.assign({}, exports.defaultState), { filteredItems,
41
+ inputValue, currentValue: value, currentOpen: Boolean(isOpen) });
42
+ };
43
+ exports.createInitialState = createInitialState;
30
44
  const context = react_1.default.createContext({
31
45
  state: exports.defaultState,
32
46
  dispatch: () => undefined,
@@ -34,16 +34,15 @@ const context_1 = require("./context");
34
34
  __exportStar(require("./AutocompleteContainer"), exports);
35
35
  __exportStar(require("./AutocompleteItem"), exports);
36
36
  const Autocomplete = react_1.default.forwardRef((props, ref) => {
37
- const { children, items, isOpen, multiple, selectedItemToString, value } = props, restProps = __rest(props, ["children", "items", "isOpen", "multiple", "selectedItemToString", "value"]);
38
- return (react_1.default.createElement(context_1.ContextProvider, { initialState: {
39
- filteredItems: items,
40
- currentOpen: isOpen,
41
- currentValue: value,
42
- inputValue: value === null
43
- ? ''
44
- : selectedItemToString(value),
45
- } },
46
- react_1.default.createElement(AutocompleteContainer_1.default, Object.assign({}, restProps, { items: items, isOpen: isOpen, multiple: multiple, selectedItemToString: selectedItemToString, value: value, ref: ref }), children)));
37
+ const { children, items, filterItems, isOpen, multiple, selectedItemToString, value } = props, restProps = __rest(props, ["children", "items", "filterItems", "isOpen", "multiple", "selectedItemToString", "value"]);
38
+ return (react_1.default.createElement(context_1.ContextProvider, { initialState: (0, context_1.createInitialState)({
39
+ items,
40
+ selectedItemToString,
41
+ filterItems,
42
+ value,
43
+ isOpen,
44
+ }) },
45
+ react_1.default.createElement(AutocompleteContainer_1.default, Object.assign({}, restProps, { items: items, filterItems: filterItems, isOpen: isOpen, multiple: multiple, selectedItemToString: selectedItemToString, value: value, ref: ref }), children)));
47
46
  });
48
47
  Autocomplete.displayName = 'Autocomplete';
49
48
  exports.default = Autocomplete;
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ type Item = {
3
+ readonly id: string;
4
+ readonly label: string;
5
+ };
6
+ type Autocomplete2Props = {
7
+ readonly value: Item | null;
8
+ readonly items: readonly Item[];
9
+ readonly onChange: (value: Item | null) => void;
10
+ };
11
+ declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<Autocomplete2Props & React.RefAttributes<HTMLDivElement>>>;
12
+ export default _default;
@@ -0,0 +1,83 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const React = __importStar(require("react"));
30
+ const Autocomplete2TextField_1 = __importDefault(require("./Autocomplete2TextField"));
31
+ const Autocomplete2 = React.forwardRef((props, ref) => {
32
+ const { value, items, onChange } = props;
33
+ /**
34
+ * Get item ID
35
+ */
36
+ const getItemID = React.useCallback((item) => (item ? item.id : '<no-value-id>'), []);
37
+ const [valueID, setValueID] = React.useState(() => getItemID(value));
38
+ /**
39
+ * Filter items list by input value
40
+ */
41
+ const filterItems = React.useCallback((items, data) => {
42
+ const { query } = data;
43
+ return items.filter(item => item.label.toLocaleLowerCase().indexOf(query) !== -1);
44
+ }, []);
45
+ /**
46
+ * Input value
47
+ */
48
+ const [inputValue, setInputValue] = React.useState(() => {
49
+ if (!value) {
50
+ return '';
51
+ }
52
+ return value.label;
53
+ });
54
+ /**
55
+ * Filtered items
56
+ */
57
+ const [filteredItems, setFilteredItems] = React.useState(() => filterItems(items, { query: inputValue }));
58
+ /**
59
+ * Render filtered items list
60
+ */
61
+ const renderItems = React.useCallback(() => (React.createElement("ol", null, filteredItems.map(item => (React.createElement("li", { key: item.id, onClick: () => onChange(item) }, item.label))))), [filteredItems, onChange]);
62
+ /**
63
+ * onChange text field input
64
+ */
65
+ const handleInputChange = React.useCallback((input) => {
66
+ setInputValue(input);
67
+ setFilteredItems(filterItems(items, { query: input }));
68
+ }, [filterItems, items]);
69
+ /**
70
+ * value listener
71
+ */
72
+ React.useEffect(() => {
73
+ const newValueID = getItemID(value);
74
+ if (newValueID !== valueID) {
75
+ setValueID(newValueID);
76
+ }
77
+ }, [getItemID, inputValue, value, valueID]);
78
+ return (React.createElement("div", null,
79
+ React.createElement(Autocomplete2TextField_1.default, { ref: ref, value: inputValue, onChange: handleInputChange }),
80
+ renderItems()));
81
+ });
82
+ Autocomplete2.displayName = 'Autocomplete2';
83
+ exports.default = React.memo(Autocomplete2);
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ export type Autocomplete2TextFieldProps = {
3
+ readonly value: string;
4
+ readonly onChange: (value: string) => void;
5
+ };
6
+ declare const Autocomplete2TextField: React.ForwardRefExoticComponent<Autocomplete2TextFieldProps & React.RefAttributes<HTMLDivElement>>;
7
+ export default Autocomplete2TextField;
@@ -0,0 +1,39 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const React = __importStar(require("react"));
30
+ const TextField_1 = __importDefault(require("../TextField"));
31
+ const Autocomplete2TextField = React.forwardRef((props, ref) => {
32
+ const { value, onChange } = props;
33
+ const handleChange = React.useCallback(event => {
34
+ onChange(event.target.value);
35
+ }, [onChange]);
36
+ return React.createElement(TextField_1.default, { value: value, onChange: handleChange, ref: ref });
37
+ });
38
+ Autocomplete2TextField.displayName = 'Autocomplete2TextField';
39
+ exports.default = Autocomplete2TextField;
@@ -0,0 +1,2 @@
1
+ import Autocomplete2 from "./Autocomplete2";
2
+ export default Autocomplete2;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const Autocomplete2_1 = __importDefault(require("./Autocomplete2"));
7
+ exports.default = Autocomplete2_1.default;