@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.
- package/dist/components/Actions/Actions.js +21 -4
- package/dist/components/Actions/index.js +3 -1
- package/dist/components/Alert/Alert.css.js +28 -20
- package/dist/components/Alert/Alert.js +84 -26
- package/dist/components/Alert/index.js +3 -1
- package/dist/components/Anchor/Anchor.css.js +11 -3
- package/dist/components/Anchor/Anchor.js +53 -28
- package/dist/components/Anchor/index.js +3 -1
- package/dist/components/AutoSuggest/AutoSuggest.css.js +84 -76
- package/dist/components/AutoSuggest/AutoSuggest.js +621 -302
- package/dist/components/AutoSuggest/index.js +3 -1
- package/dist/components/AutoSuggest/useLayoutSuggestionVisible.js +29 -31
- package/dist/components/Badge/Badge.css.js +79 -71
- package/dist/components/Badge/Badge.js +44 -27
- package/dist/components/Badge/index.js +3 -1
- package/dist/components/Box/Box.js +122 -53
- package/dist/components/Box/argTypes.js +72 -105
- package/dist/components/Box/index.js +4 -2
- package/dist/components/Box/useBoxStyles.css.d.ts +4 -4
- package/dist/components/Box/useBoxStyles.css.d.ts.map +1 -1
- package/dist/components/Box/useBoxStyles.css.js +114 -89
- package/dist/components/Box/useBoxStyles.d.ts +7 -7
- package/dist/components/Box/useBoxStyles.d.ts.map +1 -1
- package/dist/components/Box/useBoxStyles.js +75 -47
- package/dist/components/BulletList/Bullet.css.js +49 -41
- package/dist/components/BulletList/Bullet.js +38 -24
- package/dist/components/BulletList/BulletList.css.js +13 -5
- package/dist/components/BulletList/BulletList.js +23 -10
- package/dist/components/BulletList/context.js +3 -1
- package/dist/components/BulletList/index.js +4 -2
- package/dist/components/BulletText/BulletText.css.js +21 -13
- package/dist/components/BulletText/BulletText.js +57 -16
- package/dist/components/BulletText/index.js +3 -1
- package/dist/components/Button/Button.css.js +243 -235
- package/dist/components/Button/Button.js +154 -91
- package/dist/components/Button/index.js +3 -1
- package/dist/components/CheckBox/CheckBox.css.js +28 -20
- package/dist/components/CheckBox/CheckBox.js +54 -16
- package/dist/components/CheckBox/index.js +3 -1
- package/dist/components/ColourInput/ColourInput.css.js +31 -23
- package/dist/components/ColourInput/ColourInput.js +70 -20
- package/dist/components/ColourInput/index.js +3 -1
- package/dist/components/Columns/Column.css.js +36 -26
- package/dist/components/Columns/Column.js +51 -16
- package/dist/components/Columns/Columns.css.js +39 -31
- package/dist/components/Columns/Columns.js +55 -22
- package/dist/components/Columns/index.js +4 -2
- package/dist/components/DateInput/DateInput.js +34 -7
- package/dist/components/DateInput/index.js +3 -1
- package/dist/components/DatePicker/DatePicker.css.js +40 -32
- package/dist/components/DatePicker/DatePicker.js +64 -23
- package/dist/components/DatePicker/index.js +3 -1
- package/dist/components/DividerLine/DividerLine.css.js +45 -37
- package/dist/components/DividerLine/DividerLine.js +22 -6
- package/dist/components/DividerLine/index.js +3 -1
- package/dist/components/Flyout/Flyout.js +41 -5
- package/dist/components/Flyout/index.js +3 -1
- package/dist/components/Heading/Heading.js +41 -21
- package/dist/components/Heading/index.js +3 -1
- package/dist/components/Icon/Icon.css.js +13 -5
- package/dist/components/Icon/Icon.js +26 -9
- package/dist/components/Icon/index.js +3 -1
- package/dist/components/Image/Image.js +23 -5
- package/dist/components/Image/ImageServerProvider.d.ts +1 -1
- package/dist/components/Image/ImageServerProvider.d.ts.map +1 -1
- package/dist/components/Image/ImageServerProvider.js +55 -35
- package/dist/components/Image/ResponsiveImage.js +46 -21
- package/dist/components/Image/SimpleImage.js +30 -2
- package/dist/components/Image/index.js +4 -2
- package/dist/components/Image/types.js +3 -1
- package/dist/components/Inline/Inline.js +74 -30
- package/dist/components/Inline/index.js +3 -1
- package/dist/components/LinearProgressIndicator/LinearProgressIndicator.css.js +56 -48
- package/dist/components/LinearProgressIndicator/LinearProgressIndicator.js +31 -7
- package/dist/components/LinearProgressIndicator/index.js +3 -1
- package/dist/components/LoadingBox/LoadingBox.css.js +26 -18
- package/dist/components/LoadingBox/LoadingBox.js +40 -7
- package/dist/components/LoadingBox/index.js +3 -1
- package/dist/components/Meta/Meta.css.js +16 -8
- package/dist/components/Meta/Meta.js +30 -8
- package/dist/components/Meta/index.js +3 -1
- package/dist/components/MinimalModal/MinimalModal.css.js +15 -7
- package/dist/components/MinimalModal/MinimalModal.js +67 -29
- package/dist/components/MinimalModal/index.js +3 -1
- package/dist/components/Modal/Modal.css.js +38 -30
- package/dist/components/Modal/Modal.js +129 -73
- package/dist/components/Modal/index.js +3 -1
- package/dist/components/NumberBubble/NumberBubble.css.js +12 -4
- package/dist/components/NumberBubble/NumberBubble.js +51 -23
- package/dist/components/NumberBubble/index.js +3 -1
- package/dist/components/NumberInput/NumberInput.js +67 -29
- package/dist/components/NumberInput/index.js +3 -1
- package/dist/components/OrderedList/OrderedList.css.js +16 -8
- package/dist/components/OrderedList/OrderedList.js +60 -26
- package/dist/components/OrderedList/index.js +3 -1
- package/dist/components/OutsideClick/OutsideClick.js +40 -35
- package/dist/components/OutsideClick/index.js +3 -1
- package/dist/components/OverdriveProvider/OverdriveProvider.js +33 -19
- package/dist/components/OverdriveProvider/index.js +3 -1
- package/dist/components/Pagination/Bubble.js +41 -19
- package/dist/components/Pagination/Pagination.css.js +28 -20
- package/dist/components/Pagination/Pagination.js +166 -67
- package/dist/components/Pagination/index.js +3 -1
- package/dist/components/Portal/Portal.js +40 -24
- package/dist/components/Portal/index.js +3 -1
- package/dist/components/Positioner/Positioner.css.js +14 -6
- package/dist/components/Positioner/Positioner.js +109 -85
- package/dist/components/Positioner/alignment.js +13 -10
- package/dist/components/Positioner/index.js +4 -2
- package/dist/components/ProgressBar/ProgressBar.css.js +14 -6
- package/dist/components/ProgressBar/ProgressBar.js +30 -12
- package/dist/components/ProgressBar/index.js +3 -1
- package/dist/components/ProgressBarGroup/ProgressBarGroup.css.js +12 -4
- package/dist/components/ProgressBarGroup/ProgressBarGroup.js +42 -14
- package/dist/components/ProgressBarGroup/index.js +3 -1
- package/dist/components/ProgressSpinner/ProgressSpinner.css.js +81 -73
- package/dist/components/ProgressSpinner/ProgressSpinner.js +32 -14
- package/dist/components/ProgressSpinner/index.js +3 -1
- package/dist/components/Radio/Radio.css.js +31 -23
- package/dist/components/Radio/Radio.js +58 -19
- package/dist/components/Radio/RadioGroup.js +32 -7
- package/dist/components/Radio/index.js +4 -2
- package/dist/components/Section/Section.css.js +13 -5
- package/dist/components/Section/Section.js +19 -4
- package/dist/components/Section/index.js +3 -1
- package/dist/components/SelectInput/SelectInput.css.js +19 -11
- package/dist/components/SelectInput/SelectInput.js +60 -11
- package/dist/components/SelectInput/index.js +3 -1
- package/dist/components/SimplePagination/SimplePagination.js +57 -17
- package/dist/components/SimplePagination/index.js +3 -1
- package/dist/components/Stack/Divider.css.js +12 -4
- package/dist/components/Stack/Divider.js +13 -4
- package/dist/components/Stack/Stack.css.js +18 -10
- package/dist/components/Stack/Stack.js +47 -23
- package/dist/components/Stack/index.js +3 -1
- package/dist/components/StandardModal/StandardModal.css.js +69 -57
- package/dist/components/StandardModal/StandardModal.js +127 -52
- package/dist/components/StandardModal/index.js +3 -1
- package/dist/components/StarRating/StarRating.css.js +16 -8
- package/dist/components/StarRating/StarRating.js +90 -46
- package/dist/components/StarRating/index.js +3 -1
- package/dist/components/Stepper/Stepper.css.js +46 -36
- package/dist/components/Stepper/Stepper.js +159 -66
- package/dist/components/Stepper/index.js +3 -1
- package/dist/components/Switch/Switch.css.js +54 -46
- package/dist/components/Switch/Switch.js +54 -21
- package/dist/components/Switch/index.js +3 -1
- package/dist/components/Table/Table.css.js +14 -6
- package/dist/components/Table/Table.js +29 -6
- package/dist/components/Table/TableCell.css.js +28 -20
- package/dist/components/Table/TableCell.js +41 -11
- package/dist/components/Table/TableHeadCell.css.js +61 -50
- package/dist/components/Table/TableHeadCell.js +86 -40
- package/dist/components/Table/TableRow.js +18 -3
- package/dist/components/Table/TableRowGroup.js +16 -3
- package/dist/components/Table/context.js +21 -10
- package/dist/components/Table/index.js +7 -5
- package/dist/components/Tabs/Tab.css.js +43 -35
- package/dist/components/Tabs/Tab.js +79 -49
- package/dist/components/Tabs/TabList.css.js +30 -22
- package/dist/components/Tabs/TabList.js +122 -67
- package/dist/components/Tabs/TabPane.css.js +11 -3
- package/dist/components/Tabs/TabPane.js +32 -15
- package/dist/components/Tabs/TabPanes.css.js +16 -8
- package/dist/components/Tabs/TabPanes.js +23 -6
- package/dist/components/Tabs/Tabs.js +22 -10
- package/dist/components/Tabs/index.js +7 -5
- package/dist/components/Text/Text.js +37 -15
- package/dist/components/Text/index.js +4 -2
- package/dist/components/Text/useTextStyles.css.js +42 -20
- package/dist/components/Text/useTextStyles.js +20 -5
- package/dist/components/TextAreaInput/TextAreaInput.js +35 -7
- package/dist/components/TextAreaInput/index.js +3 -1
- package/dist/components/TextBubble/TextBubble.css.js +13 -5
- package/dist/components/TextBubble/TextBubble.js +66 -29
- package/dist/components/TextBubble/index.js +3 -1
- package/dist/components/TextContainer/TextContainer.js +44 -9
- package/dist/components/TextContainer/index.js +3 -1
- package/dist/components/TextInput/TextInput.js +36 -5
- package/dist/components/TextInput/index.js +3 -1
- package/dist/components/TextLink/TextLink.css.js +23 -15
- package/dist/components/TextLink/TextLink.js +63 -24
- package/dist/components/TextLink/index.js +3 -1
- package/dist/components/ThemeOverrideProvider/ThemeOverrideDebugger.d.ts +3 -0
- package/dist/components/ThemeOverrideProvider/ThemeOverrideDebugger.d.ts.map +1 -0
- package/dist/components/ThemeOverrideProvider/ThemeOverrideDebugger.js +80 -0
- package/dist/components/ThemeOverrideProvider/ThemeOverrideProvider.d.ts +22 -0
- package/dist/components/ThemeOverrideProvider/ThemeOverrideProvider.d.ts.map +1 -0
- package/dist/components/ThemeOverrideProvider/ThemeOverrideProvider.js +39 -0
- package/dist/components/ThemeOverrideProvider/index.d.ts +3 -0
- package/dist/components/ThemeOverrideProvider/index.d.ts.map +1 -0
- package/dist/components/ThemeOverrideProvider/index.js +4 -0
- package/dist/components/ThemeOverrideProvider/useBuildThemeOverrides.d.ts +17 -0
- package/dist/components/ThemeOverrideProvider/useBuildThemeOverrides.d.ts.map +1 -0
- package/dist/components/ThemeOverrideProvider/useBuildThemeOverrides.js +97 -0
- package/dist/components/ThemeProvider/ThemeProvider.js +30 -11
- package/dist/components/ThemeProvider/index.js +3 -1
- package/dist/components/Toaster/Toast.css.js +18 -10
- package/dist/components/Toaster/Toast.js +222 -108
- package/dist/components/Toaster/index.js +3 -1
- package/dist/components/Tooltip/Tooltip.css.js +21 -9
- package/dist/components/Tooltip/Tooltip.js +72 -40
- package/dist/components/Tooltip/index.js +3 -1
- package/dist/components/VisuallyHidden/VisuallyHidden.css.js +13 -5
- package/dist/components/VisuallyHidden/VisuallyHidden.js +20 -4
- package/dist/components/VisuallyHidden/index.js +3 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +59 -56
- package/dist/components/private/CheckableBase/CheckableBase.css.js +46 -38
- package/dist/components/private/CheckableBase/CheckableBase.js +91 -27
- package/dist/components/private/CheckableBase/index.js +3 -1
- package/dist/components/private/CheckableBase/useCheckableStyles.js +5 -3
- package/dist/components/private/InputBase/HintText.css.js +11 -3
- package/dist/components/private/InputBase/HintText.js +28 -14
- package/dist/components/private/InputBase/InputState.css.js +96 -80
- package/dist/components/private/InputBase/NotchedBase.css.js +157 -162
- package/dist/components/private/InputBase/NotchedBase.js +116 -76
- package/dist/components/private/InputBase/index.js +3 -1
- package/dist/components/private/InputBase/withEnhancedInput.css.js +117 -109
- package/dist/components/private/InputBase/withEnhancedInput.js +190 -92
- package/dist/hooks/useAttachedBoxes/index.js +3 -1
- package/dist/hooks/useAttachedBoxes/useAttachedBoxes.css.js +26 -18
- package/dist/hooks/useAttachedBoxes/useAttachedBoxes.js +71 -46
- package/dist/hooks/useMedia/index.js +3 -1
- package/dist/hooks/useMedia/useMedia.js +44 -34
- package/dist/hooks/useNegativeMargin/useNegativeMargin.js +4 -2
- package/dist/hooks/useNegativeMargin/useNegativeMarginLeft.css.js +13 -5
- package/dist/hooks/useNegativeMargin/useNegativeMarginLeft.js +6 -4
- package/dist/hooks/useNegativeMargin/useNegativeMarginTop.css.js +12 -4
- package/dist/hooks/useNegativeMargin/useNegativeMarginTop.js +6 -4
- package/dist/hooks/useResponsiveValue/index.js +3 -1
- package/dist/hooks/useResponsiveValue/useResponsiveValue.js +14 -14
- package/dist/hooks/useWindowScrollLock/index.js +15 -13
- package/dist/index.js +7 -5
- package/dist/reset/globalFonts.css.js +20 -12
- package/dist/reset/globalReset.css.js +21 -13
- package/dist/reset/reset.css.js +105 -109
- package/dist/themes/base/index.d.ts +1 -0
- package/dist/themes/base/index.d.ts.map +1 -1
- package/dist/themes/base/index.js +10 -6
- package/dist/themes/base/tokens.js +264 -257
- package/dist/themes/base/vars.css.js +10 -2
- package/dist/themes/flat_red/index.d.ts +1 -0
- package/dist/themes/flat_red/index.d.ts.map +1 -1
- package/dist/themes/flat_red/index.js +10 -6
- package/dist/themes/flat_red/tokens.js +104 -98
- package/dist/themes/flat_red/vars.css.js +10 -2
- package/dist/themes/helpers.js +60 -51
- package/dist/themes/index.js +4 -2
- package/dist/themes/makeTheme.js +27 -16
- package/dist/themes/theme.css.js +271 -259
- package/dist/themes/tokens.js +3 -1
- package/dist/utils/index.js +93 -77
- package/dist/utils/mapTokenToProperty.js +22 -10
- package/dist/utils/number.js +21 -24
- package/dist/utils/resolveResponsiveProps.js +29 -31
- package/dist/utils/responsiveProps.css.js +29 -17
- package/dist/utils/responsiveStyle.js +26 -16
- 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
|
|
6
|
-
import { useMedia } from
|
|
7
|
-
import { useWindowScrollLock } from
|
|
8
|
-
import { setRef, useId } from
|
|
9
|
-
import { Box } from
|
|
10
|
-
import { Button } from
|
|
11
|
-
import { Icon } from
|
|
12
|
-
import { Portal } from
|
|
13
|
-
import { Positioner } from
|
|
14
|
-
import { EAlignment } from
|
|
15
|
-
import { Text } from
|
|
16
|
-
import { withEnhancedInput } from
|
|
17
|
-
import * as styles from
|
|
18
|
-
import { useLayoutSuggestionVisible } from
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
245
|
-
index: idx,
|
|
349
|
+
type: event.key === 'ArrowDown' ? ActionTypes.INPUT_ARROW_DOWN : ActionTypes.INPUT_ARROW_UP
|
|
246
350
|
});
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
362
|
+
type: ActionTypes.INPUT_ENTER
|
|
254
363
|
});
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
552
|
+
primitiveType: 'text',
|
|
553
|
+
withPrefixIcon: true,
|
|
554
|
+
withSuffixIcon: false
|
|
291
555
|
});
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
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
|
-
|
|
642
|
+
|
|
643
|
+
export default AutoSuggest;
|