@mongodb-js/compass-components 1.3.0 → 1.5.0

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 (224) hide show
  1. package/lib/components/accordion.d.ts +1 -2
  2. package/lib/components/accordion.d.ts.map +1 -1
  3. package/lib/components/accordion.js +3 -3
  4. package/lib/components/accordion.js.map +1 -1
  5. package/lib/components/bson-value.d.ts +5 -3
  6. package/lib/components/bson-value.d.ts.map +1 -1
  7. package/lib/components/bson-value.js +52 -33
  8. package/lib/components/bson-value.js.map +1 -1
  9. package/lib/components/cancel-loader.d.ts.map +1 -1
  10. package/lib/components/cancel-loader.js +6 -1
  11. package/lib/components/cancel-loader.js.map +1 -1
  12. package/lib/components/combobox/Chip.d.ts +4 -0
  13. package/lib/components/combobox/Chip.d.ts.map +1 -0
  14. package/lib/components/combobox/Chip.js +229 -0
  15. package/lib/components/combobox/Chip.js.map +1 -0
  16. package/lib/components/combobox/Combobox.d.ts +39 -0
  17. package/lib/components/combobox/Combobox.d.ts.map +1 -0
  18. package/lib/components/combobox/Combobox.js +817 -0
  19. package/lib/components/combobox/Combobox.js.map +1 -0
  20. package/lib/components/combobox/Combobox.styles.d.ts +38 -0
  21. package/lib/components/combobox/Combobox.styles.d.ts.map +1 -0
  22. package/lib/components/combobox/Combobox.styles.js +278 -0
  23. package/lib/components/combobox/Combobox.styles.js.map +1 -0
  24. package/lib/components/combobox/Combobox.types.d.ts +121 -0
  25. package/lib/components/combobox/Combobox.types.d.ts.map +1 -0
  26. package/lib/components/combobox/Combobox.types.js +46 -0
  27. package/lib/components/combobox/Combobox.types.js.map +1 -0
  28. package/lib/components/combobox/ComboboxContext.d.ts +21 -0
  29. package/lib/components/combobox/ComboboxContext.d.ts.map +1 -0
  30. package/lib/components/combobox/ComboboxContext.js +19 -0
  31. package/lib/components/combobox/ComboboxContext.js.map +1 -0
  32. package/lib/components/combobox/ComboboxGroup.d.ts +15 -0
  33. package/lib/components/combobox/ComboboxGroup.d.ts.map +1 -0
  34. package/lib/components/combobox/ComboboxGroup.js +84 -0
  35. package/lib/components/combobox/ComboboxGroup.js.map +1 -0
  36. package/lib/components/combobox/ComboboxMenu/ComboboxMenu.d.ts +9 -0
  37. package/lib/components/combobox/ComboboxMenu/ComboboxMenu.d.ts.map +1 -0
  38. package/lib/components/combobox/ComboboxMenu/ComboboxMenu.js +86 -0
  39. package/lib/components/combobox/ComboboxMenu/ComboboxMenu.js.map +1 -0
  40. package/lib/components/combobox/ComboboxMenu/Menu.styles.d.ts +22 -0
  41. package/lib/components/combobox/ComboboxMenu/Menu.styles.d.ts.map +1 -0
  42. package/lib/components/combobox/ComboboxMenu/Menu.styles.js +115 -0
  43. package/lib/components/combobox/ComboboxMenu/Menu.styles.js.map +1 -0
  44. package/lib/components/combobox/ComboboxOption.d.ts +17 -0
  45. package/lib/components/combobox/ComboboxOption.d.ts.map +1 -0
  46. package/lib/components/combobox/ComboboxOption.js +258 -0
  47. package/lib/components/combobox/ComboboxOption.js.map +1 -0
  48. package/lib/components/combobox/Menu.styles.d.ts +18 -0
  49. package/lib/components/combobox/Menu.styles.d.ts.map +1 -0
  50. package/lib/components/combobox/Menu.styles.js +98 -0
  51. package/lib/components/combobox/Menu.styles.js.map +1 -0
  52. package/lib/components/combobox/index.d.ts +4 -0
  53. package/lib/components/combobox/index.d.ts.map +1 -0
  54. package/lib/components/combobox/index.js +13 -0
  55. package/lib/components/combobox/index.js.map +1 -0
  56. package/lib/components/combobox/utils/OptionObjectUtils.d.ts +5 -0
  57. package/lib/components/combobox/utils/OptionObjectUtils.d.ts.map +1 -0
  58. package/lib/components/combobox/utils/OptionObjectUtils.js +23 -0
  59. package/lib/components/combobox/utils/OptionObjectUtils.js.map +1 -0
  60. package/lib/components/combobox/utils/flattenChildren.d.ts +4 -0
  61. package/lib/components/combobox/utils/flattenChildren.d.ts.map +1 -0
  62. package/lib/components/combobox/utils/flattenChildren.js +35 -0
  63. package/lib/components/combobox/utils/flattenChildren.js.map +1 -0
  64. package/lib/components/combobox/utils/getNameAndValue.d.ts +6 -0
  65. package/lib/components/combobox/utils/getNameAndValue.d.ts.map +1 -0
  66. package/lib/components/combobox/utils/getNameAndValue.js +16 -0
  67. package/lib/components/combobox/utils/getNameAndValue.js.map +1 -0
  68. package/lib/components/combobox/utils/index.d.ts +5 -0
  69. package/lib/components/combobox/utils/index.d.ts.map +1 -0
  70. package/lib/components/combobox/utils/index.js +14 -0
  71. package/lib/components/combobox/utils/index.js.map +1 -0
  72. package/lib/components/combobox/utils/wrapJSX.d.ts +3 -0
  73. package/lib/components/combobox/utils/wrapJSX.d.ts.map +1 -0
  74. package/lib/components/combobox/utils/wrapJSX.js +33 -0
  75. package/lib/components/combobox/utils/wrapJSX.js.map +1 -0
  76. package/lib/components/document-list/document-edit-actions-footer.d.ts.map +1 -1
  77. package/lib/components/document-list/document-edit-actions-footer.js +9 -5
  78. package/lib/components/document-list/document-edit-actions-footer.js.map +1 -1
  79. package/lib/components/document-list/element-actions.d.ts.map +1 -1
  80. package/lib/components/document-list/element-actions.js +15 -13
  81. package/lib/components/document-list/element-actions.js.map +1 -1
  82. package/lib/components/document-list/element-editors.d.ts.map +1 -1
  83. package/lib/components/document-list/element-editors.js +41 -17
  84. package/lib/components/document-list/element-editors.js.map +1 -1
  85. package/lib/components/document-list/element.d.ts.map +1 -1
  86. package/lib/components/document-list/element.js +59 -9
  87. package/lib/components/document-list/element.js.map +1 -1
  88. package/lib/components/empty-content.d.ts.map +1 -1
  89. package/lib/components/empty-content.js +9 -2
  90. package/lib/components/empty-content.js.map +1 -1
  91. package/lib/components/file-input.d.ts +49 -17
  92. package/lib/components/file-input.d.ts.map +1 -1
  93. package/lib/components/file-input.js +107 -8
  94. package/lib/components/file-input.js.map +1 -1
  95. package/lib/components/horizontal-rule.d.ts +4 -0
  96. package/lib/components/horizontal-rule.d.ts.map +1 -0
  97. package/lib/components/horizontal-rule.js +49 -0
  98. package/lib/components/horizontal-rule.js.map +1 -0
  99. package/lib/components/icons/document-icon.d.ts +1 -4
  100. package/lib/components/icons/document-icon.d.ts.map +1 -1
  101. package/lib/components/icons/document-icon.js +2 -2
  102. package/lib/components/icons/document-icon.js.map +1 -1
  103. package/lib/components/icons/favorite-icon.d.ts +6 -7
  104. package/lib/components/icons/favorite-icon.d.ts.map +1 -1
  105. package/lib/components/icons/favorite-icon.js +2 -2
  106. package/lib/components/icons/favorite-icon.js.map +1 -1
  107. package/lib/components/icons/no-saved-items-icon.d.ts +0 -1
  108. package/lib/components/icons/no-saved-items-icon.d.ts.map +1 -1
  109. package/lib/components/icons/no-saved-items-icon.js +2 -2
  110. package/lib/components/icons/no-saved-items-icon.js.map +1 -1
  111. package/lib/components/index-keys-badge.d.ts +11 -0
  112. package/lib/components/index-keys-badge.d.ts.map +1 -0
  113. package/lib/components/index-keys-badge.js +26 -0
  114. package/lib/components/index-keys-badge.js.map +1 -0
  115. package/lib/components/interactive-popover.js +2 -2
  116. package/lib/components/interactive-popover.js.map +1 -1
  117. package/lib/components/item-action-controls.d.ts +13 -0
  118. package/lib/components/item-action-controls.d.ts.map +1 -1
  119. package/lib/components/item-action-controls.js +44 -7
  120. package/lib/components/item-action-controls.js.map +1 -1
  121. package/lib/components/keyline-card.d.ts +1 -4
  122. package/lib/components/keyline-card.d.ts.map +1 -1
  123. package/lib/components/keyline-card.js +3 -3
  124. package/lib/components/keyline-card.js.map +1 -1
  125. package/lib/components/leafygreen.d.ts +29 -73
  126. package/lib/components/leafygreen.d.ts.map +1 -1
  127. package/lib/components/leafygreen.js +44 -69
  128. package/lib/components/leafygreen.js.map +1 -1
  129. package/lib/components/modals/confirmation-modal.d.ts +1 -1
  130. package/lib/components/modals/confirmation-modal.d.ts.map +1 -1
  131. package/lib/components/modals/confirmation-modal.js +3 -2
  132. package/lib/components/modals/confirmation-modal.js.map +1 -1
  133. package/lib/components/modals/modal-body.d.ts +1 -1
  134. package/lib/components/modals/modal-body.d.ts.map +1 -1
  135. package/lib/components/modals/modal-body.js +31 -8
  136. package/lib/components/modals/modal-body.js.map +1 -1
  137. package/lib/components/modals/modal-footer-button.d.ts +2 -2
  138. package/lib/components/modals/modal-footer-button.d.ts.map +1 -1
  139. package/lib/components/modals/modal-footer-button.js +3 -4
  140. package/lib/components/modals/modal-footer-button.js.map +1 -1
  141. package/lib/components/modals/modal-header.d.ts +2 -3
  142. package/lib/components/modals/modal-header.d.ts.map +1 -1
  143. package/lib/components/modals/modal-header.js +2 -2
  144. package/lib/components/modals/modal-header.js.map +1 -1
  145. package/lib/components/modals/modal.d.ts +1 -1
  146. package/lib/components/modals/modal.d.ts.map +1 -1
  147. package/lib/components/modals/modal.js +5 -2
  148. package/lib/components/modals/modal.js.map +1 -1
  149. package/lib/components/placeholder.d.ts +3 -4
  150. package/lib/components/placeholder.d.ts.map +1 -1
  151. package/lib/components/placeholder.js +2 -2
  152. package/lib/components/placeholder.js.map +1 -1
  153. package/lib/components/resizeable-sidebar.d.ts.map +1 -1
  154. package/lib/components/resizeable-sidebar.js +2 -2
  155. package/lib/components/resizeable-sidebar.js.map +1 -1
  156. package/lib/components/spin-loader.d.ts +2 -1
  157. package/lib/components/spin-loader.d.ts.map +1 -1
  158. package/lib/components/spin-loader.js +10 -3
  159. package/lib/components/spin-loader.js.map +1 -1
  160. package/lib/components/store-connector.d.ts +17 -0
  161. package/lib/components/store-connector.d.ts.map +1 -0
  162. package/lib/components/store-connector.js +25 -0
  163. package/lib/components/store-connector.js.map +1 -0
  164. package/lib/components/tab-nav-bar.d.ts +2 -3
  165. package/lib/components/tab-nav-bar.d.ts.map +1 -1
  166. package/lib/components/tab-nav-bar.js +2 -2
  167. package/lib/components/tab-nav-bar.js.map +1 -1
  168. package/lib/components/tooltip.d.ts.map +1 -1
  169. package/lib/components/tooltip.js +2 -8
  170. package/lib/components/tooltip.js.map +1 -1
  171. package/lib/components/virtual-grid.d.ts +1 -1
  172. package/lib/components/workspace-container.d.ts +1 -2
  173. package/lib/components/workspace-container.d.ts.map +1 -1
  174. package/lib/components/workspace-container.js +13 -3
  175. package/lib/components/workspace-container.js.map +1 -1
  176. package/lib/components/workspace-tabs/tab.d.ts +3 -3
  177. package/lib/components/workspace-tabs/tab.d.ts.map +1 -1
  178. package/lib/components/workspace-tabs/tab.js +18 -4
  179. package/lib/components/workspace-tabs/tab.js.map +1 -1
  180. package/lib/components/workspace-tabs/workspace-tabs.d.ts +1 -2
  181. package/lib/components/workspace-tabs/workspace-tabs.d.ts.map +1 -1
  182. package/lib/components/workspace-tabs/workspace-tabs.js +48 -23
  183. package/lib/components/workspace-tabs/workspace-tabs.js.map +1 -1
  184. package/lib/hooks/use-effect-on-change.d.ts +3 -0
  185. package/lib/hooks/use-effect-on-change.d.ts.map +1 -0
  186. package/lib/hooks/use-effect-on-change.js +19 -0
  187. package/lib/hooks/use-effect-on-change.js.map +1 -0
  188. package/lib/hooks/use-formatted-date.d.ts +2 -0
  189. package/lib/hooks/use-formatted-date.d.ts.map +1 -0
  190. package/lib/hooks/use-formatted-date.js +20 -0
  191. package/lib/hooks/use-formatted-date.js.map +1 -0
  192. package/lib/hooks/use-scrollbars.d.ts +11 -0
  193. package/lib/hooks/use-scrollbars.d.ts.map +1 -0
  194. package/lib/hooks/use-scrollbars.js +117 -0
  195. package/lib/hooks/use-scrollbars.js.map +1 -0
  196. package/lib/hooks/use-theme.d.ts +11 -13
  197. package/lib/hooks/use-theme.d.ts.map +1 -1
  198. package/lib/hooks/use-theme.js +17 -21
  199. package/lib/hooks/use-theme.js.map +1 -1
  200. package/lib/hooks/use-toast.d.ts +2 -0
  201. package/lib/hooks/use-toast.d.ts.map +1 -1
  202. package/lib/hooks/use-toast.js +59 -37
  203. package/lib/hooks/use-toast.js.map +1 -1
  204. package/lib/index.d.ts +16 -8
  205. package/lib/index.d.ts.map +1 -1
  206. package/lib/index.js +34 -11
  207. package/lib/index.js.map +1 -1
  208. package/lib/utils/format-date.d.ts +2 -0
  209. package/lib/utils/format-date.d.ts.map +1 -0
  210. package/lib/utils/format-date.js +47 -0
  211. package/lib/utils/format-date.js.map +1 -0
  212. package/package.json +53 -44
  213. package/lib/components/checkbox.d.ts +0 -5
  214. package/lib/components/checkbox.d.ts.map +0 -1
  215. package/lib/components/checkbox.js +0 -15
  216. package/lib/components/checkbox.js.map +0 -1
  217. package/lib/components/document-list/font-awesome-icon.d.ts +0 -14
  218. package/lib/components/document-list/font-awesome-icon.d.ts.map +0 -1
  219. package/lib/components/document-list/font-awesome-icon.js +0 -29
  220. package/lib/components/document-list/font-awesome-icon.js.map +0 -1
  221. package/lib/components/toggle.d.ts +0 -5
  222. package/lib/components/toggle.d.ts.map +0 -1
  223. package/lib/components/toggle.js +0 -15
  224. package/lib/components/toggle.js.map +0 -1
@@ -0,0 +1,817 @@
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
+ exports.Combobox = void 0;
30
+ const react_1 = __importStar(require("react"));
31
+ const clone_1 = __importDefault(require("lodash/clone"));
32
+ const isArray_1 = __importDefault(require("lodash/isArray"));
33
+ const isEqual_1 = __importDefault(require("lodash/isEqual"));
34
+ const isNull_1 = __importDefault(require("lodash/isNull"));
35
+ const isString_1 = __importDefault(require("lodash/isString"));
36
+ const isUndefined_1 = __importDefault(require("lodash/isUndefined"));
37
+ const prop_types_1 = __importDefault(require("prop-types"));
38
+ const emotion_1 = require("@leafygreen-ui/emotion");
39
+ const hooks_1 = require("@leafygreen-ui/hooks");
40
+ const icon_1 = __importDefault(require("@leafygreen-ui/icon"));
41
+ const icon_button_1 = __importDefault(require("@leafygreen-ui/icon-button"));
42
+ const leafygreen_provider_1 = require("@leafygreen-ui/leafygreen-provider");
43
+ const lib_1 = require("@leafygreen-ui/lib");
44
+ const palette_1 = require("@leafygreen-ui/palette");
45
+ const typography_1 = require("@leafygreen-ui/typography");
46
+ const ComboboxMenu_1 = require("./ComboboxMenu/ComboboxMenu");
47
+ const Chip_1 = require("./Chip");
48
+ const Combobox_styles_1 = require("./Combobox.styles");
49
+ const Combobox_types_1 = require("./Combobox.types");
50
+ const ComboboxContext_1 = require("./ComboboxContext");
51
+ const ComboboxGroup_1 = require("./ComboboxGroup");
52
+ const ComboboxOption_1 = require("./ComboboxOption");
53
+ const utils_1 = require("./utils");
54
+ const tokens_1 = require("@leafygreen-ui/tokens");
55
+ const descriptionWidth = tokens_1.spacing[5] * 14;
56
+ const popoverMenuStyles = (width, containsDescription) => {
57
+ if (!containsDescription) {
58
+ return (0, emotion_1.css) `
59
+ width: ${width}px;
60
+ `;
61
+ }
62
+ const dropdownWidth = width + descriptionWidth;
63
+ return (0, emotion_1.css) `
64
+ width: ${dropdownWidth}px;
65
+ margin-left: ${(dropdownWidth / 2) - (width / 2)}px;
66
+ `;
67
+ };
68
+ function Combobox({ children, label, description, placeholder = 'Select', 'aria-label': ariaLabel, disabled = false, size = Combobox_types_1.ComboboxSize.Default, darkMode: darkModeProp, state = 'none', errorMessage, searchState = 'unset', searchEmptyMessage = 'No results found', searchErrorMessage = 'Could not get results!', searchLoadingMessage = 'Loading results...', filteredOptions, onFilter, clearable = true, onClear, overflow = 'expand-y', multiselect = false, initialValue, onChange, value, chipTruncationLocation, chipCharacterLimit = 12, className, usePortal = true, portalClassName, portalContainer, scrollContainer, popoverZIndex, popoverClassName, ...rest }) {
69
+ const { darkMode, theme } = (0, leafygreen_provider_1.useDarkMode)(darkModeProp);
70
+ const getOptionRef = (0, hooks_1.useDynamicRefs)({ prefix: 'option' });
71
+ const getChipRef = (0, hooks_1.useDynamicRefs)({ prefix: 'chip' });
72
+ const inputId = (0, hooks_1.useIdAllocator)({ prefix: 'combobox-input' });
73
+ const labelId = (0, hooks_1.useIdAllocator)({ prefix: 'combobox-label' });
74
+ const menuId = (0, hooks_1.useIdAllocator)({ prefix: 'combobox-menu' });
75
+ const comboboxRef = (0, react_1.useRef)(null);
76
+ const clearButtonRef = (0, react_1.useRef)(null);
77
+ const inputWrapperRef = (0, react_1.useRef)(null);
78
+ const inputRef = (0, react_1.useRef)(null);
79
+ const menuRef = (0, react_1.useRef)(null);
80
+ const [isOpen, setOpen] = (0, react_1.useState)(false);
81
+ const wasOpen = (0, hooks_1.usePrevious)(isOpen);
82
+ const [highlightedOption, setHighlightedOption] = (0, react_1.useState)(null);
83
+ const [selection, setSelection] = (0, react_1.useState)(null);
84
+ const prevSelection = (0, hooks_1.usePrevious)(selection);
85
+ const [inputValue, setInputValue] = (0, react_1.useState)('');
86
+ const prevValue = (0, hooks_1.usePrevious)(inputValue);
87
+ const [focusedChip, setFocusedChip] = (0, react_1.useState)(null);
88
+ const doesSelectionExist = !(0, isNull_1.default)(selection) &&
89
+ (((0, isArray_1.default)(selection) && selection.length > 0) || (0, isString_1.default)(selection));
90
+ const placeholderValue = multiselect && (0, isArray_1.default)(selection) && selection.length > 0
91
+ ? undefined
92
+ : placeholder;
93
+ const closeMenu = () => setOpen(false);
94
+ const openMenu = () => setOpen(true);
95
+ const allOptions = (0, react_1.useMemo)(() => (0, utils_1.flattenChildren)(children), [children]);
96
+ const isMultiselect = (0, react_1.useCallback)((val) => {
97
+ if (multiselect && (typeof val == 'string' || typeof val == 'number')) {
98
+ lib_1.consoleOnce.error(`Error in Combobox: multiselect is set to \`true\`, but received a ${typeof val} value: "${val}"`);
99
+ }
100
+ else if (!multiselect && (0, isArray_1.default)(val)) {
101
+ lib_1.consoleOnce.error('Error in Combobox: multiselect is set to `false`, but received an Array value');
102
+ }
103
+ return multiselect && (0, isArray_1.default)(val);
104
+ }, [multiselect]);
105
+ const setInputFocus = (0, react_1.useCallback)((cursorPos) => {
106
+ if (!disabled && inputRef && inputRef.current) {
107
+ inputRef.current.focus();
108
+ if (!(0, isUndefined_1.default)(cursorPos)) {
109
+ inputRef.current.setSelectionRange(cursorPos, cursorPos);
110
+ }
111
+ }
112
+ }, [disabled]);
113
+ const updateSelection = (0, react_1.useCallback)((value) => {
114
+ if (isMultiselect(selection)) {
115
+ const newSelection = (0, clone_1.default)(selection);
116
+ if ((0, isNull_1.default)(value)) {
117
+ newSelection.length = 0;
118
+ }
119
+ else {
120
+ if (selection.includes(value)) {
121
+ newSelection.splice(newSelection.indexOf(value), 1);
122
+ }
123
+ else {
124
+ newSelection.push(value);
125
+ setInputValue('');
126
+ }
127
+ }
128
+ setSelection(newSelection);
129
+ onChange === null || onChange === void 0 ? void 0 : onChange(newSelection);
130
+ }
131
+ else {
132
+ const newSelection = value;
133
+ setSelection(newSelection);
134
+ onChange === null || onChange === void 0 ? void 0 : onChange(newSelection);
135
+ }
136
+ }, [isMultiselect, onChange, selection]);
137
+ const isValueCurrentSelection = (0, react_1.useCallback)((value) => {
138
+ return isMultiselect(selection)
139
+ ? selection.includes(value)
140
+ : value === selection;
141
+ }, [isMultiselect, selection]);
142
+ const isTextCurrentSelection = (0, react_1.useCallback)((text) => {
143
+ const value = (0, utils_1.getValueForDisplayName)(text, allOptions);
144
+ return isValueCurrentSelection(value);
145
+ }, [allOptions, isValueCurrentSelection]);
146
+ const isOptionDisabled = (option) => {
147
+ if (typeof option === 'string') {
148
+ const optionObj = (0, utils_1.getOptionObjectFromValue)(option, allOptions);
149
+ return !!(optionObj === null || optionObj === void 0 ? void 0 : optionObj.isDisabled);
150
+ }
151
+ else {
152
+ return !!option.isDisabled;
153
+ }
154
+ };
155
+ const shouldOptionBeVisible = (0, react_1.useCallback)((option) => {
156
+ const value = typeof option === 'string' ? option : option.value;
157
+ if (filteredOptions && filteredOptions.length > 0) {
158
+ return filteredOptions.includes(value);
159
+ }
160
+ if (isTextCurrentSelection(inputValue)) {
161
+ return true;
162
+ }
163
+ const displayName = typeof option === 'string'
164
+ ? (0, utils_1.getDisplayNameForValue)(value, allOptions)
165
+ : option.displayName;
166
+ const isValueInDisplayName = displayName
167
+ .toLowerCase()
168
+ .includes(inputValue.toLowerCase());
169
+ return isValueInDisplayName;
170
+ }, [filteredOptions, isTextCurrentSelection, inputValue, allOptions]);
171
+ const visibleOptions = (0, react_1.useMemo)(() => allOptions.filter(shouldOptionBeVisible), [allOptions, shouldOptionBeVisible]);
172
+ const isValueValid = (0, react_1.useCallback)((value) => {
173
+ return value ? !!allOptions.find(opt => opt.value === value) : false;
174
+ }, [allOptions]);
175
+ const getIndexOfValue = (0, react_1.useCallback)((value) => {
176
+ return visibleOptions
177
+ ? visibleOptions.findIndex(option => option.value === value)
178
+ : -1;
179
+ }, [visibleOptions]);
180
+ const getValueAtIndex = (0, react_1.useCallback)((index) => {
181
+ if (visibleOptions && visibleOptions.length >= index) {
182
+ const option = visibleOptions[index];
183
+ return option ? option.value : undefined;
184
+ }
185
+ }, [visibleOptions]);
186
+ const getActiveChipIndex = (0, react_1.useCallback)(() => isMultiselect(selection)
187
+ ? selection.findIndex(value => { var _a, _b; return (_b = (_a = getChipRef(value)) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.contains(document.activeElement); })
188
+ : -1, [getChipRef, isMultiselect, selection]);
189
+ const [focusedElementName, trackFocusedElement] = (0, react_1.useState)();
190
+ const isElementFocused = (elementName) => elementName === focusedElementName;
191
+ const updateHighlightedOption = (0, react_1.useCallback)((direction) => {
192
+ var _a;
193
+ const optionsCount = (_a = visibleOptions === null || visibleOptions === void 0 ? void 0 : visibleOptions.length) !== null && _a !== void 0 ? _a : 0;
194
+ const lastIndex = optionsCount - 1 > 0 ? optionsCount - 1 : 0;
195
+ const indexOfHighlight = getIndexOfValue(highlightedOption);
196
+ if (direction && isOpen) {
197
+ setFocusedChip(null);
198
+ setInputFocus();
199
+ }
200
+ switch (direction) {
201
+ case 'next': {
202
+ const newValue = indexOfHighlight + 1 < optionsCount
203
+ ? getValueAtIndex(indexOfHighlight + 1)
204
+ : getValueAtIndex(0);
205
+ setHighlightedOption(newValue !== null && newValue !== void 0 ? newValue : null);
206
+ break;
207
+ }
208
+ case 'prev': {
209
+ const newValue = indexOfHighlight - 1 >= 0
210
+ ? getValueAtIndex(indexOfHighlight - 1)
211
+ : getValueAtIndex(lastIndex);
212
+ setHighlightedOption(newValue !== null && newValue !== void 0 ? newValue : null);
213
+ break;
214
+ }
215
+ case 'last': {
216
+ const newValue = getValueAtIndex(lastIndex);
217
+ setHighlightedOption(newValue !== null && newValue !== void 0 ? newValue : null);
218
+ break;
219
+ }
220
+ case 'first':
221
+ default: {
222
+ const newValue = getValueAtIndex(0);
223
+ setHighlightedOption(newValue !== null && newValue !== void 0 ? newValue : null);
224
+ }
225
+ }
226
+ }, [
227
+ highlightedOption,
228
+ getIndexOfValue,
229
+ getValueAtIndex,
230
+ isOpen,
231
+ setInputFocus,
232
+ visibleOptions === null || visibleOptions === void 0 ? void 0 : visibleOptions.length,
233
+ ]);
234
+ const updateFocusedChip = (0, react_1.useCallback)((direction, relativeToIndex) => {
235
+ if (isMultiselect(selection)) {
236
+ switch (direction) {
237
+ case 'next': {
238
+ const referenceChipIndex = relativeToIndex !== null && relativeToIndex !== void 0 ? relativeToIndex : getActiveChipIndex();
239
+ const nextChipIndex = referenceChipIndex + 1 < selection.length
240
+ ? referenceChipIndex + 1
241
+ : selection.length - 1;
242
+ const nextChipValue = selection[nextChipIndex];
243
+ setFocusedChip(nextChipValue);
244
+ break;
245
+ }
246
+ case 'prev': {
247
+ const referenceChipIndex = relativeToIndex !== null && relativeToIndex !== void 0 ? relativeToIndex : getActiveChipIndex();
248
+ const prevChipIndex = referenceChipIndex > 0
249
+ ? referenceChipIndex - 1
250
+ : referenceChipIndex < 0
251
+ ? selection.length - 1
252
+ : 0;
253
+ const prevChipValue = selection[prevChipIndex];
254
+ setFocusedChip(prevChipValue);
255
+ break;
256
+ }
257
+ case 'first': {
258
+ const firstChipValue = selection[0];
259
+ setFocusedChip(firstChipValue);
260
+ break;
261
+ }
262
+ case 'last': {
263
+ const lastChipValue = selection[selection.length - 1];
264
+ setFocusedChip(lastChipValue);
265
+ break;
266
+ }
267
+ default:
268
+ setFocusedChip(null);
269
+ break;
270
+ }
271
+ }
272
+ }, [getActiveChipIndex, isMultiselect, selection]);
273
+ const handleArrowKey = (0, react_1.useCallback)((direction, event) => {
274
+ var _a, _b, _c, _d, _e;
275
+ if (direction)
276
+ setHighlightedOption(null);
277
+ switch (direction) {
278
+ case 'right':
279
+ switch (focusedElementName) {
280
+ case Combobox_types_1.ComboboxElement.Input: {
281
+ if (((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.selectionEnd) ===
282
+ ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.value.length)) {
283
+ (_c = clearButtonRef.current) === null || _c === void 0 ? void 0 : _c.focus();
284
+ }
285
+ break;
286
+ }
287
+ case Combobox_types_1.ComboboxElement.FirstChip:
288
+ case Combobox_types_1.ComboboxElement.MiddleChip:
289
+ case Combobox_types_1.ComboboxElement.LastChip: {
290
+ if (focusedElementName === Combobox_types_1.ComboboxElement.LastChip ||
291
+ (selection === null || selection === void 0 ? void 0 : selection.length) === 1) {
292
+ setInputFocus(0);
293
+ updateFocusedChip(null);
294
+ event.preventDefault();
295
+ break;
296
+ }
297
+ updateFocusedChip('next');
298
+ break;
299
+ }
300
+ case Combobox_types_1.ComboboxElement.ClearButton:
301
+ default:
302
+ break;
303
+ }
304
+ break;
305
+ case 'left':
306
+ switch (focusedElementName) {
307
+ case Combobox_types_1.ComboboxElement.ClearButton: {
308
+ event.preventDefault();
309
+ setInputFocus((_d = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _d === void 0 ? void 0 : _d.value.length);
310
+ break;
311
+ }
312
+ case Combobox_types_1.ComboboxElement.Input:
313
+ case Combobox_types_1.ComboboxElement.MiddleChip:
314
+ case Combobox_types_1.ComboboxElement.LastChip: {
315
+ if (isMultiselect(selection)) {
316
+ if (focusedElementName === Combobox_types_1.ComboboxElement.Input &&
317
+ ((_e = inputRef.current) === null || _e === void 0 ? void 0 : _e.selectionStart) !== 0) {
318
+ break;
319
+ }
320
+ updateFocusedChip('prev');
321
+ }
322
+ break;
323
+ }
324
+ case Combobox_types_1.ComboboxElement.FirstChip:
325
+ default:
326
+ break;
327
+ }
328
+ break;
329
+ default:
330
+ updateFocusedChip(null);
331
+ break;
332
+ }
333
+ }, [
334
+ focusedElementName,
335
+ isMultiselect,
336
+ selection,
337
+ setInputFocus,
338
+ updateFocusedChip,
339
+ ]);
340
+ (0, react_1.useEffect)(() => {
341
+ if (inputValue !== prevValue) {
342
+ updateHighlightedOption('first');
343
+ }
344
+ }, [inputValue, isOpen, prevValue, updateHighlightedOption]);
345
+ (0, react_1.useEffect)(() => {
346
+ if (highlightedOption) {
347
+ const focusedElementRef = getOptionRef(highlightedOption);
348
+ if (focusedElementRef && focusedElementRef.current && menuRef.current) {
349
+ const { offsetTop: optionTop } = focusedElementRef.current;
350
+ const { scrollTop: menuScroll, offsetHeight: menuHeight } = menuRef.current;
351
+ if (optionTop > menuHeight || optionTop < menuScroll) {
352
+ menuRef.current.scrollTop = optionTop;
353
+ }
354
+ }
355
+ }
356
+ }, [highlightedOption, getOptionRef]);
357
+ const renderOption = (0, react_1.useCallback)((child) => {
358
+ if ((0, lib_1.isComponentType)(child, 'ComboboxOption')) {
359
+ const { value, displayName } = (0, utils_1.getNameAndValue)(child.props);
360
+ if (shouldOptionBeVisible(value)) {
361
+ const { className, glyph, disabled } = child.props;
362
+ const index = allOptions.findIndex(opt => opt.value === value);
363
+ const isFocused = highlightedOption === value;
364
+ const isSelected = isMultiselect(selection)
365
+ ? selection.includes(value)
366
+ : selection === value;
367
+ const setSelected = () => {
368
+ setHighlightedOption(value);
369
+ updateSelection(value);
370
+ setInputFocus();
371
+ if (value === selection) {
372
+ closeMenu();
373
+ }
374
+ };
375
+ const optionRef = getOptionRef(value);
376
+ return (react_1.default.createElement(ComboboxOption_1.InternalComboboxOption, { value: value, displayName: displayName, isFocused: isFocused, isSelected: isSelected, disabled: disabled, setSelected: setSelected, glyph: glyph, className: className, index: index, ref: optionRef, description: child.props.description }));
377
+ }
378
+ }
379
+ else if ((0, lib_1.isComponentType)(child, 'ComboboxGroup')) {
380
+ const nestedChildren = react_1.default.Children.map(child.props.children, renderOption);
381
+ if (nestedChildren && (nestedChildren === null || nestedChildren === void 0 ? void 0 : nestedChildren.length) > 0) {
382
+ return (react_1.default.createElement(ComboboxGroup_1.InternalComboboxGroup, { label: child.props.label, className: child.props.className }, react_1.default.Children.map(nestedChildren, renderOption)));
383
+ }
384
+ }
385
+ }, [
386
+ allOptions,
387
+ getOptionRef,
388
+ highlightedOption,
389
+ isMultiselect,
390
+ selection,
391
+ setInputFocus,
392
+ shouldOptionBeVisible,
393
+ updateSelection,
394
+ ]);
395
+ const renderedOptionsJSX = (0, react_1.useMemo)(() => react_1.default.Children.map(children, renderOption), [children, renderOption]);
396
+ const renderedChips = (0, react_1.useMemo)(() => {
397
+ if (isMultiselect(selection)) {
398
+ return selection.filter(isValueValid).map((value, index) => {
399
+ const displayName = (0, utils_1.getDisplayNameForValue)(value, allOptions);
400
+ const isFocused = focusedChip === value;
401
+ const chipRef = getChipRef(value);
402
+ const isLastChip = index >= selection.length - 1;
403
+ const onRemove = () => {
404
+ if (isLastChip) {
405
+ setInputFocus();
406
+ updateFocusedChip(null);
407
+ }
408
+ else {
409
+ updateFocusedChip('next', index);
410
+ }
411
+ updateSelection(value);
412
+ };
413
+ const onFocus = () => {
414
+ setFocusedChip(value);
415
+ };
416
+ return (react_1.default.createElement(Chip_1.Chip, { key: value, displayName: displayName, isFocused: isFocused, onRemove: onRemove, onFocus: onFocus, ref: chipRef }));
417
+ });
418
+ }
419
+ }, [
420
+ isMultiselect,
421
+ selection,
422
+ isValueValid,
423
+ allOptions,
424
+ focusedChip,
425
+ getChipRef,
426
+ updateSelection,
427
+ setInputFocus,
428
+ updateFocusedChip,
429
+ ]);
430
+ const renderedInputIcons = (0, react_1.useMemo)(() => {
431
+ const handleClearButtonClick = (e) => {
432
+ if (!disabled) {
433
+ updateSelection(null);
434
+ onClear === null || onClear === void 0 ? void 0 : onClear(e);
435
+ onFilter === null || onFilter === void 0 ? void 0 : onFilter('');
436
+ if (!isOpen) {
437
+ openMenu();
438
+ }
439
+ }
440
+ };
441
+ return (react_1.default.createElement(react_1.default.Fragment, null,
442
+ clearable && doesSelectionExist && (react_1.default.createElement(icon_button_1.default, { "aria-label": "Clear selection", "aria-disabled": disabled, disabled: disabled, ref: clearButtonRef, onClick: handleClearButtonClick, onFocus: handleClearButtonFocus, className: (0, emotion_1.cx)(Combobox_styles_1.clearButtonStyle), darkMode: darkMode },
443
+ react_1.default.createElement(icon_1.default, { glyph: "XWithCircle" }))),
444
+ state === 'error' ? (react_1.default.createElement(icon_1.default, { glyph: "Warning", color: darkMode ? palette_1.palette.red.light1 : palette_1.palette.red.base, className: (0, Combobox_styles_1.endIconStyle)(size) })) : (react_1.default.createElement(icon_1.default, { glyph: "CaretDown", className: (0, Combobox_styles_1.endIconStyle)(size) }))));
445
+ }, [
446
+ clearable,
447
+ doesSelectionExist,
448
+ disabled,
449
+ state,
450
+ darkMode,
451
+ size,
452
+ updateSelection,
453
+ onClear,
454
+ onFilter,
455
+ isOpen,
456
+ ]);
457
+ const withIcons = (0, react_1.useMemo)(() => allOptions.some(opt => opt.hasGlyph), [allOptions]);
458
+ const onCloseMenu = (0, react_1.useCallback)(() => {
459
+ var _a;
460
+ if (!isMultiselect(selection) && selection === prevSelection) {
461
+ const exactMatchedOption = visibleOptions.find(option => option.displayName === inputValue || option.value === inputValue);
462
+ if (exactMatchedOption && !value) {
463
+ setSelection(exactMatchedOption.value);
464
+ }
465
+ else {
466
+ const displayName = (_a = (0, utils_1.getDisplayNameForValue)(selection, allOptions)) !== null && _a !== void 0 ? _a : '';
467
+ setInputValue(displayName);
468
+ }
469
+ }
470
+ }, [
471
+ allOptions,
472
+ inputValue,
473
+ isMultiselect,
474
+ prevSelection,
475
+ selection,
476
+ value,
477
+ visibleOptions,
478
+ ]);
479
+ const onSelect = (0, react_1.useCallback)(() => {
480
+ var _a;
481
+ if (doesSelectionExist) {
482
+ if (isMultiselect(selection)) {
483
+ scrollInputToEnd();
484
+ }
485
+ else if (!isMultiselect(selection)) {
486
+ const displayName = (_a = (0, utils_1.getDisplayNameForValue)(selection, allOptions)) !== null && _a !== void 0 ? _a : '';
487
+ setInputValue(displayName);
488
+ closeMenu();
489
+ }
490
+ }
491
+ else {
492
+ setInputValue('');
493
+ }
494
+ }, [doesSelectionExist, allOptions, isMultiselect, selection]);
495
+ (0, react_1.useEffect)(() => {
496
+ var _a;
497
+ if (initialValue) {
498
+ if ((0, isArray_1.default)(initialValue)) {
499
+ const filteredValue = (_a = initialValue.filter(value => isValueValid(value))) !== null && _a !== void 0 ? _a : [];
500
+ setSelection(filteredValue);
501
+ }
502
+ else {
503
+ if (isValueValid(initialValue)) {
504
+ setSelection(initialValue);
505
+ }
506
+ }
507
+ }
508
+ else {
509
+ setSelection((0, Combobox_types_1.getNullSelection)(multiselect));
510
+ }
511
+ }, []);
512
+ (0, react_1.useEffect)(() => {
513
+ if (!(0, isUndefined_1.default)(value) && value !== prevValue) {
514
+ if ((0, isNull_1.default)(value)) {
515
+ setSelection(null);
516
+ }
517
+ else if (isMultiselect(value)) {
518
+ const newSelection = value.filter(isValueValid);
519
+ setSelection(newSelection);
520
+ }
521
+ else {
522
+ setSelection(isValueValid(value) ? value : null);
523
+ }
524
+ }
525
+ }, [isMultiselect, isValueValid, prevValue, value]);
526
+ (0, react_1.useEffect)(() => {
527
+ if (!(0, isEqual_1.default)(selection, prevSelection)) {
528
+ onSelect();
529
+ }
530
+ }, [onSelect, prevSelection, selection]);
531
+ (0, react_1.useEffect)(() => {
532
+ if (!isOpen && wasOpen) {
533
+ onCloseMenu();
534
+ }
535
+ }, [isOpen, wasOpen, onCloseMenu]);
536
+ const [popoverMenuWidth, setPopoverMenuWidth] = (0, react_1.useState)(0);
537
+ (0, react_1.useEffect)(() => {
538
+ var _a, _b;
539
+ setPopoverMenuWidth((_b = (_a = comboboxRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) !== null && _b !== void 0 ? _b : 0);
540
+ }, [comboboxRef, isOpen, highlightedOption, selection]);
541
+ const handleTransitionEnd = () => {
542
+ var _a, _b;
543
+ setPopoverMenuWidth((_b = (_a = comboboxRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) !== null && _b !== void 0 ? _b : 0);
544
+ };
545
+ const handleInputWrapperMousedown = (e) => {
546
+ if (disabled) {
547
+ e.preventDefault();
548
+ }
549
+ };
550
+ const handleComboboxClick = (e) => {
551
+ if (e.target !== inputRef.current) {
552
+ let cursorPos = 0;
553
+ if (inputRef.current) {
554
+ const mouseX = e.nativeEvent.offsetX;
555
+ const inputRight = inputRef.current.offsetLeft + inputRef.current.clientWidth;
556
+ cursorPos = mouseX > inputRight ? inputValue.length : 0;
557
+ }
558
+ setInputFocus(cursorPos);
559
+ }
560
+ openMenu();
561
+ };
562
+ const handleComboboxFocus = (e) => {
563
+ scrollInputToEnd();
564
+ trackFocusedElement(getNameFromElement(e.target));
565
+ };
566
+ const handleInputChange = ({ target: { value }, }) => {
567
+ setInputValue(value);
568
+ onFilter === null || onFilter === void 0 ? void 0 : onFilter(value);
569
+ };
570
+ const handleClearButtonFocus = () => {
571
+ setHighlightedOption(null);
572
+ };
573
+ const handleKeyDown = (event) => {
574
+ var _a, _b, _c;
575
+ const isFocusInMenu = (_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.contains(document.activeElement);
576
+ const isFocusOnCombobox = (_b = comboboxRef.current) === null || _b === void 0 ? void 0 : _b.contains(document.activeElement);
577
+ const isFocusInComponent = isFocusOnCombobox || isFocusInMenu;
578
+ if (isFocusInComponent) {
579
+ if (event.ctrlKey || event.shiftKey || event.altKey) {
580
+ return;
581
+ }
582
+ switch (event.keyCode) {
583
+ case lib_1.keyMap.Tab: {
584
+ switch (focusedElementName) {
585
+ case 'Input': {
586
+ if (!doesSelectionExist) {
587
+ closeMenu();
588
+ updateHighlightedOption('first');
589
+ updateFocusedChip(null);
590
+ }
591
+ break;
592
+ }
593
+ case 'LastChip': {
594
+ updateFocusedChip(null);
595
+ break;
596
+ }
597
+ case 'FirstChip':
598
+ case 'MiddleChip': {
599
+ break;
600
+ }
601
+ case 'ClearButton':
602
+ default:
603
+ break;
604
+ }
605
+ break;
606
+ }
607
+ case lib_1.keyMap.Escape: {
608
+ closeMenu();
609
+ updateHighlightedOption('first');
610
+ break;
611
+ }
612
+ case lib_1.keyMap.Enter: {
613
+ if (!isOpen) {
614
+ openMenu();
615
+ }
616
+ else if (focusedElementName === Combobox_types_1.ComboboxElement.Input &&
617
+ !(0, isNull_1.default)(highlightedOption) &&
618
+ !isOptionDisabled(highlightedOption)) {
619
+ updateSelection(highlightedOption);
620
+ }
621
+ else if (focusedElementName === Combobox_types_1.ComboboxElement.ClearButton) {
622
+ updateSelection(null);
623
+ setInputFocus();
624
+ }
625
+ break;
626
+ }
627
+ case lib_1.keyMap.Backspace: {
628
+ if (isMultiselect(selection)) {
629
+ if (focusedElementName === 'Input' &&
630
+ ((_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.selectionStart) === 0) {
631
+ updateFocusedChip('last');
632
+ }
633
+ }
634
+ openMenu();
635
+ break;
636
+ }
637
+ case lib_1.keyMap.ArrowDown: {
638
+ if (isOpen) {
639
+ event.preventDefault();
640
+ updateHighlightedOption('next');
641
+ }
642
+ else {
643
+ openMenu();
644
+ }
645
+ break;
646
+ }
647
+ case lib_1.keyMap.ArrowUp: {
648
+ if (isOpen) {
649
+ event.preventDefault();
650
+ updateHighlightedOption('prev');
651
+ }
652
+ else {
653
+ openMenu();
654
+ }
655
+ break;
656
+ }
657
+ case lib_1.keyMap.ArrowRight: {
658
+ handleArrowKey('right', event);
659
+ break;
660
+ }
661
+ case lib_1.keyMap.ArrowLeft: {
662
+ handleArrowKey('left', event);
663
+ break;
664
+ }
665
+ default: {
666
+ if (!isOpen) {
667
+ openMenu();
668
+ }
669
+ }
670
+ }
671
+ }
672
+ };
673
+ (0, hooks_1.useEventListener)('mousedown', (mousedown) => {
674
+ if (!doesComponentContainEventTarget(mousedown)) {
675
+ mousedown.preventDefault();
676
+ mousedown.stopPropagation();
677
+ }
678
+ }, {
679
+ enabled: isOpen,
680
+ });
681
+ (0, hooks_1.useEventListener)('click', (click) => {
682
+ if (!doesComponentContainEventTarget(click)) {
683
+ click.stopPropagation();
684
+ closeMenu();
685
+ }
686
+ }, {
687
+ options: { capture: true },
688
+ enabled: isOpen,
689
+ });
690
+ const popoverProps = {
691
+ popoverZIndex,
692
+ ...(usePortal
693
+ ? {
694
+ usePortal,
695
+ portalClassName,
696
+ portalContainer,
697
+ scrollContainer,
698
+ }
699
+ : { usePortal }),
700
+ };
701
+ const isAnyOptionWithDescription = (0, react_1.useMemo)(() => {
702
+ var _a, _b;
703
+ const numberOfOptionsWithDescriptions = (_b = (_a = react_1.default.Children.map(children, (child) => { var _a; return (_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.description; })) === null || _a === void 0 ? void 0 : _a.filter(Boolean)) === null || _b === void 0 ? void 0 : _b.length;
704
+ return (numberOfOptionsWithDescriptions || 0) > 0;
705
+ }, [children]);
706
+ return (react_1.default.createElement(ComboboxContext_1.ComboboxContext.Provider, { value: {
707
+ multiselect,
708
+ darkMode,
709
+ theme,
710
+ size,
711
+ withIcons,
712
+ disabled,
713
+ isOpen,
714
+ state,
715
+ searchState,
716
+ chipTruncationLocation,
717
+ chipCharacterLimit,
718
+ inputValue,
719
+ searchInputSize: popoverMenuWidth,
720
+ } },
721
+ react_1.default.createElement("div", { className: (0, emotion_1.cx)((0, Combobox_styles_1.comboboxParentStyle)(size), className), ...rest },
722
+ (label || description) && (react_1.default.createElement("div", { className: Combobox_styles_1.labelDescriptionContainerStyle },
723
+ label && (react_1.default.createElement(typography_1.Label, { id: labelId, htmlFor: inputId, darkMode: darkMode }, label)),
724
+ description && (react_1.default.createElement(typography_1.Description, { darkMode: darkMode }, description)))),
725
+ react_1.default.createElement("div", { ref: comboboxRef, role: "combobox", "aria-expanded": isOpen, "aria-controls": menuId, "aria-owns": menuId, tabIndex: -1, onMouseDown: handleInputWrapperMousedown, onClick: handleComboboxClick, onFocus: handleComboboxFocus, onKeyDown: handleKeyDown, onTransitionEnd: handleTransitionEnd, className: (0, emotion_1.cx)(Combobox_styles_1.baseComboboxStyles, Combobox_styles_1.comboboxThemeStyles[theme], (0, Combobox_styles_1.comboboxSizeStyles)(size), {
726
+ [Combobox_styles_1.comboboxSelectionStyles]: clearable && doesSelectionExist,
727
+ [Combobox_styles_1.comboboxDisabledStyles[theme]]: disabled,
728
+ [Combobox_styles_1.comboboxErrorStyles[theme]]: state === Combobox_types_1.State.error,
729
+ [Combobox_styles_1.comboboxFocusStyle[theme]]: isElementFocused(Combobox_types_1.ComboboxElement.Input),
730
+ }) },
731
+ react_1.default.createElement("div", { ref: inputWrapperRef, className: (0, Combobox_styles_1.inputWrapperStyle)({
732
+ size,
733
+ overflow,
734
+ }) },
735
+ renderedChips,
736
+ react_1.default.createElement("input", { "aria-label": ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : label, "aria-autocomplete": "list", "aria-controls": menuId, "aria-labelledby": labelId, ref: inputRef, id: inputId, className: (0, emotion_1.cx)(Combobox_styles_1.baseInputElementStyle, Combobox_styles_1.inputElementSizeStyle[size], Combobox_styles_1.inputElementThemeStyle[theme], (0, Combobox_styles_1.inputElementTransitionStyles)(isOpen), {
737
+ [(0, Combobox_styles_1.multiselectInputElementStyle)(size, inputValue)]: isMultiselect(selection),
738
+ }), placeholder: placeholderValue, disabled: disabled !== null && disabled !== void 0 ? disabled : undefined, onChange: handleInputChange, value: inputValue, autoComplete: "off" })),
739
+ renderedInputIcons),
740
+ state === 'error' && errorMessage && (react_1.default.createElement("div", { className: (0, emotion_1.cx)(Combobox_styles_1.errorMessageThemeStyle[theme], Combobox_styles_1.errorMessageSizeStyle[size]) }, errorMessage)),
741
+ react_1.default.createElement(ComboboxMenu_1.ComboboxMenu, { id: menuId, labelId: labelId, refEl: comboboxRef, ref: menuRef, className: (0, emotion_1.cx)(popoverMenuStyles(popoverMenuWidth, isAnyOptionWithDescription), popoverClassName), searchLoadingMessage: searchLoadingMessage, searchErrorMessage: searchErrorMessage, searchEmptyMessage: searchEmptyMessage, ...popoverProps }, renderedOptionsJSX))));
742
+ function doesComponentContainEventTarget({ target }) {
743
+ var _a, _b;
744
+ return (((_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) ||
745
+ ((_b = comboboxRef.current) === null || _b === void 0 ? void 0 : _b.contains(target)) ||
746
+ false);
747
+ }
748
+ function scrollInputToEnd() {
749
+ if (inputWrapperRef && inputWrapperRef.current) {
750
+ inputWrapperRef.current.scrollLeft = inputWrapperRef.current.scrollWidth;
751
+ }
752
+ }
753
+ function getNameFromElement(element) {
754
+ var _a, _b, _c, _d;
755
+ if (!element)
756
+ return;
757
+ if ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.contains(element))
758
+ return Combobox_types_1.ComboboxElement.Input;
759
+ if ((_b = clearButtonRef.current) === null || _b === void 0 ? void 0 : _b.contains(element))
760
+ return Combobox_types_1.ComboboxElement.ClearButton;
761
+ const activeChipIndex = isMultiselect(selection)
762
+ ? selection.findIndex(value => { var _a, _b; return (_b = (_a = getChipRef(value)) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.contains(element); })
763
+ : -1;
764
+ if (isMultiselect(selection)) {
765
+ if (activeChipIndex === 0)
766
+ return Combobox_types_1.ComboboxElement.FirstChip;
767
+ if (activeChipIndex === selection.length - 1)
768
+ return Combobox_types_1.ComboboxElement.LastChip;
769
+ if (activeChipIndex > 0)
770
+ return Combobox_types_1.ComboboxElement.MiddleChip;
771
+ }
772
+ if ((_c = menuRef.current) === null || _c === void 0 ? void 0 : _c.contains(element))
773
+ return Combobox_types_1.ComboboxElement.Menu;
774
+ if ((_d = comboboxRef.current) === null || _d === void 0 ? void 0 : _d.contains(element))
775
+ return Combobox_types_1.ComboboxElement.Combobox;
776
+ }
777
+ }
778
+ exports.Combobox = Combobox;
779
+ Combobox.propTypes = {
780
+ multiselect: prop_types_1.default.bool,
781
+ value: prop_types_1.default.oneOfType([
782
+ prop_types_1.default.string,
783
+ prop_types_1.default.arrayOf(prop_types_1.default.string),
784
+ ]),
785
+ initialValue: prop_types_1.default.oneOfType([
786
+ prop_types_1.default.string,
787
+ prop_types_1.default.arrayOf(prop_types_1.default.string),
788
+ ]),
789
+ overflow: prop_types_1.default.oneOf(Object.values(Combobox_types_1.Overflow)),
790
+ darkMode: prop_types_1.default.bool,
791
+ label: prop_types_1.default.string,
792
+ 'aria-label': prop_types_1.default.string,
793
+ children: prop_types_1.default.node,
794
+ onChange: prop_types_1.default.func,
795
+ chipCharacterLimit: prop_types_1.default.number,
796
+ chipTruncationLocation: prop_types_1.default.oneOf(Object.values(Combobox_types_1.TruncationLocation)),
797
+ onClear: prop_types_1.default.func,
798
+ onFilter: prop_types_1.default.func,
799
+ clearable: prop_types_1.default.bool,
800
+ searchLoadingMessage: prop_types_1.default.string,
801
+ searchErrorMessage: prop_types_1.default.string,
802
+ searchEmptyMessage: prop_types_1.default.string,
803
+ searchState: prop_types_1.default.oneOf(Object.values(Combobox_types_1.SearchState)),
804
+ errorMessage: prop_types_1.default.string,
805
+ state: prop_types_1.default.oneOf(Object.values(Combobox_types_1.State)),
806
+ size: prop_types_1.default.oneOf(Object.values(Combobox_types_1.ComboboxSize)),
807
+ disabled: prop_types_1.default.bool,
808
+ description: prop_types_1.default.string,
809
+ placeholder: prop_types_1.default.string,
810
+ filteredOptions: prop_types_1.default.arrayOf(prop_types_1.default.string),
811
+ popoverZIndex: prop_types_1.default.number,
812
+ usePortal: prop_types_1.default.bool,
813
+ scrollContainer: prop_types_1.default.elementType,
814
+ portalContainer: prop_types_1.default.elementType,
815
+ portalClassName: prop_types_1.default.string,
816
+ };
817
+ //# sourceMappingURL=Combobox.js.map