@autoguru/overdrive 4.10.1 → 4.11.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 (260) hide show
  1. package/dist/components/Actions/Actions.js +21 -4
  2. package/dist/components/Actions/index.js +3 -1
  3. package/dist/components/Alert/Alert.css.js +28 -20
  4. package/dist/components/Alert/Alert.js +84 -26
  5. package/dist/components/Alert/index.js +3 -1
  6. package/dist/components/Anchor/Anchor.css.js +11 -3
  7. package/dist/components/Anchor/Anchor.js +53 -28
  8. package/dist/components/Anchor/index.js +3 -1
  9. package/dist/components/AutoSuggest/AutoSuggest.css.js +84 -76
  10. package/dist/components/AutoSuggest/AutoSuggest.js +621 -302
  11. package/dist/components/AutoSuggest/index.js +3 -1
  12. package/dist/components/AutoSuggest/useLayoutSuggestionVisible.js +29 -31
  13. package/dist/components/Badge/Badge.css.js +79 -71
  14. package/dist/components/Badge/Badge.js +44 -27
  15. package/dist/components/Badge/index.js +3 -1
  16. package/dist/components/Box/Box.js +122 -53
  17. package/dist/components/Box/argTypes.js +72 -105
  18. package/dist/components/Box/index.js +4 -2
  19. package/dist/components/Box/useBoxStyles.css.d.ts +4 -4
  20. package/dist/components/Box/useBoxStyles.css.d.ts.map +1 -1
  21. package/dist/components/Box/useBoxStyles.css.js +114 -89
  22. package/dist/components/Box/useBoxStyles.d.ts +7 -7
  23. package/dist/components/Box/useBoxStyles.d.ts.map +1 -1
  24. package/dist/components/Box/useBoxStyles.js +75 -47
  25. package/dist/components/BulletList/Bullet.css.js +49 -41
  26. package/dist/components/BulletList/Bullet.js +38 -24
  27. package/dist/components/BulletList/BulletList.css.js +13 -5
  28. package/dist/components/BulletList/BulletList.js +23 -10
  29. package/dist/components/BulletList/context.js +3 -1
  30. package/dist/components/BulletList/index.js +4 -2
  31. package/dist/components/BulletText/BulletText.css.js +21 -13
  32. package/dist/components/BulletText/BulletText.js +57 -16
  33. package/dist/components/BulletText/index.js +3 -1
  34. package/dist/components/Button/Button.css.js +243 -235
  35. package/dist/components/Button/Button.js +154 -91
  36. package/dist/components/Button/index.js +3 -1
  37. package/dist/components/CheckBox/CheckBox.css.js +28 -20
  38. package/dist/components/CheckBox/CheckBox.js +54 -16
  39. package/dist/components/CheckBox/index.js +3 -1
  40. package/dist/components/ColourInput/ColourInput.css.js +31 -23
  41. package/dist/components/ColourInput/ColourInput.js +70 -20
  42. package/dist/components/ColourInput/index.js +3 -1
  43. package/dist/components/Columns/Column.css.js +36 -26
  44. package/dist/components/Columns/Column.js +51 -16
  45. package/dist/components/Columns/Columns.css.js +39 -31
  46. package/dist/components/Columns/Columns.js +55 -22
  47. package/dist/components/Columns/index.js +4 -2
  48. package/dist/components/DateInput/DateInput.js +34 -7
  49. package/dist/components/DateInput/index.js +3 -1
  50. package/dist/components/DatePicker/DatePicker.css.js +40 -32
  51. package/dist/components/DatePicker/DatePicker.js +64 -23
  52. package/dist/components/DatePicker/index.js +3 -1
  53. package/dist/components/DividerLine/DividerLine.css.js +45 -37
  54. package/dist/components/DividerLine/DividerLine.js +22 -6
  55. package/dist/components/DividerLine/index.js +3 -1
  56. package/dist/components/Flyout/Flyout.js +41 -5
  57. package/dist/components/Flyout/index.js +3 -1
  58. package/dist/components/Heading/Heading.js +41 -21
  59. package/dist/components/Heading/index.js +3 -1
  60. package/dist/components/Icon/Icon.css.js +13 -5
  61. package/dist/components/Icon/Icon.js +26 -9
  62. package/dist/components/Icon/index.js +3 -1
  63. package/dist/components/Image/Image.js +23 -5
  64. package/dist/components/Image/ImageServerProvider.d.ts +1 -1
  65. package/dist/components/Image/ImageServerProvider.d.ts.map +1 -1
  66. package/dist/components/Image/ImageServerProvider.js +55 -35
  67. package/dist/components/Image/ResponsiveImage.js +46 -21
  68. package/dist/components/Image/SimpleImage.js +30 -2
  69. package/dist/components/Image/index.js +4 -2
  70. package/dist/components/Image/types.js +3 -1
  71. package/dist/components/Inline/Inline.js +74 -30
  72. package/dist/components/Inline/index.js +3 -1
  73. package/dist/components/LinearProgressIndicator/LinearProgressIndicator.css.js +56 -48
  74. package/dist/components/LinearProgressIndicator/LinearProgressIndicator.js +31 -7
  75. package/dist/components/LinearProgressIndicator/index.js +3 -1
  76. package/dist/components/LoadingBox/LoadingBox.css.js +26 -18
  77. package/dist/components/LoadingBox/LoadingBox.js +40 -7
  78. package/dist/components/LoadingBox/index.js +3 -1
  79. package/dist/components/Meta/Meta.css.js +16 -8
  80. package/dist/components/Meta/Meta.js +30 -8
  81. package/dist/components/Meta/index.js +3 -1
  82. package/dist/components/MinimalModal/MinimalModal.css.js +15 -7
  83. package/dist/components/MinimalModal/MinimalModal.js +67 -29
  84. package/dist/components/MinimalModal/index.js +3 -1
  85. package/dist/components/Modal/Modal.css.js +38 -30
  86. package/dist/components/Modal/Modal.js +129 -73
  87. package/dist/components/Modal/index.js +3 -1
  88. package/dist/components/NumberBubble/NumberBubble.css.js +12 -4
  89. package/dist/components/NumberBubble/NumberBubble.js +51 -23
  90. package/dist/components/NumberBubble/index.js +3 -1
  91. package/dist/components/NumberInput/NumberInput.js +67 -29
  92. package/dist/components/NumberInput/index.js +3 -1
  93. package/dist/components/OrderedList/OrderedList.css.js +16 -8
  94. package/dist/components/OrderedList/OrderedList.js +60 -26
  95. package/dist/components/OrderedList/index.js +3 -1
  96. package/dist/components/OutsideClick/OutsideClick.js +40 -35
  97. package/dist/components/OutsideClick/index.js +3 -1
  98. package/dist/components/OverdriveProvider/OverdriveProvider.js +33 -19
  99. package/dist/components/OverdriveProvider/index.js +3 -1
  100. package/dist/components/Pagination/Bubble.js +41 -19
  101. package/dist/components/Pagination/Pagination.css.js +28 -20
  102. package/dist/components/Pagination/Pagination.js +166 -67
  103. package/dist/components/Pagination/index.js +3 -1
  104. package/dist/components/Portal/Portal.js +40 -24
  105. package/dist/components/Portal/index.js +3 -1
  106. package/dist/components/Positioner/Positioner.css.js +14 -6
  107. package/dist/components/Positioner/Positioner.js +109 -85
  108. package/dist/components/Positioner/alignment.js +13 -10
  109. package/dist/components/Positioner/index.js +4 -2
  110. package/dist/components/ProgressBar/ProgressBar.css.js +14 -6
  111. package/dist/components/ProgressBar/ProgressBar.js +30 -12
  112. package/dist/components/ProgressBar/index.js +3 -1
  113. package/dist/components/ProgressBarGroup/ProgressBarGroup.css.js +12 -4
  114. package/dist/components/ProgressBarGroup/ProgressBarGroup.js +42 -14
  115. package/dist/components/ProgressBarGroup/index.js +3 -1
  116. package/dist/components/ProgressSpinner/ProgressSpinner.css.js +81 -73
  117. package/dist/components/ProgressSpinner/ProgressSpinner.js +32 -14
  118. package/dist/components/ProgressSpinner/index.js +3 -1
  119. package/dist/components/Radio/Radio.css.js +31 -23
  120. package/dist/components/Radio/Radio.js +58 -19
  121. package/dist/components/Radio/RadioGroup.js +32 -7
  122. package/dist/components/Radio/index.js +4 -2
  123. package/dist/components/Section/Section.css.js +13 -5
  124. package/dist/components/Section/Section.js +19 -4
  125. package/dist/components/Section/index.js +3 -1
  126. package/dist/components/SelectInput/SelectInput.css.js +19 -11
  127. package/dist/components/SelectInput/SelectInput.js +60 -11
  128. package/dist/components/SelectInput/index.js +3 -1
  129. package/dist/components/SimplePagination/SimplePagination.js +57 -17
  130. package/dist/components/SimplePagination/index.js +3 -1
  131. package/dist/components/Stack/Divider.css.js +12 -4
  132. package/dist/components/Stack/Divider.js +13 -4
  133. package/dist/components/Stack/Stack.css.js +18 -10
  134. package/dist/components/Stack/Stack.js +47 -23
  135. package/dist/components/Stack/index.js +3 -1
  136. package/dist/components/StandardModal/StandardModal.css.js +69 -57
  137. package/dist/components/StandardModal/StandardModal.js +127 -52
  138. package/dist/components/StandardModal/index.js +3 -1
  139. package/dist/components/StarRating/StarRating.css.js +16 -8
  140. package/dist/components/StarRating/StarRating.js +90 -46
  141. package/dist/components/StarRating/index.js +3 -1
  142. package/dist/components/Stepper/Stepper.css.js +46 -36
  143. package/dist/components/Stepper/Stepper.js +159 -66
  144. package/dist/components/Stepper/index.js +3 -1
  145. package/dist/components/Switch/Switch.css.js +54 -46
  146. package/dist/components/Switch/Switch.js +54 -21
  147. package/dist/components/Switch/index.js +3 -1
  148. package/dist/components/Table/Table.css.js +14 -6
  149. package/dist/components/Table/Table.js +29 -6
  150. package/dist/components/Table/TableCell.css.js +28 -20
  151. package/dist/components/Table/TableCell.js +41 -11
  152. package/dist/components/Table/TableHeadCell.css.js +61 -50
  153. package/dist/components/Table/TableHeadCell.js +86 -40
  154. package/dist/components/Table/TableRow.js +18 -3
  155. package/dist/components/Table/TableRowGroup.js +16 -3
  156. package/dist/components/Table/context.js +21 -10
  157. package/dist/components/Table/index.js +7 -5
  158. package/dist/components/Tabs/Tab.css.js +43 -35
  159. package/dist/components/Tabs/Tab.js +79 -49
  160. package/dist/components/Tabs/TabList.css.js +30 -22
  161. package/dist/components/Tabs/TabList.js +122 -67
  162. package/dist/components/Tabs/TabPane.css.js +11 -3
  163. package/dist/components/Tabs/TabPane.js +32 -15
  164. package/dist/components/Tabs/TabPanes.css.js +16 -8
  165. package/dist/components/Tabs/TabPanes.js +23 -6
  166. package/dist/components/Tabs/Tabs.js +22 -10
  167. package/dist/components/Tabs/index.js +7 -5
  168. package/dist/components/Text/Text.js +37 -15
  169. package/dist/components/Text/index.js +4 -2
  170. package/dist/components/Text/useTextStyles.css.js +42 -20
  171. package/dist/components/Text/useTextStyles.js +20 -5
  172. package/dist/components/TextAreaInput/TextAreaInput.js +35 -7
  173. package/dist/components/TextAreaInput/index.js +3 -1
  174. package/dist/components/TextBubble/TextBubble.css.js +13 -5
  175. package/dist/components/TextBubble/TextBubble.js +66 -29
  176. package/dist/components/TextBubble/index.js +3 -1
  177. package/dist/components/TextContainer/TextContainer.js +44 -9
  178. package/dist/components/TextContainer/index.js +3 -1
  179. package/dist/components/TextInput/TextInput.js +36 -5
  180. package/dist/components/TextInput/index.js +3 -1
  181. package/dist/components/TextLink/TextLink.css.js +23 -15
  182. package/dist/components/TextLink/TextLink.js +63 -24
  183. package/dist/components/TextLink/index.js +3 -1
  184. package/dist/components/ThemeOverrideProvider/ThemeOverrideDebugger.d.ts +3 -0
  185. package/dist/components/ThemeOverrideProvider/ThemeOverrideDebugger.d.ts.map +1 -0
  186. package/dist/components/ThemeOverrideProvider/ThemeOverrideDebugger.js +80 -0
  187. package/dist/components/ThemeOverrideProvider/ThemeOverrideProvider.d.ts +22 -0
  188. package/dist/components/ThemeOverrideProvider/ThemeOverrideProvider.d.ts.map +1 -0
  189. package/dist/components/ThemeOverrideProvider/ThemeOverrideProvider.js +39 -0
  190. package/dist/components/ThemeOverrideProvider/index.d.ts +3 -0
  191. package/dist/components/ThemeOverrideProvider/index.d.ts.map +1 -0
  192. package/dist/components/ThemeOverrideProvider/index.js +4 -0
  193. package/dist/components/ThemeOverrideProvider/useBuildThemeOverrides.d.ts +17 -0
  194. package/dist/components/ThemeOverrideProvider/useBuildThemeOverrides.d.ts.map +1 -0
  195. package/dist/components/ThemeOverrideProvider/useBuildThemeOverrides.js +97 -0
  196. package/dist/components/ThemeProvider/ThemeProvider.js +30 -11
  197. package/dist/components/ThemeProvider/index.js +3 -1
  198. package/dist/components/Toaster/Toast.css.js +18 -10
  199. package/dist/components/Toaster/Toast.js +222 -108
  200. package/dist/components/Toaster/index.js +3 -1
  201. package/dist/components/Tooltip/Tooltip.css.js +21 -9
  202. package/dist/components/Tooltip/Tooltip.js +72 -40
  203. package/dist/components/Tooltip/index.js +3 -1
  204. package/dist/components/VisuallyHidden/VisuallyHidden.css.js +13 -5
  205. package/dist/components/VisuallyHidden/VisuallyHidden.js +20 -4
  206. package/dist/components/VisuallyHidden/index.js +3 -1
  207. package/dist/components/index.d.ts +1 -0
  208. package/dist/components/index.d.ts.map +1 -1
  209. package/dist/components/index.js +59 -56
  210. package/dist/components/private/CheckableBase/CheckableBase.css.js +46 -38
  211. package/dist/components/private/CheckableBase/CheckableBase.js +91 -27
  212. package/dist/components/private/CheckableBase/index.js +3 -1
  213. package/dist/components/private/CheckableBase/useCheckableStyles.js +5 -3
  214. package/dist/components/private/InputBase/HintText.css.js +11 -3
  215. package/dist/components/private/InputBase/HintText.js +28 -14
  216. package/dist/components/private/InputBase/InputState.css.js +96 -80
  217. package/dist/components/private/InputBase/NotchedBase.css.js +157 -162
  218. package/dist/components/private/InputBase/NotchedBase.js +116 -76
  219. package/dist/components/private/InputBase/index.js +3 -1
  220. package/dist/components/private/InputBase/withEnhancedInput.css.js +117 -109
  221. package/dist/components/private/InputBase/withEnhancedInput.js +190 -92
  222. package/dist/hooks/useAttachedBoxes/index.js +3 -1
  223. package/dist/hooks/useAttachedBoxes/useAttachedBoxes.css.js +26 -18
  224. package/dist/hooks/useAttachedBoxes/useAttachedBoxes.js +71 -46
  225. package/dist/hooks/useMedia/index.js +3 -1
  226. package/dist/hooks/useMedia/useMedia.js +44 -34
  227. package/dist/hooks/useNegativeMargin/useNegativeMargin.js +4 -2
  228. package/dist/hooks/useNegativeMargin/useNegativeMarginLeft.css.js +13 -5
  229. package/dist/hooks/useNegativeMargin/useNegativeMarginLeft.js +6 -4
  230. package/dist/hooks/useNegativeMargin/useNegativeMarginTop.css.js +12 -4
  231. package/dist/hooks/useNegativeMargin/useNegativeMarginTop.js +6 -4
  232. package/dist/hooks/useResponsiveValue/index.js +3 -1
  233. package/dist/hooks/useResponsiveValue/useResponsiveValue.js +14 -14
  234. package/dist/hooks/useWindowScrollLock/index.js +15 -13
  235. package/dist/index.js +7 -5
  236. package/dist/reset/globalFonts.css.js +20 -12
  237. package/dist/reset/globalReset.css.js +21 -13
  238. package/dist/reset/reset.css.js +105 -109
  239. package/dist/themes/base/index.d.ts +1 -0
  240. package/dist/themes/base/index.d.ts.map +1 -1
  241. package/dist/themes/base/index.js +10 -6
  242. package/dist/themes/base/tokens.js +264 -257
  243. package/dist/themes/base/vars.css.js +10 -2
  244. package/dist/themes/flat_red/index.d.ts +1 -0
  245. package/dist/themes/flat_red/index.d.ts.map +1 -1
  246. package/dist/themes/flat_red/index.js +10 -6
  247. package/dist/themes/flat_red/tokens.js +104 -98
  248. package/dist/themes/flat_red/vars.css.js +10 -2
  249. package/dist/themes/helpers.js +60 -51
  250. package/dist/themes/index.js +4 -2
  251. package/dist/themes/makeTheme.js +27 -16
  252. package/dist/themes/theme.css.js +271 -259
  253. package/dist/themes/tokens.js +3 -1
  254. package/dist/utils/index.js +93 -77
  255. package/dist/utils/mapTokenToProperty.js +22 -10
  256. package/dist/utils/number.js +21 -24
  257. package/dist/utils/resolveResponsiveProps.js +29 -31
  258. package/dist/utils/responsiveProps.css.js +29 -17
  259. package/dist/utils/responsiveStyle.js +26 -16
  260. package/package.json +4 -2
@@ -1,324 +1,643 @@
1
+ "use strict";
2
+
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
+ const _excluded = ["autoFocus", "autoWidth", "inlineOptions", "fieldIcon", "suggestions", "value", "onChange", "onEnter", "itemRenderer", "onBlur", "onFocus", "onKeyDown", "onClick"],
6
+ _excluded2 = ["closeModal"],
7
+ _excluded3 = ["inlineOptions", "noScroll", "isFocused", "size", "fieldIcon", "isLoading", "autoFocus", "autoWidth", "suggestions", "value", "onChange", "itemRenderer", "onBlur", "onFocus", "onKeyDown", "onClick", "className"],
8
+ _excluded4 = ["field", "eventHandlers", "validation", "suffixed", "prefixed", "isLoading", "fieldIcon", "isFocused", "className", "size"],
9
+ _excluded5 = ["onReset"];
10
+
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
+
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
14
+
1
15
  import { ChevronDownIcon, CloseIcon } from '@autoguru/icons';
2
16
  import { wrapEvent } from '@autoguru/utilities';
3
17
  import clsx from 'clsx';
4
18
  import * as React from 'react';
5
- import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef, useState, } from 'react';
6
- import { useMedia } from '../../hooks/useMedia';
7
- import { useWindowScrollLock } from '../../hooks/useWindowScrollLock';
8
- import { setRef, useId } from '../../utils';
9
- import { Box } from '../Box';
10
- import { Button } from '../Button';
11
- import { Icon } from '../Icon';
12
- import { Portal } from '../Portal';
13
- import { Positioner } from '../Positioner';
14
- import { EAlignment } from '../Positioner/alignment';
15
- import { Text } from '../Text';
16
- import { withEnhancedInput } from '../private/InputBase';
17
- import * as styles from './AutoSuggest.css';
18
- import { useLayoutSuggestionVisible } from './useLayoutSuggestionVisible';
19
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useReducer, useRef, useState } from 'react';
20
+ import { useMedia } from "../../hooks/useMedia/index.js";
21
+ import { useWindowScrollLock } from "../../hooks/useWindowScrollLock/index.js";
22
+ import { setRef, useId } from "../../utils/index.js";
23
+ import { Box } from "../Box/index.js";
24
+ import { Button } from "../Button/index.js";
25
+ import { Icon } from "../Icon/index.js";
26
+ import { Portal } from "../Portal/index.js";
27
+ import { Positioner } from "../Positioner/index.js";
28
+ import { EAlignment } from "../Positioner/alignment.js";
29
+ import { Text } from "../Text/index.js";
30
+ import { withEnhancedInput } from "../private/InputBase/index.js";
31
+ import * as styles from "./AutoSuggest.css.js";
32
+ import { useLayoutSuggestionVisible } from "./useLayoutSuggestionVisible.js";
33
+ import { jsx as _jsx } from "react/jsx-runtime";
34
+ import { jsxs as _jsxs } from "react/jsx-runtime";
19
35
  var ActionTypes;
36
+
20
37
  (function (ActionTypes) {
21
- ActionTypes[ActionTypes["INPUT_CHANGE"] = 0] = "INPUT_CHANGE";
22
- ActionTypes[ActionTypes["INPUT_ESCAPE"] = 1] = "INPUT_ESCAPE";
23
- ActionTypes[ActionTypes["INPUT_ENTER"] = 2] = "INPUT_ENTER";
24
- ActionTypes[ActionTypes["INPUT_FOCUS"] = 3] = "INPUT_FOCUS";
25
- ActionTypes[ActionTypes["INPUT_BLUR"] = 4] = "INPUT_BLUR";
26
- ActionTypes[ActionTypes["INPUT_ARROW_DOWN"] = 5] = "INPUT_ARROW_DOWN";
27
- ActionTypes[ActionTypes["INPUT_ARROW_UP"] = 6] = "INPUT_ARROW_UP";
28
- ActionTypes[ActionTypes["FLYOUT_CLOSE"] = 7] = "FLYOUT_CLOSE";
29
- ActionTypes[ActionTypes["SUGGESTION_MOUSE_ENTER"] = 8] = "SUGGESTION_MOUSE_ENTER";
30
- ActionTypes[ActionTypes["SUGGESTION_MOUSE_CLICK"] = 9] = "SUGGESTION_MOUSE_CLICK";
38
+ ActionTypes[ActionTypes["INPUT_CHANGE"] = 0] = "INPUT_CHANGE";
39
+ ActionTypes[ActionTypes["INPUT_ESCAPE"] = 1] = "INPUT_ESCAPE";
40
+ ActionTypes[ActionTypes["INPUT_ENTER"] = 2] = "INPUT_ENTER";
41
+ ActionTypes[ActionTypes["INPUT_FOCUS"] = 3] = "INPUT_FOCUS";
42
+ ActionTypes[ActionTypes["INPUT_BLUR"] = 4] = "INPUT_BLUR";
43
+ ActionTypes[ActionTypes["INPUT_ARROW_DOWN"] = 5] = "INPUT_ARROW_DOWN";
44
+ ActionTypes[ActionTypes["INPUT_ARROW_UP"] = 6] = "INPUT_ARROW_UP";
45
+ ActionTypes[ActionTypes["FLYOUT_CLOSE"] = 7] = "FLYOUT_CLOSE";
46
+ ActionTypes[ActionTypes["SUGGESTION_MOUSE_ENTER"] = 8] = "SUGGESTION_MOUSE_ENTER";
47
+ ActionTypes[ActionTypes["SUGGESTION_MOUSE_CLICK"] = 9] = "SUGGESTION_MOUSE_CLICK";
31
48
  })(ActionTypes || (ActionTypes = {}));
32
- const inputReducerFactory = (suggestions) => (prevState, action) => {
33
- switch (action.type) {
34
- default:
35
- case ActionTypes.INPUT_CHANGE: {
36
- return {
37
- isFlyoutOpen: true,
38
- highlightIndex: -1,
39
- previewText: null,
40
- };
41
- }
42
- case ActionTypes.FLYOUT_CLOSE:
43
- case ActionTypes.SUGGESTION_MOUSE_CLICK:
44
- case ActionTypes.INPUT_ESCAPE:
45
- case ActionTypes.INPUT_BLUR: {
46
- return {
47
- isFlyoutOpen: false,
48
- highlightIndex: -1,
49
- previewText: null,
50
- };
51
- }
52
- case ActionTypes.INPUT_FOCUS: {
53
- return {
54
- ...prevState,
55
- isFlyoutOpen: suggestions.length > -1,
56
- };
57
- }
58
- case ActionTypes.INPUT_ARROW_DOWN: {
59
- const nextIndex = getNextIndex(1, prevState.highlightIndex, suggestions);
60
- return {
61
- isFlyoutOpen: true,
62
- highlightIndex: nextIndex,
63
- previewText: nextIndex > -1 ? suggestions[nextIndex].text : null,
64
- };
65
- }
66
- case ActionTypes.INPUT_ARROW_UP: {
67
- const firstIndex = getNextIndex(1, -1, suggestions);
68
- if (prevState.highlightIndex === firstIndex) {
69
- return {
70
- isFlyoutOpen: true,
71
- highlightIndex: -1,
72
- previewText: null,
73
- };
74
- }
75
- const nextIndex = getNextIndex(-1, prevState.highlightIndex, suggestions);
76
- return {
77
- isFlyoutOpen: true,
78
- highlightIndex: nextIndex,
79
- previewText: nextIndex > -1 ? suggestions[nextIndex].text : null,
80
- };
81
- }
82
- case ActionTypes.SUGGESTION_MOUSE_ENTER: {
83
- return {
84
- ...prevState,
85
- highlightIndex: action.index,
86
- };
49
+
50
+ const inputReducerFactory = suggestions => (prevState, action) => {
51
+ switch (action.type) {
52
+ default:
53
+ case ActionTypes.INPUT_CHANGE:
54
+ {
55
+ return {
56
+ isFlyoutOpen: true,
57
+ highlightIndex: -1,
58
+ previewText: null
59
+ };
60
+ }
61
+
62
+ case ActionTypes.FLYOUT_CLOSE:
63
+ case ActionTypes.SUGGESTION_MOUSE_CLICK:
64
+ case ActionTypes.INPUT_ESCAPE:
65
+ case ActionTypes.INPUT_BLUR:
66
+ {
67
+ return {
68
+ isFlyoutOpen: false,
69
+ highlightIndex: -1,
70
+ previewText: null
71
+ };
72
+ }
73
+
74
+ case ActionTypes.INPUT_FOCUS:
75
+ {
76
+ return _objectSpread(_objectSpread({}, prevState), {}, {
77
+ isFlyoutOpen: suggestions.length > -1
78
+ });
79
+ }
80
+
81
+ case ActionTypes.INPUT_ARROW_DOWN:
82
+ {
83
+ const nextIndex = getNextIndex(1, prevState.highlightIndex, suggestions);
84
+ return {
85
+ isFlyoutOpen: true,
86
+ highlightIndex: nextIndex,
87
+ previewText: nextIndex > -1 ? suggestions[nextIndex].text : null
88
+ };
89
+ }
90
+
91
+ case ActionTypes.INPUT_ARROW_UP:
92
+ {
93
+ const firstIndex = getNextIndex(1, -1, suggestions);
94
+
95
+ if (prevState.highlightIndex === firstIndex) {
96
+ return {
97
+ isFlyoutOpen: true,
98
+ highlightIndex: -1,
99
+ previewText: null
100
+ };
87
101
  }
88
- case ActionTypes.INPUT_ENTER: {
89
- if (prevState.highlightIndex > -1) {
90
- return {
91
- highlightIndex: -1,
92
- previewText: null,
93
- isFlyoutOpen: false,
94
- };
95
- }
96
- return prevState;
102
+
103
+ const nextIndex = getNextIndex(-1, prevState.highlightIndex, suggestions);
104
+ return {
105
+ isFlyoutOpen: true,
106
+ highlightIndex: nextIndex,
107
+ previewText: nextIndex > -1 ? suggestions[nextIndex].text : null
108
+ };
109
+ }
110
+
111
+ case ActionTypes.SUGGESTION_MOUSE_ENTER:
112
+ {
113
+ return _objectSpread(_objectSpread({}, prevState), {}, {
114
+ highlightIndex: action.index
115
+ });
116
+ }
117
+
118
+ case ActionTypes.INPUT_ENTER:
119
+ {
120
+ if (prevState.highlightIndex > -1) {
121
+ return {
122
+ highlightIndex: -1,
123
+ previewText: null,
124
+ isFlyoutOpen: false
125
+ };
97
126
  }
98
- }
127
+
128
+ return prevState;
129
+ }
130
+ }
99
131
  };
100
- export const AutoSuggest = forwardRef(function AutoSuggest({ autoFocus = false, autoWidth = false, inlineOptions = false, fieldIcon, suggestions, value: incomingValue, onChange: incomingOnChange, onEnter, itemRenderer = defaultItemRenderer, onBlur: incomingOnBlur, onFocus: incomingOnFocus, onKeyDown, onClick, ...textInputProps }, ref) {
101
- const inputRef = useRef();
102
- const valueRef = useRef(incomingValue);
103
- useImperativeHandle(ref, () => inputRef.current);
104
- const [isDesktop] = useMedia(['desktop'], false);
105
- const [isFocused, setIsFocused] = useState(false);
106
- const [showModal, setShowModal] = useState(false);
107
- const closeModal = useCallback(() => {
132
+
133
+ export const AutoSuggest = forwardRef(function AutoSuggest(_ref, ref) {
134
+ let {
135
+ autoFocus = false,
136
+ autoWidth = false,
137
+ inlineOptions = false,
138
+ fieldIcon,
139
+ suggestions,
140
+ value: incomingValue,
141
+ onChange: incomingOnChange,
142
+ onEnter,
143
+ itemRenderer = defaultItemRenderer,
144
+ onBlur: incomingOnBlur,
145
+ onFocus: incomingOnFocus,
146
+ onKeyDown,
147
+ onClick
148
+ } = _ref,
149
+ textInputProps = _objectWithoutProperties(_ref, _excluded);
150
+
151
+ const inputRef = useRef();
152
+ const valueRef = useRef(incomingValue);
153
+ useImperativeHandle(ref, () => inputRef.current);
154
+ const [isDesktop] = useMedia(['desktop'], false);
155
+ const [isFocused, setIsFocused] = useState(false);
156
+ const [showModal, setShowModal] = useState(false);
157
+ const closeModal = useCallback(() => {
158
+ setShowModal(false);
159
+ setIsFocused(false);
160
+ }, [setShowModal]);
161
+
162
+ if (incomingValue && incomingValue !== valueRef.current) {
163
+ valueRef.current = incomingValue;
164
+ if (incomingValue.payload) closeModal();
165
+ }
166
+
167
+ const props = _objectSpread({
168
+ suggestions,
169
+ value: valueRef.current,
170
+ onChange: value => {
171
+ if (typeof value.payload !== 'undefined' && value.payload !== null) {
172
+ setShowModal(false);
173
+ if (!isDesktop) setIsFocused(false);
174
+ }
175
+
176
+ if (typeof incomingOnChange === 'function') incomingOnChange(value);
177
+ },
178
+ onKeyUp: event => {
179
+ if (event.key === 'Enter' && typeof onEnter === 'function') {
180
+ var _inputRef$current;
181
+
108
182
  setShowModal(false);
109
183
  setIsFocused(false);
110
- }, [setShowModal]);
111
- if (incomingValue && incomingValue !== valueRef.current) {
112
- valueRef.current = incomingValue;
113
- if (incomingValue.payload)
114
- closeModal();
115
- }
116
- const props = {
117
- suggestions,
118
- value: valueRef.current,
119
- onChange: (value) => {
120
- if (typeof value.payload !== 'undefined' &&
121
- value.payload !== null) {
122
- setShowModal(false);
123
- if (!isDesktop)
124
- setIsFocused(false);
125
- }
126
- if (typeof incomingOnChange === 'function')
127
- incomingOnChange(value);
128
- },
129
- onKeyUp: (event) => {
130
- if (event.key === 'Enter' && typeof onEnter === 'function') {
131
- setShowModal(false);
132
- setIsFocused(false);
133
- inputRef.current?.blur();
134
- onEnter(valueRef.current);
135
- }
136
- },
137
- itemRenderer,
138
- onKeyDown,
139
- onClick,
140
- onFocus: wrapEvent(() => {
141
- setIsFocused(true);
142
- setShowModal(true);
143
- }, incomingOnFocus),
144
- onBlur: wrapEvent(() => setIsFocused(false), incomingOnBlur),
145
- ...textInputProps,
146
- };
147
- return !inlineOptions && !isDesktop && showModal ? (React.createElement(AutoSuggestFullscreenInput, { ...props, attach: "NONE", borderMerged: "NONE", isFocused: isFocused, inlineOptions: true, fieldIcon: fieldIcon, autoFocus: autoFocus, closeModal: closeModal })) : (React.createElement(AutoSuggestInput, { ref: inputRef, ...props, isFocused: isFocused, inlineOptions: inlineOptions, fieldIcon: fieldIcon, autoFocus: autoFocus, autoWidth: autoWidth }));
148
- });
149
- const AutoSuggestFullscreenInput = forwardRef(function AutoSuggestFullscreenInput({ closeModal, ...props }, ref) {
150
- const [showPortal, setShowPortal] = useState(false);
151
- useWindowScrollLock();
152
- useEffect(() => {
153
- const cb = requestAnimationFrame(() => setShowPortal(true));
154
- return () => {
155
- cancelAnimationFrame(cb);
156
- };
157
- }, [setShowPortal]);
158
- return showPortal ? (React.createElement(Portal, null,
159
- React.createElement("div", { className: styles.fullScreenRoot },
160
- React.createElement(AutoSuggestInput, { ref: ref, ...props, className: styles.fullScreenInput, inlineOptions: true, noScroll: true }),
161
- React.createElement(Button, { minimal: true, rounded: true, className: styles.fullScreenCloseBtn, size: "medium", onClick: closeModal },
162
- React.createElement(Icon, { icon: CloseIcon }))))) : null;
184
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.blur();
185
+ onEnter(valueRef.current);
186
+ }
187
+ },
188
+ itemRenderer,
189
+ onKeyDown,
190
+ onClick,
191
+ onFocus: wrapEvent(() => {
192
+ setIsFocused(true);
193
+ setShowModal(true);
194
+ }, incomingOnFocus),
195
+ onBlur: wrapEvent(() => setIsFocused(false), incomingOnBlur)
196
+ }, textInputProps);
197
+
198
+ return !inlineOptions && !isDesktop && showModal ? _jsx(AutoSuggestFullscreenInput, _objectSpread(_objectSpread({}, props), {}, {
199
+ attach: "NONE",
200
+ borderMerged: "NONE",
201
+ isFocused: isFocused,
202
+ inlineOptions: true,
203
+ fieldIcon: fieldIcon,
204
+ autoFocus: autoFocus,
205
+ closeModal: closeModal
206
+ })) : _jsx(AutoSuggestInput, _objectSpread(_objectSpread({
207
+ ref: inputRef
208
+ }, props), {}, {
209
+ isFocused: isFocused,
210
+ inlineOptions: inlineOptions,
211
+ fieldIcon: fieldIcon,
212
+ autoFocus: autoFocus,
213
+ autoWidth: autoWidth
214
+ }));
163
215
  });
164
- const AutoSuggestInput = forwardRef(function AutoSuggestInput({ inlineOptions = false, noScroll = false, isFocused = false, size, fieldIcon, isLoading, autoFocus, autoWidth, suggestions, value, onChange, itemRenderer = defaultItemRenderer, onBlur, onFocus, onKeyDown, onClick, className, ...textInputProps }, ref) {
165
- const triggerRef = useRef(null);
166
- const highlightRef = useRef(null);
167
- const suggestionListRef = useRef(null);
168
- const suggestionListId = useId();
169
- const reducer = useMemo(() => inputReducerFactory(suggestions), [suggestions]);
170
- const [state, dispatch] = useReducer(reducer, {
171
- highlightIndex: -1,
172
- previewText: null,
173
- isFlyoutOpen: false,
174
- });
175
- const shouldOpenFlyout = suggestions.length > 0 && state.isFlyoutOpen;
176
- useLayoutSuggestionVisible(state.highlightIndex, highlightRef, suggestionListRef);
177
- return (React.createElement(Box, { role: "combobox", "aria-label": textInputProps.placeholder, "aria-expanded": shouldOpenFlyout, "aria-owns": suggestionListId, "aria-haspopup": "listbox", width: "full" },
178
- React.createElement(Box, { backgroundColour: "white", borderRadius: "1", className: styles.input },
179
- React.createElement(AutoSuggestInputPrimitive, { className: className, size: size, isFocused: isFocused, isLoading: isLoading, autoFocus: autoFocus, fieldIcon: fieldIcon, wrapperRef: triggerRef, ...textInputProps, ref: ref, "aria-autocomplete": "list", "aria-controls": suggestionListId, "aria-activedescendant": state.highlightIndex > -1
180
- ? getSuggestionId(suggestionListId, state.highlightIndex)
181
- : undefined, value: state.previewText ?? value?.text, onReset: () => {
182
- dispatch({ type: ActionTypes.INPUT_CHANGE });
183
- if (typeof onChange === 'function')
184
- onChange({
185
- text: '',
186
- payload: undefined,
187
- });
188
- }, onChange: (event) => {
189
- dispatch({ type: ActionTypes.INPUT_CHANGE });
190
- if (typeof onChange === 'function')
191
- onChange({
192
- text: event.target.value,
193
- payload: undefined,
194
- });
195
- }, onFocus: wrapEvent(() => dispatch({ type: ActionTypes.INPUT_FOCUS }), onFocus), onBlur: wrapEvent(() => {
196
- if (state.highlightIndex > -1 &&
197
- state.highlightIndex &&
198
- state.previewText ===
199
- suggestions[state.highlightIndex]?.text &&
200
- typeof onChange === 'function')
201
- onChange(suggestions[state.highlightIndex]);
202
- dispatch({ type: ActionTypes.INPUT_BLUR });
203
- }, onBlur), onKeyDown: wrapEvent((event) => {
204
- switch (event.key) {
205
- case 'ArrowUp':
206
- case 'ArrowDown': {
207
- event.preventDefault();
208
- dispatch({
209
- type: event.key === 'ArrowDown'
210
- ? ActionTypes.INPUT_ARROW_DOWN
211
- : ActionTypes.INPUT_ARROW_UP,
212
- });
213
- return;
214
- }
215
- case 'Enter': {
216
- if (state.highlightIndex > -1) {
217
- event.preventDefault();
218
- if (typeof onChange === 'function')
219
- onChange(suggestions[state.highlightIndex]);
220
- }
221
- dispatch({ type: ActionTypes.INPUT_ENTER });
222
- return;
223
- }
224
- case 'Escape': {
225
- dispatch({ type: ActionTypes.INPUT_ESCAPE });
226
- }
227
- }
228
- }, onKeyDown) })),
229
- inlineOptions ? (React.createElement(SuggestionsList, { suggestionListRef: suggestionListRef, suggestionListId: suggestionListId, placeholder: textInputProps.placeholder, highlightIndex: state.highlightIndex, suggestions: suggestions, highlightRef: highlightRef, itemRenderer: itemRenderer, className: noScroll
230
- ? styles.suggestionList.inlineOptionsNoScroll
231
- : styles.suggestionList.inlineOptions, dispatch: dispatch, onChange: onChange })) : (React.createElement(SuggestionListFlyout, { id: suggestionListId, autoWidth: autoWidth, triggerRef: triggerRef, alignment: EAlignment.BOTTOM_LEFT, isOpen: shouldOpenFlyout, triggerOffset: 4 },
232
- React.createElement(SuggestionsList, { className: styles.suggestionList.blockOptions, suggestionListRef: suggestionListRef, suggestionListId: suggestionListId, placeholder: textInputProps.placeholder, highlightIndex: state.highlightIndex, suggestions: suggestions, highlightRef: highlightRef, itemRenderer: itemRenderer, dispatch: dispatch, onChange: onChange })))));
216
+ const AutoSuggestFullscreenInput = forwardRef(function AutoSuggestFullscreenInput(_ref2, ref) {
217
+ let {
218
+ closeModal
219
+ } = _ref2,
220
+ props = _objectWithoutProperties(_ref2, _excluded2);
221
+
222
+ const [showPortal, setShowPortal] = useState(false);
223
+ useWindowScrollLock();
224
+ useEffect(() => {
225
+ const cb = requestAnimationFrame(() => setShowPortal(true));
226
+ return () => {
227
+ cancelAnimationFrame(cb);
228
+ };
229
+ }, [setShowPortal]);
230
+ return showPortal ? _jsx(Portal, {
231
+ children: _jsxs("div", {
232
+ className: styles.fullScreenRoot,
233
+ children: [_jsx(AutoSuggestInput, _objectSpread(_objectSpread({
234
+ ref: ref
235
+ }, props), {}, {
236
+ className: styles.fullScreenInput,
237
+ inlineOptions: true,
238
+ noScroll: true
239
+ })), _jsx(Button, {
240
+ minimal: true,
241
+ rounded: true,
242
+ className: styles.fullScreenCloseBtn,
243
+ size: "medium",
244
+ onClick: closeModal,
245
+ children: _jsx(Icon, {
246
+ icon: CloseIcon
247
+ })
248
+ })]
249
+ })
250
+ }) : null;
233
251
  });
234
- const SuggestionsList = ({ className = '', suggestionListId, placeholder, highlightIndex, suggestions, highlightRef, itemRenderer, onChange, dispatch, suggestionListRef, }) => (React.createElement(Box, { ref: suggestionListRef, is: "ul", backgroundColour: "white", className: [styles.suggestionList.defaults, className], id: suggestionListId, "aria-label": placeholder, role: "listbox" },
235
- React.createElement("div", { className: styles.spacer }),
236
- suggestions.map((suggestion, idx) => {
237
- const highlight = highlightIndex === idx;
238
- return (React.createElement(Box, { key: suggestion.text.concat(String(idx)), ref: highlight ? highlightRef : undefined, is: "li", id: getSuggestionId(suggestionListId, idx), role: "option", "aria-selected": highlight, "aria-label": suggestion.text, className: clsx(styles.suggestionListItem.default, {
239
- [styles.suggestionListItem.skipped]: suggestion.skip,
240
- }), onMouseDown: (event) => event.preventDefault(), onMouseMove: () => {
241
- if (suggestion.skip)
242
- return;
252
+ const AutoSuggestInput = forwardRef(function AutoSuggestInput(_ref3, ref) {
253
+ var _state$previewText;
254
+
255
+ let {
256
+ inlineOptions = false,
257
+ noScroll = false,
258
+ isFocused = false,
259
+ size,
260
+ fieldIcon,
261
+ isLoading,
262
+ autoFocus,
263
+ autoWidth,
264
+ suggestions,
265
+ value,
266
+ onChange,
267
+ itemRenderer = defaultItemRenderer,
268
+ onBlur,
269
+ onFocus,
270
+ onKeyDown,
271
+ onClick,
272
+ className
273
+ } = _ref3,
274
+ textInputProps = _objectWithoutProperties(_ref3, _excluded3);
275
+
276
+ const triggerRef = useRef(null);
277
+ const highlightRef = useRef(null);
278
+ const suggestionListRef = useRef(null);
279
+ const suggestionListId = useId();
280
+ const reducer = useMemo(() => inputReducerFactory(suggestions), [suggestions]);
281
+ const [state, dispatch] = useReducer(reducer, {
282
+ highlightIndex: -1,
283
+ previewText: null,
284
+ isFlyoutOpen: false
285
+ });
286
+ const shouldOpenFlyout = suggestions.length > 0 && state.isFlyoutOpen;
287
+ useLayoutSuggestionVisible(state.highlightIndex, highlightRef, suggestionListRef);
288
+ return _jsxs(Box, {
289
+ role: "combobox",
290
+ "aria-label": textInputProps.placeholder,
291
+ "aria-expanded": shouldOpenFlyout,
292
+ "aria-owns": suggestionListId,
293
+ "aria-haspopup": "listbox",
294
+ width: "full",
295
+ children: [_jsx(Box, {
296
+ backgroundColour: "white",
297
+ borderRadius: "1",
298
+ className: styles.input,
299
+ children: _jsx(AutoSuggestInputPrimitive, _objectSpread(_objectSpread({
300
+ className: className,
301
+ size: size,
302
+ isFocused: isFocused,
303
+ isLoading: isLoading,
304
+ autoFocus: autoFocus,
305
+ fieldIcon: fieldIcon,
306
+ wrapperRef: triggerRef
307
+ }, textInputProps), {}, {
308
+ ref: ref,
309
+ "aria-autocomplete": "list",
310
+ "aria-controls": suggestionListId,
311
+ "aria-activedescendant": state.highlightIndex > -1 ? getSuggestionId(suggestionListId, state.highlightIndex) : undefined,
312
+ value: (_state$previewText = state.previewText) !== null && _state$previewText !== void 0 ? _state$previewText : value === null || value === void 0 ? void 0 : value.text,
313
+ onReset: () => {
314
+ dispatch({
315
+ type: ActionTypes.INPUT_CHANGE
316
+ });
317
+ if (typeof onChange === 'function') onChange({
318
+ text: '',
319
+ payload: undefined
320
+ });
321
+ },
322
+ onChange: event => {
323
+ dispatch({
324
+ type: ActionTypes.INPUT_CHANGE
325
+ });
326
+ if (typeof onChange === 'function') onChange({
327
+ text: event.target.value,
328
+ payload: undefined
329
+ });
330
+ },
331
+ onFocus: wrapEvent(() => dispatch({
332
+ type: ActionTypes.INPUT_FOCUS
333
+ }), onFocus),
334
+ onBlur: wrapEvent(() => {
335
+ var _suggestions$state$hi;
336
+
337
+ if (state.highlightIndex > -1 && state.highlightIndex && state.previewText === ((_suggestions$state$hi = suggestions[state.highlightIndex]) === null || _suggestions$state$hi === void 0 ? void 0 : _suggestions$state$hi.text) && typeof onChange === 'function') onChange(suggestions[state.highlightIndex]);
338
+ dispatch({
339
+ type: ActionTypes.INPUT_BLUR
340
+ });
341
+ }, onBlur),
342
+ onKeyDown: wrapEvent(event => {
343
+ switch (event.key) {
344
+ case 'ArrowUp':
345
+ case 'ArrowDown':
346
+ {
347
+ event.preventDefault();
243
348
  dispatch({
244
- type: ActionTypes.SUGGESTION_MOUSE_ENTER,
245
- index: idx,
349
+ type: event.key === 'ArrowDown' ? ActionTypes.INPUT_ARROW_DOWN : ActionTypes.INPUT_ARROW_UP
246
350
  });
247
- }, onClick: () => {
248
- if (suggestion.skip)
249
- return;
250
- if (typeof onChange === 'function')
251
- onChange(suggestion);
351
+ return;
352
+ }
353
+
354
+ case 'Enter':
355
+ {
356
+ if (state.highlightIndex > -1) {
357
+ event.preventDefault();
358
+ if (typeof onChange === 'function') onChange(suggestions[state.highlightIndex]);
359
+ }
360
+
252
361
  dispatch({
253
- type: ActionTypes.SUGGESTION_MOUSE_CLICK,
362
+ type: ActionTypes.INPUT_ENTER
254
363
  });
255
- } }, typeof itemRenderer === 'function' &&
256
- itemRenderer({
257
- suggestions,
258
- highlight,
259
- value: suggestion,
260
- })));
261
- }),
262
- React.createElement("div", { className: styles.spacer })));
263
- const AutoSuggestInputPrimitive = withEnhancedInput(({ field, eventHandlers, validation, suffixed, prefixed, isLoading, fieldIcon = ChevronDownIcon, isFocused, className, size, ...rest }) => {
264
- let focusTimeout;
265
- const ref = useRef(null);
266
- const focusHandler = useCallback(() => {
267
- ref.current?.focus();
268
- }, []);
269
- const { onReset, ...inputEventHandlers } = eventHandlers;
270
- const handleRef = useCallback((node) => {
271
- if (field.ref)
272
- setRef(field.ref, node);
273
- setRef(ref, node);
274
- }, [field]);
275
- const onRequestReset = useCallback(() => {
276
- if (typeof onReset === 'function')
277
- onReset();
278
- focusTimeout = setTimeout(() => ref.current?.focus(), 100);
279
- }, [onReset, focusTimeout]);
280
- const suffix = useMemo(() => isLoading ? null : field.value && isFocused ? (React.createElement(Box, { is: "button", paddingY: size === 'small' ? '1' : '3', paddingRight: size === 'small' ? '2' : '3', flexShrink: 0, onMouseDown: onRequestReset },
281
- React.createElement(Icon, { size: "medium", icon: CloseIcon }))) : fieldIcon ? (React.createElement(Box, { flexShrink: 0, paddingY: size === 'medium' ? '3' : '2', paddingRight: size === 'medium' ? '3' : '2', onClick: focusHandler },
282
- React.createElement(Icon, { size: "medium", icon: fieldIcon }))) : null, [field.value, isLoading, fieldIcon, isFocused, onRequestReset]);
283
- useEffect(() => () => focusTimeout ? clearTimeout(focusTimeout) : void 0, []);
284
- return (React.createElement(Box, { display: "flex", flexWrap: "nowrap", alignItems: "center", justifyContent: "center", className: className },
285
- React.createElement(Box, { is: "input", flexGrow: 1, ...inputEventHandlers, ...field, ref: handleRef, autoCapitalize: "none", spellCheck: "false", autoComplete: "off", ...rest, type: "search" }),
286
- suffix));
364
+ return;
365
+ }
366
+
367
+ case 'Escape':
368
+ {
369
+ dispatch({
370
+ type: ActionTypes.INPUT_ESCAPE
371
+ });
372
+ }
373
+ }
374
+ }, onKeyDown)
375
+ }))
376
+ }), inlineOptions ? _jsx(SuggestionsList, {
377
+ suggestionListRef: suggestionListRef,
378
+ suggestionListId: suggestionListId,
379
+ placeholder: textInputProps.placeholder,
380
+ highlightIndex: state.highlightIndex,
381
+ suggestions: suggestions,
382
+ highlightRef: highlightRef,
383
+ itemRenderer: itemRenderer,
384
+ className: noScroll ? styles.suggestionList.inlineOptionsNoScroll : styles.suggestionList.inlineOptions,
385
+ dispatch: dispatch,
386
+ onChange: onChange
387
+ }) : _jsx(SuggestionListFlyout, {
388
+ id: suggestionListId,
389
+ autoWidth: autoWidth,
390
+ triggerRef: triggerRef,
391
+ alignment: EAlignment.BOTTOM_LEFT,
392
+ isOpen: shouldOpenFlyout,
393
+ triggerOffset: 4,
394
+ children: _jsx(SuggestionsList, {
395
+ className: styles.suggestionList.blockOptions,
396
+ suggestionListRef: suggestionListRef,
397
+ suggestionListId: suggestionListId,
398
+ placeholder: textInputProps.placeholder,
399
+ highlightIndex: state.highlightIndex,
400
+ suggestions: suggestions,
401
+ highlightRef: highlightRef,
402
+ itemRenderer: itemRenderer,
403
+ dispatch: dispatch,
404
+ onChange: onChange
405
+ })
406
+ })]
407
+ });
408
+ });
409
+
410
+ const SuggestionsList = _ref4 => {
411
+ let {
412
+ className = '',
413
+ suggestionListId,
414
+ placeholder,
415
+ highlightIndex,
416
+ suggestions,
417
+ highlightRef,
418
+ itemRenderer,
419
+ onChange,
420
+ dispatch,
421
+ suggestionListRef
422
+ } = _ref4;
423
+ return _jsxs(Box, {
424
+ ref: suggestionListRef,
425
+ is: "ul",
426
+ backgroundColour: "white",
427
+ className: [styles.suggestionList.defaults, className],
428
+ id: suggestionListId,
429
+ "aria-label": placeholder,
430
+ role: "listbox",
431
+ children: [_jsx("div", {
432
+ className: styles.spacer
433
+ }), suggestions.map((suggestion, idx) => {
434
+ const highlight = highlightIndex === idx;
435
+ return _jsx(Box, {
436
+ ref: highlight ? highlightRef : undefined,
437
+ is: "li",
438
+ id: getSuggestionId(suggestionListId, idx),
439
+ role: "option",
440
+ "aria-selected": highlight,
441
+ "aria-label": suggestion.text,
442
+ className: clsx(styles.suggestionListItem.default, {
443
+ [styles.suggestionListItem.skipped]: suggestion.skip
444
+ }),
445
+ onMouseDown: event => event.preventDefault(),
446
+ onMouseMove: () => {
447
+ if (suggestion.skip) return;
448
+ dispatch({
449
+ type: ActionTypes.SUGGESTION_MOUSE_ENTER,
450
+ index: idx
451
+ });
452
+ },
453
+ onClick: () => {
454
+ if (suggestion.skip) return;
455
+ if (typeof onChange === 'function') onChange(suggestion);
456
+ dispatch({
457
+ type: ActionTypes.SUGGESTION_MOUSE_CLICK
458
+ });
459
+ },
460
+ children: typeof itemRenderer === 'function' && itemRenderer({
461
+ suggestions,
462
+ highlight,
463
+ value: suggestion
464
+ })
465
+ }, suggestion.text.concat(String(idx)));
466
+ }), _jsx("div", {
467
+ className: styles.spacer
468
+ })]
469
+ });
470
+ };
471
+
472
+ const AutoSuggestInputPrimitive = withEnhancedInput(_ref5 => {
473
+ let {
474
+ field,
475
+ eventHandlers,
476
+ validation,
477
+ suffixed,
478
+ prefixed,
479
+ isLoading,
480
+ fieldIcon = ChevronDownIcon,
481
+ isFocused,
482
+ className,
483
+ size
484
+ } = _ref5,
485
+ rest = _objectWithoutProperties(_ref5, _excluded4);
486
+
487
+ let focusTimeout;
488
+ const ref = useRef(null);
489
+ const focusHandler = useCallback(() => {
490
+ var _ref$current;
491
+
492
+ (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
493
+ }, []);
494
+
495
+ const {
496
+ onReset
497
+ } = eventHandlers,
498
+ inputEventHandlers = _objectWithoutProperties(eventHandlers, _excluded5);
499
+
500
+ const handleRef = useCallback(node => {
501
+ if (field.ref) setRef(field.ref, node);
502
+ setRef(ref, node);
503
+ }, [field]);
504
+ const onRequestReset = useCallback(() => {
505
+ if (typeof onReset === 'function') onReset();
506
+ focusTimeout = setTimeout(() => {
507
+ var _ref$current2;
508
+
509
+ return (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focus();
510
+ }, 100);
511
+ }, [onReset, focusTimeout]);
512
+ const suffix = useMemo(() => isLoading ? null : field.value && isFocused ? _jsx(Box, {
513
+ is: "button",
514
+ paddingY: size === 'small' ? '1' : '3',
515
+ paddingRight: size === 'small' ? '2' : '3',
516
+ flexShrink: 0,
517
+ onMouseDown: onRequestReset,
518
+ children: _jsx(Icon, {
519
+ size: "medium",
520
+ icon: CloseIcon
521
+ })
522
+ }) : fieldIcon ? _jsx(Box, {
523
+ flexShrink: 0,
524
+ paddingY: size === 'medium' ? '3' : '2',
525
+ paddingRight: size === 'medium' ? '3' : '2',
526
+ onClick: focusHandler,
527
+ children: _jsx(Icon, {
528
+ size: "medium",
529
+ icon: fieldIcon
530
+ })
531
+ }) : null, [field.value, isLoading, fieldIcon, isFocused, onRequestReset]);
532
+ useEffect(() => () => focusTimeout ? clearTimeout(focusTimeout) : void 0, []);
533
+ return _jsxs(Box, {
534
+ display: "flex",
535
+ flexWrap: "nowrap",
536
+ alignItems: "center",
537
+ justifyContent: "center",
538
+ className: className,
539
+ children: [_jsx(Box, _objectSpread(_objectSpread(_objectSpread(_objectSpread({
540
+ is: "input",
541
+ flexGrow: 1
542
+ }, inputEventHandlers), field), {}, {
543
+ ref: handleRef,
544
+ autoCapitalize: "none",
545
+ spellCheck: "false",
546
+ autoComplete: "off"
547
+ }, rest), {}, {
548
+ type: "search"
549
+ })), suffix]
550
+ });
287
551
  }, {
288
- primitiveType: 'text',
289
- withPrefixIcon: true,
290
- withSuffixIcon: false,
552
+ primitiveType: 'text',
553
+ withPrefixIcon: true,
554
+ withSuffixIcon: false
291
555
  });
292
- const getSuggestionId = (id, index) => `${id}-option-${index}`;
293
- const SuggestionListFlyout = ({ id, alignment, isOpen, triggerOffset, triggerRef, autoWidth, children, }) => (React.createElement(Positioner, { id: id, triggerRef: triggerRef, alignment: alignment, isOpen: isOpen, triggerOffset: triggerOffset, role: "listbox" },
294
- React.createElement(Box, { borderWidth: "1", borderColour: "gray", borderRadius: "1", backgroundColour: "white", boxShadow: "2", style: {
295
- width: triggerRef.current && !autoWidth
296
- ? triggerRef.current.clientWidth
297
- : undefined,
298
- }, onMouseDown: (event) => event.preventDefault() }, children)));
299
- const defaultItemRenderer = ({ value, highlight, }) => (React.createElement(DefaultSuggestion, { highlight: highlight, text: value.text }));
300
- const DefaultSuggestion = ({ text, highlight, }) => (React.createElement("div", { className: clsx(styles.suggestion, {
301
- [styles.suggestionHighlight]: highlight,
302
- }) },
303
- React.createElement(Text, { is: "span" }, text)));
556
+
557
+ const getSuggestionId = (id, index) => "".concat(id, "-option-").concat(index);
558
+
559
+ const SuggestionListFlyout = _ref6 => {
560
+ let {
561
+ id,
562
+ alignment,
563
+ isOpen,
564
+ triggerOffset,
565
+ triggerRef,
566
+ autoWidth,
567
+ children
568
+ } = _ref6;
569
+ return _jsx(Positioner, {
570
+ id: id,
571
+ triggerRef: triggerRef,
572
+ alignment: alignment,
573
+ isOpen: isOpen,
574
+ triggerOffset: triggerOffset,
575
+ role: "listbox",
576
+ children: _jsx(Box, {
577
+ borderWidth: "1",
578
+ borderColour: "gray",
579
+ borderRadius: "1",
580
+ backgroundColour: "white",
581
+ boxShadow: "2",
582
+ style: {
583
+ width: triggerRef.current && !autoWidth ? triggerRef.current.clientWidth : undefined
584
+ },
585
+ onMouseDown: event => event.preventDefault(),
586
+ children: children
587
+ })
588
+ });
589
+ };
590
+
591
+ const defaultItemRenderer = _ref7 => {
592
+ let {
593
+ value,
594
+ highlight
595
+ } = _ref7;
596
+ return _jsx(DefaultSuggestion, {
597
+ highlight: highlight,
598
+ text: value.text
599
+ });
600
+ };
601
+
602
+ const DefaultSuggestion = _ref8 => {
603
+ let {
604
+ text,
605
+ highlight
606
+ } = _ref8;
607
+ return _jsx("div", {
608
+ className: clsx(styles.suggestion, {
609
+ [styles.suggestionHighlight]: highlight
610
+ }),
611
+ children: _jsx(Text, {
612
+ is: "span",
613
+ children: text
614
+ })
615
+ });
616
+ };
617
+
304
618
  const getNextIndex = (direction, currentIndex, suggestions) => {
305
- if (!Array.isArray(suggestions) || suggestions.length === 0)
306
- return -1;
307
- const maxIndex = suggestions.length - 1;
308
- let itter = -1;
309
- let returnIdx = -1;
310
- let shouldSkip;
311
- do {
312
- ++itter;
313
- const maybeNextIdx = Math.trunc((returnIdx === -1 ? currentIndex : returnIdx) + direction);
314
- if (maybeNextIdx < 0) {
315
- returnIdx = maybeNextIdx > maxIndex ? 0 : maxIndex;
316
- }
317
- else {
318
- returnIdx = maybeNextIdx > maxIndex ? 0 : maybeNextIdx;
319
- }
320
- shouldSkip = suggestions[returnIdx]?.skip ?? false;
321
- } while (shouldSkip && itter <= maxIndex);
322
- return itter > maxIndex ? -1 : returnIdx;
619
+ if (!Array.isArray(suggestions) || suggestions.length === 0) return -1;
620
+ const maxIndex = suggestions.length - 1;
621
+ let itter = -1;
622
+ let returnIdx = -1;
623
+ let shouldSkip;
624
+
625
+ do {
626
+ var _suggestions$returnId, _suggestions$returnId2;
627
+
628
+ ++itter;
629
+ const maybeNextIdx = Math.trunc((returnIdx === -1 ? currentIndex : returnIdx) + direction);
630
+
631
+ if (maybeNextIdx < 0) {
632
+ returnIdx = maybeNextIdx > maxIndex ? 0 : maxIndex;
633
+ } else {
634
+ returnIdx = maybeNextIdx > maxIndex ? 0 : maybeNextIdx;
635
+ }
636
+
637
+ shouldSkip = (_suggestions$returnId = (_suggestions$returnId2 = suggestions[returnIdx]) === null || _suggestions$returnId2 === void 0 ? void 0 : _suggestions$returnId2.skip) !== null && _suggestions$returnId !== void 0 ? _suggestions$returnId : false;
638
+ } while (shouldSkip && itter <= maxIndex);
639
+
640
+ return itter > maxIndex ? -1 : returnIdx;
323
641
  };
324
- export default AutoSuggest;
642
+
643
+ export default AutoSuggest;