@jobber/components 2.86.0 → 2.86.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/Autocomplete/Autocomplete.d.ts +47 -47
- package/dist/Autocomplete/Menu.d.ts +9 -9
- package/dist/Autocomplete/Option.d.ts +15 -15
- package/dist/Autocomplete/index.d.ts +2 -2
- package/dist/Autocomplete/index.js +215 -211
- package/dist/Avatar/Avatar.d.ts +37 -37
- package/dist/Avatar/index.d.ts +1 -1
- package/dist/Avatar/index.js +7 -74
- package/dist/Avatar/utilities.d.ts +1 -1
- package/dist/Avatar-cfd04e86.js +82 -0
- package/dist/Banner/Banner.d.ts +19 -19
- package/dist/Banner/index.d.ts +1 -1
- package/dist/Banner/index.js +67 -65
- package/dist/Button/Button.d.ts +64 -64
- package/dist/Button/index.d.ts +1 -1
- package/dist/Button/index.js +9 -53
- package/dist/Button-5b2f1636.js +60 -0
- package/dist/ButtonDismiss/ButtonDismiss.d.ts +7 -7
- package/dist/ButtonDismiss/index.d.ts +1 -1
- package/dist/ButtonDismiss/index.js +10 -15
- package/dist/ButtonDismiss-4cde8f7c.js +15 -0
- package/dist/Card/Card.d.ts +31 -31
- package/dist/Card/CardClickable.d.ts +12 -12
- package/dist/Card/index.d.ts +1 -1
- package/dist/Card/index.js +7 -61
- package/dist/Card-368e01a3.js +68 -0
- package/dist/Checkbox/Checkbox.d.ts +52 -52
- package/dist/Checkbox/index.d.ts +1 -1
- package/dist/Checkbox/index.js +34 -32
- package/dist/Chips/Chip.d.ts +8 -8
- package/dist/Chips/ChipDismissible.d.ts +7 -7
- package/dist/Chips/ChipTypes.d.ts +59 -59
- package/dist/Chips/Chips.d.ts +2 -2
- package/dist/Chips/ChipsTypes.d.ts +82 -82
- package/dist/Chips/InternalChip.d.ts +2 -2
- package/dist/Chips/InternalChipAffix.d.ts +10 -10
- package/dist/Chips/InternalChipButton.d.ts +10 -10
- package/dist/Chips/InternalChipDismissible/InternalChipDismissible.d.ts +2 -2
- package/dist/Chips/InternalChipDismissible/InternalChipDismissibleInput.d.ts +2 -2
- package/dist/Chips/InternalChipDismissible/InternalChipDismissibleTypes.d.ts +13 -13
- package/dist/Chips/InternalChipDismissible/hooks/index.d.ts +5 -5
- package/dist/Chips/InternalChipDismissible/hooks/useInView.d.ts +5 -5
- package/dist/Chips/InternalChipDismissible/hooks/useInternalChipDismissible.d.ts +15 -15
- package/dist/Chips/InternalChipDismissible/hooks/useInternalChipDismissibleInput.d.ts +28 -28
- package/dist/Chips/InternalChipDismissible/hooks/useRepositionMenu.d.ts +16 -16
- package/dist/Chips/InternalChipDismissible/hooks/useScrollToActive.d.ts +2 -2
- package/dist/Chips/InternalChipDismissible/index.d.ts +1 -1
- package/dist/Chips/InternalChipMultiSelect.d.ts +4 -4
- package/dist/Chips/InternalChipSingleSelect.d.ts +4 -4
- package/dist/Chips/index.d.ts +3 -3
- package/dist/Chips/index.js +493 -491
- package/dist/Chips/utils/mdxUtils.d.ts +9 -9
- package/dist/ConfirmationModal/ConfirmationModal.d.ts +62 -62
- package/dist/ConfirmationModal/index.d.ts +1 -1
- package/dist/ConfirmationModal/index.js +20 -109
- package/dist/ConfirmationModal-b7ef110f.js +103 -0
- package/dist/Content/Content.d.ts +13 -13
- package/dist/Content/index.d.ts +1 -1
- package/dist/Content/index.js +5 -19
- package/dist/Content-18de5fbb.js +26 -0
- package/dist/Countdown/Countdown.d.ts +31 -31
- package/dist/Countdown/computeTimeUnit.d.ts +3 -3
- package/dist/Countdown/index.d.ts +1 -1
- package/dist/Countdown/index.js +63 -61
- package/dist/DataDump/DataDump.d.ts +20 -20
- package/dist/DataDump/index.d.ts +1 -1
- package/dist/DataDump/index.js +18 -17
- package/dist/DatePicker/DatePicker.d.ts +50 -50
- package/dist/DatePicker/DatePickerActivator.d.ts +12 -12
- package/dist/DatePicker/DatePickerCustomHeader.d.ts +2 -2
- package/dist/DatePicker/index.d.ts +1 -1
- package/dist/DatePicker/index.js +13 -97
- package/dist/DatePicker/useFocusOnSelectedDate.d.ts +5 -5
- package/dist/DatePicker-ad6f8630.js +103 -0
- package/dist/DescriptionList/DescriptionList.d.ts +10 -10
- package/dist/DescriptionList/index.d.ts +1 -1
- package/dist/DescriptionList/index.js +16 -15
- package/dist/Disclosure/Disclosure.d.ts +20 -20
- package/dist/Disclosure/index.d.ts +1 -1
- package/dist/Disclosure/index.js +32 -31
- package/dist/Divider/Divider.d.ts +16 -16
- package/dist/Divider/index.d.ts +1 -1
- package/dist/Divider/index.js +19 -17
- package/dist/Drawer/Drawer.d.ts +13 -13
- package/dist/Drawer/DrawerGrid.d.ts +6 -6
- package/dist/Drawer/index.d.ts +2 -2
- package/dist/Drawer/index.js +39 -37
- package/dist/Emphasis/Emphasis.d.ts +11 -11
- package/dist/Emphasis/index.d.ts +1 -1
- package/dist/Emphasis/index.js +7 -17
- package/dist/Emphasis-fd845639.js +21 -0
- package/dist/FeatureSwitch/FeatureSwitch.d.ts +51 -51
- package/dist/FeatureSwitch/index.d.ts +1 -1
- package/dist/FeatureSwitch/index.js +57 -55
- package/dist/Form/Form.d.ts +18 -18
- package/dist/Form/index.d.ts +1 -1
- package/dist/Form/index.js +58 -57
- package/dist/FormField/FormField.d.ts +2 -2
- package/dist/FormField/FormFieldAffix.d.ts +13 -13
- package/dist/FormField/FormFieldDescription.d.ts +6 -6
- package/dist/FormField/FormFieldPostFix.d.ts +5 -5
- package/dist/FormField/FormFieldTypes.d.ts +160 -160
- package/dist/FormField/FormFieldWrapper.d.ts +9 -9
- package/dist/FormField/index.d.ts +2 -2
- package/dist/FormField/index.js +15 -208
- package/dist/FormField-a92c7bac.js +213 -0
- package/dist/FormatDate/FormatDate.d.ts +12 -12
- package/dist/FormatDate/index.d.ts +1 -1
- package/dist/FormatDate/index.js +24 -23
- package/dist/FormatEmail/FormatEmail.d.ts +8 -8
- package/dist/FormatEmail/index.d.ts +1 -1
- package/dist/FormatEmail/index.js +12 -10
- package/dist/FormatFile/FormatFile.d.ts +30 -30
- package/dist/FormatFile/FormatFileDeleteButton.d.ts +6 -6
- package/dist/FormatFile/InternalThumbnail.d.ts +9 -9
- package/dist/FormatFile/index.d.ts +1 -1
- package/dist/FormatFile/index.js +21 -112
- package/dist/FormatFile-5391d4cf.js +112 -0
- package/dist/FormatRelativeDateTime/FormatRelativeDateTime.d.ts +11 -11
- package/dist/FormatRelativeDateTime/index.d.ts +1 -1
- package/dist/FormatRelativeDateTime/index.js +64 -63
- package/dist/FormatTime/FormatTime.d.ts +15 -15
- package/dist/FormatTime/index.d.ts +1 -1
- package/dist/FormatTime/index.js +28 -27
- package/dist/Gallery/Gallery.d.ts +2 -2
- package/dist/Gallery/GalleryTypes.d.ts +31 -31
- package/dist/Gallery/index.d.ts +1 -1
- package/dist/Gallery/index.js +82 -80
- package/dist/Heading/Heading.d.ts +14 -14
- package/dist/Heading/index.d.ts +1 -1
- package/dist/Heading/index.js +7 -53
- package/dist/Heading-56750113.js +57 -0
- package/dist/Icon/Icon.d.ts +22 -22
- package/dist/Icon/index.d.ts +1 -1
- package/dist/Icon/index.js +4 -35
- package/dist/Icon-d5ad1a6d.js +41 -0
- package/dist/InlineLabel/InlineLabel.d.ts +17 -17
- package/dist/InlineLabel/index.d.ts +1 -1
- package/dist/InlineLabel/index.js +20 -18
- package/dist/InputAvatar/InputAvatar.d.ts +22 -22
- package/dist/InputAvatar/index.d.ts +1 -1
- package/dist/InputAvatar/index.js +57 -56
- package/dist/InputDate/InputDate.d.ts +19 -19
- package/dist/InputDate/index.d.ts +1 -1
- package/dist/InputDate/index.js +34 -33
- package/dist/InputEmail/InputEmail.d.ts +5 -5
- package/dist/InputEmail/index.d.ts +1 -1
- package/dist/InputEmail/index.js +29 -28
- package/dist/InputFile/InputFile.d.ts +121 -121
- package/dist/InputFile/index.d.ts +1 -1
- package/dist/InputFile/index.js +15 -168
- package/dist/InputFile-b5cf90c3.js +174 -0
- package/dist/InputGroup/InputGroup.d.ts +11 -11
- package/dist/InputGroup/index.d.ts +1 -1
- package/dist/InputGroup/index.js +24 -22
- package/dist/InputNumber/InputNumber.d.ts +11 -11
- package/dist/InputNumber/index.d.ts +1 -1
- package/dist/InputNumber/index.js +52 -51
- package/dist/InputPassword/InputPassword.d.ts +12 -12
- package/dist/InputPassword/index.d.ts +1 -1
- package/dist/InputPassword/index.js +28 -27
- package/dist/InputText/InputText.d.ts +29 -29
- package/dist/InputText/index.d.ts +1 -1
- package/dist/InputText/index.js +15 -95
- package/dist/InputText-cb3be15c.js +91 -0
- package/dist/InputTime/InputTime.d.ts +2 -2
- package/dist/InputTime/InputTimeProps.d.ts +18 -18
- package/dist/InputTime/InputTimeSafari.d.ts +2 -2
- package/dist/InputTime/civilTimeConversions.d.ts +3 -3
- package/dist/InputTime/index.d.ts +1 -1
- package/dist/InputTime/index.js +402 -257
- package/dist/InputValidation/InputValidation.d.ts +8 -8
- package/dist/InputValidation/index.d.ts +1 -1
- package/dist/InputValidation/index.js +8 -24
- package/dist/InputValidation-24d3621a.js +28 -0
- package/dist/LightBox/LightBox.d.ts +37 -37
- package/dist/LightBox/index.d.ts +1 -1
- package/dist/LightBox/index.js +6 -34
- package/dist/LightBox-b893b656.js +42 -0
- package/dist/List/List.d.ts +11 -11
- package/dist/List/ListItem.d.ts +54 -54
- package/dist/List/index.d.ts +1 -1
- package/dist/List/index.js +76 -74
- package/dist/Markdown/Markdown.d.ts +17 -17
- package/dist/Markdown/index.d.ts +1 -1
- package/dist/Markdown/index.js +12 -64
- package/dist/Markdown-69986c49.js +68 -0
- package/dist/Menu/Menu.d.ts +46 -46
- package/dist/Menu/index.d.ts +1 -1
- package/dist/Menu/index.js +13 -128
- package/dist/Menu-6a392af6.js +134 -0
- package/dist/Modal/Modal.d.ts +22 -22
- package/dist/Modal/index.d.ts +1 -1
- package/dist/Modal/index.js +14 -127
- package/dist/Modal/useFocusTrap.d.ts +10 -10
- package/dist/Modal-aaaaf2df.js +132 -0
- package/dist/Page/Page.d.ts +59 -59
- package/dist/Page/index.d.ts +1 -1
- package/dist/Page/index.js +63 -61
- package/dist/Popover/Popover.d.ts +26 -26
- package/dist/Popover/index.d.ts +1 -1
- package/dist/Popover/index.js +49 -48
- package/dist/ProgressBar/ProgressBar.d.ts +18 -18
- package/dist/ProgressBar/index.d.ts +1 -1
- package/dist/ProgressBar/index.js +5 -22
- package/dist/ProgressBar-e9a49129.js +29 -0
- package/dist/RadioGroup/RadioGroup.d.ts +27 -27
- package/dist/RadioGroup/RadioOption.d.ts +34 -34
- package/dist/RadioGroup/index.d.ts +2 -2
- package/dist/RadioGroup/index.js +38 -37
- package/dist/RecurringSelect/CurrentRecurrenceComponent.d.ts +8 -8
- package/dist/RecurringSelect/RecurringSelect.d.ts +8 -8
- package/dist/RecurringSelect/components/DayOfMonthSelect.d.ts +8 -8
- package/dist/RecurringSelect/components/MonthlyDayOfWeekSelect.d.ts +8 -8
- package/dist/RecurringSelect/components/MonthlySelect.d.ts +8 -8
- package/dist/RecurringSelect/components/WeeklySelect.d.ts +8 -8
- package/dist/RecurringSelect/components/index.d.ts +4 -4
- package/dist/RecurringSelect/index.d.ts +2 -2
- package/dist/RecurringSelect/types.d.ts +65 -65
- package/dist/Select/Option.d.ts +17 -17
- package/dist/Select/Select.d.ts +10 -10
- package/dist/Select/index.d.ts +2 -2
- package/dist/Select/index.js +20 -19
- package/dist/Spinner/Spinner.d.ts +15 -15
- package/dist/Spinner/index.d.ts +1 -1
- package/dist/Spinner/index.js +5 -19
- package/dist/Spinner-18d3dee6.js +26 -0
- package/dist/StatusLabel/StatusLabel.d.ts +25 -25
- package/dist/StatusLabel/index.d.ts +1 -1
- package/dist/StatusLabel/index.js +21 -19
- package/dist/Switch/Switch.d.ts +14 -14
- package/dist/Switch/index.d.ts +1 -1
- package/dist/Switch/index.js +7 -53
- package/dist/Switch-d2bec677.js +60 -0
- package/dist/Table/Body.d.ts +6 -6
- package/dist/Table/Cells/Cell.d.ts +7 -7
- package/dist/Table/Cells/CellCurrency.d.ts +8 -8
- package/dist/Table/Cells/CellNumeric.d.ts +4 -4
- package/dist/Table/Footer.d.ts +6 -6
- package/dist/Table/Header.d.ts +6 -6
- package/dist/Table/Row.d.ts +6 -6
- package/dist/Table/Table.d.ts +6 -6
- package/dist/Table/index.d.ts +8 -8
- package/dist/Table/index.js +41 -39
- package/dist/Tabs/Tabs.d.ts +19 -19
- package/dist/Tabs/index.d.ts +1 -1
- package/dist/Tabs/index.js +69 -67
- package/dist/Text/Text.d.ts +9 -9
- package/dist/Text/index.d.ts +1 -1
- package/dist/Text/index.js +7 -29
- package/dist/Text-9bc093e9.js +32 -0
- package/dist/Toast/Toast.d.ts +17 -17
- package/dist/Toast/index.d.ts +1 -1
- package/dist/Toast/index.js +93 -93
- package/dist/Toast/showToast.d.ts +2 -2
- package/dist/Tooltip/Tooltip.d.ts +10 -10
- package/dist/Tooltip/index.d.ts +1 -1
- package/dist/Tooltip/index.js +11 -110
- package/dist/Tooltip/useTooltipPositioning.d.ts +18 -18
- package/dist/Tooltip-4396164d.js +116 -0
- package/dist/Typography/Typography.d.ts +38 -38
- package/dist/Typography/index.d.ts +1 -1
- package/dist/Typography/index.js +6 -57
- package/dist/Typography-7e542a72.js +64 -0
- package/dist/{chunk-17e02351.js → style-inject.es-dcee06b6.js} +0 -0
- package/dist/{chunk-b67af3cb.js → tslib.es6-5b50eb8e.js} +0 -0
- package/package.json +6 -8
- package/rollup.config.js +28 -3
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,22 @@ menu: Changelog
|
|
|
8
8
|
All notable changes to this project will be documented in this file.
|
|
9
9
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
10
10
|
|
|
11
|
+
## [2.86.2](https://github.com/GetJobber/atlantis/compare/@jobber/components@2.86.1...@jobber/components@2.86.2) (2022-11-01)
|
|
12
|
+
|
|
13
|
+
**Note:** Version bump only for package @jobber/components
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [2.86.1](https://github.com/GetJobber/atlantis/compare/@jobber/components@2.86.0...@jobber/components@2.86.1) (2022-10-17)
|
|
20
|
+
|
|
21
|
+
**Note:** Version bump only for package @jobber/components
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
11
27
|
# [2.86.0](https://github.com/GetJobber/atlantis/compare/@jobber/components@2.85.8...@jobber/components@2.86.0) (2022-10-14)
|
|
12
28
|
|
|
13
29
|
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { XOR } from "ts-xor";
|
|
2
|
-
import { GroupOption, Option } from "./Option";
|
|
3
|
-
import { FormFieldProps } from "../FormField";
|
|
4
|
-
declare type OptionCollection = XOR<Option[], GroupOption[]>;
|
|
5
|
-
interface AutocompleteProps extends Pick<FormFieldProps, "size" | "onBlur" | "onFocus" | "invalid"> {
|
|
6
|
-
/**
|
|
7
|
-
* Initial options to show when user first focuses the Autocomplete
|
|
8
|
-
*/
|
|
9
|
-
readonly initialOptions?: OptionCollection;
|
|
10
|
-
/**
|
|
11
|
-
* Set Autocomplete value.
|
|
12
|
-
*/
|
|
13
|
-
readonly value: Option | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Allow the autocomplete to use values not from the drop down menu.
|
|
16
|
-
*
|
|
17
|
-
* @default true
|
|
18
|
-
*/
|
|
19
|
-
readonly allowFreeForm?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Debounce in milliseconds for getOptions
|
|
22
|
-
*
|
|
23
|
-
* @default 300
|
|
24
|
-
*/
|
|
25
|
-
readonly debounce?: number;
|
|
26
|
-
/**
|
|
27
|
-
* Simplified onChange handler that only provides the new value.
|
|
28
|
-
* @param newValue
|
|
29
|
-
*/
|
|
30
|
-
onChange(newValue?: Option): void;
|
|
31
|
-
/**
|
|
32
|
-
* Called as the user types in the input. The autocomplete will display what
|
|
33
|
-
* is returned from this method to the user as available options.
|
|
34
|
-
* @param newInputText
|
|
35
|
-
*/
|
|
36
|
-
getOptions(newInputText: string): OptionCollection | Promise<OptionCollection>;
|
|
37
|
-
/**
|
|
38
|
-
* Hint text that goes above the value once the form is filled out.
|
|
39
|
-
*/
|
|
40
|
-
readonly placeholder: string;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Max statements disabled here to make room for the
|
|
44
|
-
* debounce functions.
|
|
45
|
-
*/
|
|
46
|
-
export declare function Autocomplete({ initialOptions, value, allowFreeForm, size, invalid, debounce: debounceRate, onChange, getOptions, placeholder, onBlur, onFocus, }: AutocompleteProps): JSX.Element;
|
|
47
|
-
export {};
|
|
1
|
+
import { XOR } from "ts-xor";
|
|
2
|
+
import { GroupOption, Option } from "./Option";
|
|
3
|
+
import { FormFieldProps } from "../FormField";
|
|
4
|
+
declare type OptionCollection = XOR<Option[], GroupOption[]>;
|
|
5
|
+
interface AutocompleteProps extends Pick<FormFieldProps, "size" | "onBlur" | "onFocus" | "invalid"> {
|
|
6
|
+
/**
|
|
7
|
+
* Initial options to show when user first focuses the Autocomplete
|
|
8
|
+
*/
|
|
9
|
+
readonly initialOptions?: OptionCollection;
|
|
10
|
+
/**
|
|
11
|
+
* Set Autocomplete value.
|
|
12
|
+
*/
|
|
13
|
+
readonly value: Option | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Allow the autocomplete to use values not from the drop down menu.
|
|
16
|
+
*
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
readonly allowFreeForm?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Debounce in milliseconds for getOptions
|
|
22
|
+
*
|
|
23
|
+
* @default 300
|
|
24
|
+
*/
|
|
25
|
+
readonly debounce?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Simplified onChange handler that only provides the new value.
|
|
28
|
+
* @param newValue
|
|
29
|
+
*/
|
|
30
|
+
onChange(newValue?: Option): void;
|
|
31
|
+
/**
|
|
32
|
+
* Called as the user types in the input. The autocomplete will display what
|
|
33
|
+
* is returned from this method to the user as available options.
|
|
34
|
+
* @param newInputText
|
|
35
|
+
*/
|
|
36
|
+
getOptions(newInputText: string): OptionCollection | Promise<OptionCollection>;
|
|
37
|
+
/**
|
|
38
|
+
* Hint text that goes above the value once the form is filled out.
|
|
39
|
+
*/
|
|
40
|
+
readonly placeholder: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Max statements disabled here to make room for the
|
|
44
|
+
* debounce functions.
|
|
45
|
+
*/
|
|
46
|
+
export declare function Autocomplete({ initialOptions, value, allowFreeForm, size, invalid, debounce: debounceRate, onChange, getOptions, placeholder, onBlur, onFocus, }: AutocompleteProps): JSX.Element;
|
|
47
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Option } from "./Option";
|
|
2
|
-
interface MenuProps {
|
|
3
|
-
readonly visible: boolean;
|
|
4
|
-
readonly options: Option[];
|
|
5
|
-
readonly selectedOption?: Option;
|
|
6
|
-
onOptionSelect(chosenOption: Option): void;
|
|
7
|
-
}
|
|
8
|
-
export declare function Menu({ visible, options, selectedOption, onOptionSelect, }: MenuProps): JSX.Element;
|
|
9
|
-
export {};
|
|
1
|
+
import { Option } from "./Option";
|
|
2
|
+
interface MenuProps {
|
|
3
|
+
readonly visible: boolean;
|
|
4
|
+
readonly options: Option[];
|
|
5
|
+
readonly selectedOption?: Option;
|
|
6
|
+
onOptionSelect(chosenOption: Option): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function Menu({ visible, options, selectedOption, onOptionSelect, }: MenuProps): JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { XOR } from "ts-xor";
|
|
2
|
-
declare type OptionValue = string | number;
|
|
3
|
-
interface BaseOption {
|
|
4
|
-
label: string;
|
|
5
|
-
}
|
|
6
|
-
export interface Option extends BaseOption {
|
|
7
|
-
value?: OptionValue;
|
|
8
|
-
description?: string;
|
|
9
|
-
details?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface GroupOption extends BaseOption {
|
|
12
|
-
options: Option[];
|
|
13
|
-
}
|
|
14
|
-
export declare type AnyOption = XOR<Option, GroupOption>;
|
|
15
|
-
export {};
|
|
1
|
+
import { XOR } from "ts-xor";
|
|
2
|
+
declare type OptionValue = string | number;
|
|
3
|
+
interface BaseOption {
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Option extends BaseOption {
|
|
7
|
+
value?: OptionValue;
|
|
8
|
+
description?: string;
|
|
9
|
+
details?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface GroupOption extends BaseOption {
|
|
12
|
+
options: Option[];
|
|
13
|
+
}
|
|
14
|
+
export declare type AnyOption = XOR<Option, GroupOption>;
|
|
15
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Autocomplete } from "./Autocomplete";
|
|
2
|
-
export * from "./Option";
|
|
1
|
+
export { Autocomplete } from "./Autocomplete";
|
|
2
|
+
export * from "./Option";
|
|
@@ -2,229 +2,233 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var __chunk_1 = require('../chunk-b67af3cb.js');
|
|
5
|
+
var tslib_es6 = require('../tslib.es6-5b50eb8e.js');
|
|
8
6
|
var React = require('react');
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
require('../
|
|
15
|
-
var
|
|
7
|
+
var debounce = require('lodash/debounce');
|
|
8
|
+
var styleInject_es = require('../style-inject.es-dcee06b6.js');
|
|
9
|
+
var classnames = require('classnames');
|
|
10
|
+
var useEventListener = require('@use-it/event-listener');
|
|
11
|
+
var Text = require('../Text-9bc093e9.js');
|
|
12
|
+
var Icon = require('../Icon-d5ad1a6d.js');
|
|
13
|
+
var Heading = require('../Heading-56750113.js');
|
|
14
|
+
var InputText = require('../InputText-cb3be15c.js');
|
|
15
|
+
require('../Typography-7e542a72.js');
|
|
16
16
|
require('@jobber/design');
|
|
17
|
-
|
|
18
|
-
var index$3 = require('../Heading/index.js');
|
|
17
|
+
require('../FormField-a92c7bac.js');
|
|
19
18
|
require('uuid');
|
|
20
19
|
require('react-hook-form');
|
|
21
|
-
require('../
|
|
20
|
+
require('../Button-5b2f1636.js');
|
|
22
21
|
require('react-router-dom');
|
|
23
|
-
require('../
|
|
22
|
+
require('../InputValidation-24d3621a.js');
|
|
24
23
|
require('framer-motion');
|
|
25
|
-
require('../
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
require('../Spinner-18d3dee6.js');
|
|
25
|
+
|
|
26
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
27
|
+
|
|
28
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
29
|
+
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce);
|
|
30
|
+
var classnames__default = /*#__PURE__*/_interopDefaultLegacy(classnames);
|
|
31
|
+
var useEventListener__default = /*#__PURE__*/_interopDefaultLegacy(useEventListener);
|
|
28
32
|
|
|
29
33
|
var css = "._3iJawkVmPDeT-G85L3PrR4 {\n position: relative;\n width: 100%;\n}\n\n.Af1qI_fw1xXvkJ0bbFJBR {\n display: none;\n position: absolute;\n z-index: var(--elevation-menu);\n width: 100%;\n /* Unfortunately this is how we define our line item picker height in jobber online.\n This is a concession to maintain visual parity. */\n max-height: 300px;\n box-shadow: var(--shadow-base);\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n border: var(--border-base) solid var(--color-color-border);\n border-radius: var(--radius-base);\n overflow: auto;\n scroll-behavior: smooth;\n background-color: var(--color-surface);\n}\n\n.Af1qI_fw1xXvkJ0bbFJBR h5 {\n padding: var(--space-small) 0 var(--space-smaller) var(--space-small);\n border-bottom: var(--border-base) solid var(--color-border--section);\n}\n\n.Af1qI_fw1xXvkJ0bbFJBR.WzLfyEQ4ab8OziNjJry2V {\n display: block;\n}\n\n.Af1qI_fw1xXvkJ0bbFJBR.WzLfyEQ4ab8OziNjJry2V:empty {\n display: none;\n}\n\n._1jtF2MKszvsdtf5A_eH2RW {\n display: -ms-flexbox;\n display: flex;\n width: 100%;\n -ms-flex-direction: row;\n flex-direction: row;\n -ms-flex-wrap: nowrap;\n flex-wrap: nowrap;\n -ms-flex-pack: start;\n justify-content: flex-start;\n -ms-flex-line-pack: stretch;\n align-content: stretch;\n -ms-flex-align: center;\n align-items: center;\n padding: var(--space-small);\n border: none;\n border-radius: var(--radius-base);\n text-align: left;\n list-style: none;\n background-color: transparent;\n cursor: pointer;\n transition: all var(--timing-base);\n}\n\n._1jtF2MKszvsdtf5A_eH2RW:hover,\n._1jtF2MKszvsdtf5A_eH2RW:focus,\n._1jtF2MKszvsdtf5A_eH2RW._251uShpt-dRyALyCV91boK {\n background-color: var(--color-surface--hover);\n outline-color: var(--color-focus);\n}\n\n._1jtF2MKszvsdtf5A_eH2RW._1gB8TepBLyFBEQfRE7HKyI:not(:last-child) {\n border-bottom: var(--border-base) solid var(--color-border);\n}\n\n.Af1qI_fw1xXvkJ0bbFJBR:hover ._1jtF2MKszvsdtf5A_eH2RW._251uShpt-dRyALyCV91boK:not(:hover) {\n background-color: transparent;\n outline-color: transparent;\n}\n\n._3iJawkVmPDeT-G85L3PrR4 ._1Izjm9c_0ZyI0B_UGAIJ_x:not(:first-child) {\n padding-top: var(--space-small);\n}\n\n._1jtF2MKszvsdtf5A_eH2RW ._2jEQ11E1vWaAghL4b35e4N {\n -ms-flex: 0 1 auto;\n flex: 0 1 auto;\n -ms-flex-item-align: auto;\n align-self: auto;\n width: var(--space-large);\n}\n\n._1jtF2MKszvsdtf5A_eH2RW ._9VoF70mJOE0wCLhUlEcxz {\n display: -ms-inline-flexbox;\n display: inline-flex;\n -ms-flex: 1 100%;\n flex: 1 100%;\n -ms-flex-wrap: wrap;\n flex-wrap: wrap;\n}\n\n._1jtF2MKszvsdtf5A_eH2RW ._2WHXg3Ns3j9p_cD0cOKSXe {\n -ms-flex: 2;\n flex: 2;\n}\n\n._1jtF2MKszvsdtf5A_eH2RW ._3RIm_h-piEE21P80O7ejtV {\n -ms-flex: 1;\n flex: 1;\n -ms-flex-item-align: end;\n align-self: flex-end;\n text-align: right;\n}\n";
|
|
30
34
|
var styles = {"autocomplete":"_3iJawkVmPDeT-G85L3PrR4","options":"Af1qI_fw1xXvkJ0bbFJBR","visible":"WzLfyEQ4ab8OziNjJry2V","option":"_1jtF2MKszvsdtf5A_eH2RW","active":"_251uShpt-dRyALyCV91boK","separator":"_1gB8TepBLyFBEQfRE7HKyI","heading":"_1Izjm9c_0ZyI0B_UGAIJ_x","icon":"_2jEQ11E1vWaAghL4b35e4N","text":"_9VoF70mJOE0wCLhUlEcxz","label":"_2WHXg3Ns3j9p_cD0cOKSXe","details":"_3RIm_h-piEE21P80O7ejtV"};
|
|
31
|
-
|
|
35
|
+
styleInject_es.styleInject(css);
|
|
32
36
|
|
|
33
|
-
var IndexChange;
|
|
34
|
-
(function (IndexChange) {
|
|
35
|
-
IndexChange[IndexChange["Previous"] = -1] = "Previous";
|
|
36
|
-
IndexChange[IndexChange["Next"] = 1] = "Next";
|
|
37
|
-
})(IndexChange || (IndexChange = {}));
|
|
38
|
-
function Menu(_a) {
|
|
39
|
-
var _b;
|
|
40
|
-
var visible = _a.visible, options = _a.options, selectedOption = _a.selectedOption, onOptionSelect = _a.onOptionSelect;
|
|
41
|
-
var _c =
|
|
42
|
-
var optionMenuClass =
|
|
43
|
-
_b[styles.visible] = visible,
|
|
44
|
-
_b));
|
|
45
|
-
var menuDiv = React.useRef();
|
|
46
|
-
var detectSeparatorCondition = function (option) {
|
|
47
|
-
return option.description || option.details;
|
|
48
|
-
};
|
|
49
|
-
var detectGroups = function (option) { return option.options; };
|
|
50
|
-
var addSeparators = options.some(detectSeparatorCondition);
|
|
51
|
-
var initialHighlight = options.some(detectGroups) ? 1 : 0;
|
|
52
|
-
setupKeyListeners();
|
|
53
|
-
React.useEffect(function () { return setHighlightedIndex(initialHighlight); }, [options]);
|
|
54
|
-
return (React__default.createElement("div", { className: optionMenuClass, ref: menuDiv }, options.map(function (option, index) {
|
|
55
|
-
var _a;
|
|
56
|
-
var optionClass =
|
|
57
|
-
_a[styles.active] = index === highlightedIndex,
|
|
58
|
-
_a[styles.separator] = addSeparators,
|
|
59
|
-
_a));
|
|
60
|
-
if (isGroup(option)) {
|
|
61
|
-
return (React__default.createElement("div", { key: option.label, className: styles.heading },
|
|
62
|
-
React__default.createElement(
|
|
63
|
-
}
|
|
64
|
-
return (React__default.createElement("button", { className: optionClass, key: option.value, onMouseDown: onOptionSelect.bind(undefined, option) },
|
|
65
|
-
React__default.createElement("div", { className: styles.icon }, isOptionSelected(selectedOption, option) && (React__default.createElement(
|
|
66
|
-
React__default.createElement("div", { className: styles.text },
|
|
67
|
-
React__default.createElement("div", { className: styles.label },
|
|
68
|
-
React__default.createElement(
|
|
69
|
-
option.description !== undefined && (React__default.createElement(
|
|
70
|
-
option.details !== undefined && (React__default.createElement("div", { className: styles.details },
|
|
71
|
-
React__default.createElement(
|
|
72
|
-
})));
|
|
73
|
-
function setupKeyListeners() {
|
|
74
|
-
useOnKeyDown("ArrowDown", function (event) {
|
|
75
|
-
var indexChange = arrowKeyPress(event, IndexChange.Next);
|
|
76
|
-
if (indexChange) {
|
|
77
|
-
setHighlightedIndex(Math.min(options.length - 1, highlightedIndex + indexChange));
|
|
78
|
-
}
|
|
79
|
-
if (menuDiv.current) {
|
|
80
|
-
scrollMenuIfItemNotInView(menuDiv.current, "down");
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
useOnKeyDown("ArrowUp", function (event) {
|
|
84
|
-
var indexChange = arrowKeyPress(event, IndexChange.Previous);
|
|
85
|
-
if (indexChange) {
|
|
86
|
-
setHighlightedIndex(Math.max(0, highlightedIndex + indexChange));
|
|
87
|
-
}
|
|
88
|
-
if (menuDiv.current) {
|
|
89
|
-
scrollMenuIfItemNotInView(menuDiv.current, "up");
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
function scrollMenuIfItemNotInView(menuDivElement, direction) {
|
|
93
|
-
var itemDiv = menuDivElement.querySelector("button." + styles.option + ":nth-child(" + (highlightedIndex + 1) + ")");
|
|
94
|
-
if (!itemDiv)
|
|
95
|
-
return;
|
|
96
|
-
var menuTop = menuDivElement.getBoundingClientRect().top;
|
|
97
|
-
var _a = itemDiv.getBoundingClientRect(), itemTop = _a.top, itemHeight = _a.height, itemBottom = _a.bottom;
|
|
98
|
-
var itemTrueBottom = itemBottom + itemHeight;
|
|
99
|
-
var menuBottom = menuDivElement.getBoundingClientRect().bottom;
|
|
100
|
-
if (direction == "up" && itemTop - itemHeight < menuTop) {
|
|
101
|
-
menuDivElement.scrollTop -= itemHeight;
|
|
102
|
-
}
|
|
103
|
-
else if (direction == "down" && itemTrueBottom > menuBottom) {
|
|
104
|
-
menuDivElement.scrollTop += itemHeight;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
useOnKeyDown("Enter", function (event) {
|
|
108
|
-
if (!visible)
|
|
109
|
-
return;
|
|
110
|
-
if (isGroup(options[highlightedIndex]))
|
|
111
|
-
return;
|
|
112
|
-
event.preventDefault();
|
|
113
|
-
onOptionSelect(options[highlightedIndex]);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function arrowKeyPress(event, direction) {
|
|
117
|
-
if (!visible)
|
|
118
|
-
return;
|
|
119
|
-
event.preventDefault();
|
|
120
|
-
var requestedIndex = options[highlightedIndex + direction];
|
|
121
|
-
return requestedIndex && isGroup(requestedIndex)
|
|
122
|
-
? direction + direction
|
|
123
|
-
: direction;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function isOptionSelected(selectedOption, option) {
|
|
127
|
-
return selectedOption && selectedOption.value === option.value;
|
|
128
|
-
}
|
|
129
|
-
// Split this out into a hooks package.
|
|
130
|
-
function useOnKeyDown(keyName, handler) {
|
|
131
|
-
// Pending: https://github.com/donavon/use-event-listener/pull/12
|
|
132
|
-
// The types in useEventListener mistakenly require a SyntheticEvent for the passed generic.
|
|
133
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
134
|
-
//@ts-ignore
|
|
135
|
-
|
|
136
|
-
if (event.key === keyName) {
|
|
137
|
-
handler(event);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
function isGroup(option) {
|
|
142
|
-
if (option.options)
|
|
143
|
-
return true;
|
|
144
|
-
return false;
|
|
37
|
+
var IndexChange;
|
|
38
|
+
(function (IndexChange) {
|
|
39
|
+
IndexChange[IndexChange["Previous"] = -1] = "Previous";
|
|
40
|
+
IndexChange[IndexChange["Next"] = 1] = "Next";
|
|
41
|
+
})(IndexChange || (IndexChange = {}));
|
|
42
|
+
function Menu(_a) {
|
|
43
|
+
var _b;
|
|
44
|
+
var visible = _a.visible, options = _a.options, selectedOption = _a.selectedOption, onOptionSelect = _a.onOptionSelect;
|
|
45
|
+
var _c = tslib_es6.__read(React.useState(0), 2), highlightedIndex = _c[0], setHighlightedIndex = _c[1];
|
|
46
|
+
var optionMenuClass = classnames__default["default"](styles.options, (_b = {},
|
|
47
|
+
_b[styles.visible] = visible,
|
|
48
|
+
_b));
|
|
49
|
+
var menuDiv = React.useRef();
|
|
50
|
+
var detectSeparatorCondition = function (option) {
|
|
51
|
+
return option.description || option.details;
|
|
52
|
+
};
|
|
53
|
+
var detectGroups = function (option) { return option.options; };
|
|
54
|
+
var addSeparators = options.some(detectSeparatorCondition);
|
|
55
|
+
var initialHighlight = options.some(detectGroups) ? 1 : 0;
|
|
56
|
+
setupKeyListeners();
|
|
57
|
+
React.useEffect(function () { return setHighlightedIndex(initialHighlight); }, [options]);
|
|
58
|
+
return (React__default["default"].createElement("div", { className: optionMenuClass, ref: menuDiv }, options.map(function (option, index) {
|
|
59
|
+
var _a;
|
|
60
|
+
var optionClass = classnames__default["default"](styles.option, (_a = {},
|
|
61
|
+
_a[styles.active] = index === highlightedIndex,
|
|
62
|
+
_a[styles.separator] = addSeparators,
|
|
63
|
+
_a));
|
|
64
|
+
if (isGroup(option)) {
|
|
65
|
+
return (React__default["default"].createElement("div", { key: option.label, className: styles.heading },
|
|
66
|
+
React__default["default"].createElement(Heading.Heading, { level: 5 }, option.label)));
|
|
67
|
+
}
|
|
68
|
+
return (React__default["default"].createElement("button", { className: optionClass, key: option.value, onMouseDown: onOptionSelect.bind(undefined, option) },
|
|
69
|
+
React__default["default"].createElement("div", { className: styles.icon }, isOptionSelected(selectedOption, option) && (React__default["default"].createElement(Icon.Icon, { name: "checkmark", size: "small" }))),
|
|
70
|
+
React__default["default"].createElement("div", { className: styles.text },
|
|
71
|
+
React__default["default"].createElement("div", { className: styles.label },
|
|
72
|
+
React__default["default"].createElement(Text.Text, null, option.label),
|
|
73
|
+
option.description !== undefined && (React__default["default"].createElement(Text.Text, { variation: "subdued" }, option.description))),
|
|
74
|
+
option.details !== undefined && (React__default["default"].createElement("div", { className: styles.details },
|
|
75
|
+
React__default["default"].createElement(Text.Text, null, option.details))))));
|
|
76
|
+
})));
|
|
77
|
+
function setupKeyListeners() {
|
|
78
|
+
useOnKeyDown("ArrowDown", function (event) {
|
|
79
|
+
var indexChange = arrowKeyPress(event, IndexChange.Next);
|
|
80
|
+
if (indexChange) {
|
|
81
|
+
setHighlightedIndex(Math.min(options.length - 1, highlightedIndex + indexChange));
|
|
82
|
+
}
|
|
83
|
+
if (menuDiv.current) {
|
|
84
|
+
scrollMenuIfItemNotInView(menuDiv.current, "down");
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
useOnKeyDown("ArrowUp", function (event) {
|
|
88
|
+
var indexChange = arrowKeyPress(event, IndexChange.Previous);
|
|
89
|
+
if (indexChange) {
|
|
90
|
+
setHighlightedIndex(Math.max(0, highlightedIndex + indexChange));
|
|
91
|
+
}
|
|
92
|
+
if (menuDiv.current) {
|
|
93
|
+
scrollMenuIfItemNotInView(menuDiv.current, "up");
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
function scrollMenuIfItemNotInView(menuDivElement, direction) {
|
|
97
|
+
var itemDiv = menuDivElement.querySelector("button." + styles.option + ":nth-child(" + (highlightedIndex + 1) + ")");
|
|
98
|
+
if (!itemDiv)
|
|
99
|
+
return;
|
|
100
|
+
var menuTop = menuDivElement.getBoundingClientRect().top;
|
|
101
|
+
var _a = itemDiv.getBoundingClientRect(), itemTop = _a.top, itemHeight = _a.height, itemBottom = _a.bottom;
|
|
102
|
+
var itemTrueBottom = itemBottom + itemHeight;
|
|
103
|
+
var menuBottom = menuDivElement.getBoundingClientRect().bottom;
|
|
104
|
+
if (direction == "up" && itemTop - itemHeight < menuTop) {
|
|
105
|
+
menuDivElement.scrollTop -= itemHeight;
|
|
106
|
+
}
|
|
107
|
+
else if (direction == "down" && itemTrueBottom > menuBottom) {
|
|
108
|
+
menuDivElement.scrollTop += itemHeight;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
useOnKeyDown("Enter", function (event) {
|
|
112
|
+
if (!visible)
|
|
113
|
+
return;
|
|
114
|
+
if (isGroup(options[highlightedIndex]))
|
|
115
|
+
return;
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
onOptionSelect(options[highlightedIndex]);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function arrowKeyPress(event, direction) {
|
|
121
|
+
if (!visible)
|
|
122
|
+
return;
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
var requestedIndex = options[highlightedIndex + direction];
|
|
125
|
+
return requestedIndex && isGroup(requestedIndex)
|
|
126
|
+
? direction + direction
|
|
127
|
+
: direction;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function isOptionSelected(selectedOption, option) {
|
|
131
|
+
return selectedOption && selectedOption.value === option.value;
|
|
132
|
+
}
|
|
133
|
+
// Split this out into a hooks package.
|
|
134
|
+
function useOnKeyDown(keyName, handler) {
|
|
135
|
+
// Pending: https://github.com/donavon/use-event-listener/pull/12
|
|
136
|
+
// The types in useEventListener mistakenly require a SyntheticEvent for the passed generic.
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
138
|
+
//@ts-ignore
|
|
139
|
+
useEventListener__default["default"]("keydown", function (event) {
|
|
140
|
+
if (event.key === keyName) {
|
|
141
|
+
handler(event);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function isGroup(option) {
|
|
146
|
+
if (option.options)
|
|
147
|
+
return true;
|
|
148
|
+
return false;
|
|
145
149
|
}
|
|
146
150
|
|
|
147
|
-
/**
|
|
148
|
-
* Max statements disabled here to make room for the
|
|
149
|
-
* debounce functions.
|
|
150
|
-
*/
|
|
151
|
-
// eslint-disable-next-line max-statements
|
|
152
|
-
function Autocomplete(_a) {
|
|
153
|
-
var _b = _a.initialOptions, initialOptions = _b === void 0 ? [] : _b, value = _a.value, _c = _a.allowFreeForm, allowFreeForm = _c === void 0 ? true : _c, _d = _a.size, size = _d === void 0 ? undefined : _d, invalid = _a.invalid, _e = _a.debounce, debounceRate = _e === void 0 ? 300 : _e, onChange = _a.onChange, getOptions = _a.getOptions, placeholder = _a.placeholder, onBlur = _a.onBlur, onFocus = _a.onFocus;
|
|
154
|
-
var _f;
|
|
155
|
-
var _g =
|
|
156
|
-
var _h =
|
|
157
|
-
var _j =
|
|
158
|
-
var delayedSearch =
|
|
159
|
-
React.useEffect(function () {
|
|
160
|
-
delayedSearch();
|
|
161
|
-
return delayedSearch.cancel;
|
|
162
|
-
}, [inputText]);
|
|
163
|
-
React.useEffect(function () {
|
|
164
|
-
var _a;
|
|
165
|
-
updateInput((_a = value === null || value === void 0 ? void 0 : value.label) !== null && _a !== void 0 ? _a : "");
|
|
166
|
-
}, [value]);
|
|
167
|
-
return (React__default.createElement("div", { className: styles.autocomplete },
|
|
168
|
-
React__default.createElement(
|
|
169
|
-
menuVisible && (React__default.createElement(Menu, { visible: true, options: options, selectedOption: value, onOptionSelect: handleMenuChange }))));
|
|
170
|
-
function updateInput(newText) {
|
|
171
|
-
setInputText(newText);
|
|
172
|
-
if (newText === "") {
|
|
173
|
-
setOptions(mapToOptions(initialOptions));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
function updateSearch() {
|
|
177
|
-
return
|
|
178
|
-
var updatedOptions, filteredOptions;
|
|
179
|
-
return
|
|
180
|
-
switch (_a.label) {
|
|
181
|
-
case 0: return [4 /*yield*/, getOptions(inputText)];
|
|
182
|
-
case 1:
|
|
183
|
-
updatedOptions = _a.sent();
|
|
184
|
-
filteredOptions = updatedOptions.filter(function (option) {
|
|
185
|
-
return "options" in option && option.options ? option.options.length > 0 : true;
|
|
186
|
-
});
|
|
187
|
-
setOptions(mapToOptions(filteredOptions));
|
|
188
|
-
return [2 /*return*/];
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
function handleMenuChange(chosenOption) {
|
|
194
|
-
onChange(chosenOption);
|
|
195
|
-
updateInput(chosenOption.label);
|
|
196
|
-
setMenuVisible(false);
|
|
197
|
-
}
|
|
198
|
-
function handleInputChange(newText) {
|
|
199
|
-
updateInput(newText);
|
|
200
|
-
if (allowFreeForm) {
|
|
201
|
-
onChange({ label: newText });
|
|
202
|
-
}
|
|
203
|
-
setMenuVisible(true);
|
|
204
|
-
}
|
|
205
|
-
function handleInputBlur() {
|
|
206
|
-
setMenuVisible(false);
|
|
207
|
-
if (value == undefined || value.label !== inputText) {
|
|
208
|
-
setInputText("");
|
|
209
|
-
onChange(undefined);
|
|
210
|
-
}
|
|
211
|
-
onBlur && onBlur();
|
|
212
|
-
}
|
|
213
|
-
function handleInputFocus() {
|
|
214
|
-
setMenuVisible(true);
|
|
215
|
-
if (onFocus) {
|
|
216
|
-
onFocus();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function mapToOptions(items) {
|
|
221
|
-
return items.reduce(function (result, item) {
|
|
222
|
-
result = result.concat([item]);
|
|
223
|
-
if (item.options) {
|
|
224
|
-
result = result.concat(item.options);
|
|
225
|
-
}
|
|
226
|
-
return result;
|
|
227
|
-
}, []);
|
|
151
|
+
/**
|
|
152
|
+
* Max statements disabled here to make room for the
|
|
153
|
+
* debounce functions.
|
|
154
|
+
*/
|
|
155
|
+
// eslint-disable-next-line max-statements
|
|
156
|
+
function Autocomplete(_a) {
|
|
157
|
+
var _b = _a.initialOptions, initialOptions = _b === void 0 ? [] : _b, value = _a.value, _c = _a.allowFreeForm, allowFreeForm = _c === void 0 ? true : _c, _d = _a.size, size = _d === void 0 ? undefined : _d, invalid = _a.invalid, _e = _a.debounce, debounceRate = _e === void 0 ? 300 : _e, onChange = _a.onChange, getOptions = _a.getOptions, placeholder = _a.placeholder, onBlur = _a.onBlur, onFocus = _a.onFocus;
|
|
158
|
+
var _f;
|
|
159
|
+
var _g = tslib_es6.__read(React.useState(initialOptions), 2), options = _g[0], setOptions = _g[1];
|
|
160
|
+
var _h = tslib_es6.__read(React.useState(false), 2), menuVisible = _h[0], setMenuVisible = _h[1];
|
|
161
|
+
var _j = tslib_es6.__read(React.useState((_f = value === null || value === void 0 ? void 0 : value.label) !== null && _f !== void 0 ? _f : ""), 2), inputText = _j[0], setInputText = _j[1];
|
|
162
|
+
var delayedSearch = debounce__default["default"](updateSearch, debounceRate);
|
|
163
|
+
React.useEffect(function () {
|
|
164
|
+
delayedSearch();
|
|
165
|
+
return delayedSearch.cancel;
|
|
166
|
+
}, [inputText]);
|
|
167
|
+
React.useEffect(function () {
|
|
168
|
+
var _a;
|
|
169
|
+
updateInput((_a = value === null || value === void 0 ? void 0 : value.label) !== null && _a !== void 0 ? _a : "");
|
|
170
|
+
}, [value]);
|
|
171
|
+
return (React__default["default"].createElement("div", { className: styles.autocomplete },
|
|
172
|
+
React__default["default"].createElement(InputText.InputText, { autocomplete: false, size: size, invalid: invalid, value: inputText, onChange: handleInputChange, placeholder: placeholder, onFocus: handleInputFocus, onBlur: handleInputBlur }),
|
|
173
|
+
menuVisible && (React__default["default"].createElement(Menu, { visible: true, options: options, selectedOption: value, onOptionSelect: handleMenuChange }))));
|
|
174
|
+
function updateInput(newText) {
|
|
175
|
+
setInputText(newText);
|
|
176
|
+
if (newText === "") {
|
|
177
|
+
setOptions(mapToOptions(initialOptions));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function updateSearch() {
|
|
181
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function () {
|
|
182
|
+
var updatedOptions, filteredOptions;
|
|
183
|
+
return tslib_es6.__generator(this, function (_a) {
|
|
184
|
+
switch (_a.label) {
|
|
185
|
+
case 0: return [4 /*yield*/, getOptions(inputText)];
|
|
186
|
+
case 1:
|
|
187
|
+
updatedOptions = _a.sent();
|
|
188
|
+
filteredOptions = updatedOptions.filter(function (option) {
|
|
189
|
+
return "options" in option && option.options ? option.options.length > 0 : true;
|
|
190
|
+
});
|
|
191
|
+
setOptions(mapToOptions(filteredOptions));
|
|
192
|
+
return [2 /*return*/];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function handleMenuChange(chosenOption) {
|
|
198
|
+
onChange(chosenOption);
|
|
199
|
+
updateInput(chosenOption.label);
|
|
200
|
+
setMenuVisible(false);
|
|
201
|
+
}
|
|
202
|
+
function handleInputChange(newText) {
|
|
203
|
+
updateInput(newText);
|
|
204
|
+
if (allowFreeForm) {
|
|
205
|
+
onChange({ label: newText });
|
|
206
|
+
}
|
|
207
|
+
setMenuVisible(true);
|
|
208
|
+
}
|
|
209
|
+
function handleInputBlur() {
|
|
210
|
+
setMenuVisible(false);
|
|
211
|
+
if (value == undefined || value.label !== inputText) {
|
|
212
|
+
setInputText("");
|
|
213
|
+
onChange(undefined);
|
|
214
|
+
}
|
|
215
|
+
onBlur && onBlur();
|
|
216
|
+
}
|
|
217
|
+
function handleInputFocus() {
|
|
218
|
+
setMenuVisible(true);
|
|
219
|
+
if (onFocus) {
|
|
220
|
+
onFocus();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function mapToOptions(items) {
|
|
225
|
+
return items.reduce(function (result, item) {
|
|
226
|
+
result = result.concat([item]);
|
|
227
|
+
if (item.options) {
|
|
228
|
+
result = result.concat(item.options);
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}, []);
|
|
228
232
|
}
|
|
229
233
|
|
|
230
234
|
exports.Autocomplete = Autocomplete;
|