@transferwise/components 0.0.0-experimental-a9ab536 → 0.0.0-experimental-3df0347
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/build/dateInput/DateInput.js +5 -12
- package/build/dateInput/DateInput.js.map +1 -1
- package/build/dateInput/DateInput.mjs +4 -11
- package/build/dateInput/DateInput.mjs.map +1 -1
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.js +8 -16
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.js.map +1 -1
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.mjs +6 -14
- package/build/expressiveMoneyInput/currencySelector/CurrencySelector.mjs.map +1 -1
- package/build/index.js +7 -14
- package/build/index.js.map +1 -1
- package/build/index.mjs +3 -10
- package/build/index.mjs.map +1 -1
- package/build/inputs/SelectInput.js +890 -0
- package/build/inputs/SelectInput.js.map +1 -0
- package/build/inputs/SelectInput.messages.js.map +1 -0
- package/build/inputs/SelectInput.messages.mjs.map +1 -0
- package/build/inputs/SelectInput.mjs +881 -0
- package/build/inputs/SelectInput.mjs.map +1 -0
- package/build/inputs/{SelectInput/BottomSheet/SelectInputBottomSheet.js → _BottomSheet.js} +7 -7
- package/build/inputs/_BottomSheet.js.map +1 -0
- package/build/inputs/{SelectInput/BottomSheet/SelectInputBottomSheet.mjs → _BottomSheet.mjs} +7 -7
- package/build/inputs/_BottomSheet.mjs.map +1 -0
- package/build/inputs/{SelectInput/ButtonInput/SelectInputButtonInput.js → _ButtonInput.js} +5 -5
- package/build/inputs/_ButtonInput.js.map +1 -0
- package/build/inputs/{SelectInput/ButtonInput/SelectInputButtonInput.mjs → _ButtonInput.mjs} +5 -5
- package/build/inputs/_ButtonInput.mjs.map +1 -0
- package/build/inputs/{SelectInput/Popover/SelectInputPopover.js → _Popover.js} +4 -4
- package/build/inputs/_Popover.js.map +1 -0
- package/build/inputs/{SelectInput/Popover/SelectInputPopover.mjs → _Popover.mjs} +4 -4
- package/build/inputs/_Popover.mjs.map +1 -0
- package/build/main.css +91 -91
- package/build/moneyInput/MoneyInput.js +2 -9
- package/build/moneyInput/MoneyInput.js.map +1 -1
- package/build/moneyInput/MoneyInput.mjs +1 -8
- package/build/moneyInput/MoneyInput.mjs.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.js +3 -10
- package/build/phoneNumberInput/PhoneNumberInput.js.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.mjs +2 -9
- package/build/phoneNumberInput/PhoneNumberInput.mjs.map +1 -1
- package/build/styles/main.css +91 -91
- package/build/styles/sentimentSurface/SentimentSurface.css +1 -1
- package/build/types/inputs/{SelectInput/SelectInput.types.d.ts → SelectInput.d.ts} +38 -12
- package/build/types/inputs/SelectInput.d.ts.map +1 -0
- package/build/types/inputs/SelectInput.messages.d.ts.map +1 -0
- package/build/types/inputs/{SelectInput/BottomSheet/SelectInputBottomSheet.d.ts → _BottomSheet.d.ts} +3 -3
- package/build/types/inputs/_BottomSheet.d.ts.map +1 -0
- package/build/types/inputs/_ButtonInput.d.ts +5 -0
- package/build/types/inputs/_ButtonInput.d.ts.map +1 -0
- package/build/types/inputs/{SelectInput/Popover/SelectInputPopover.d.ts → _Popover.d.ts} +3 -3
- package/build/types/inputs/_Popover.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/inputs/{SelectInput/_stories/SelectInput.docs.mdx → SelectInput.docs.mdx} +1 -0
- package/src/inputs/SelectInput.less +219 -0
- package/src/inputs/{SelectInput/_stories/SelectInput.story.tsx → SelectInput.story.tsx} +8 -11
- package/src/inputs/{SelectInput/_stories/SelectInput.test.story.tsx → SelectInput.test.story.tsx} +10 -5
- package/src/inputs/{SelectInput/SelectInput.test.tsx → SelectInput.test.tsx} +11 -9
- package/src/inputs/SelectInput.tsx +1269 -0
- package/src/inputs/{SelectInput/BottomSheet/SelectInputBottomSheet.tsx → _BottomSheet.tsx} +7 -7
- package/src/inputs/{SelectInput/ButtonInput/SelectInputButtonInput.tsx → _ButtonInput.tsx} +5 -5
- package/src/inputs/{SelectInput/Popover/SelectInputPopover.tsx → _Popover.tsx} +4 -4
- package/src/main.css +91 -91
- package/src/main.less +1 -1
- package/src/sentimentSurface/SentimentSurface.css +1 -1
- package/src/sentimentSurface/SentimentSurface.less +1 -1
- package/build/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.js.map +0 -1
- package/build/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.mjs.map +0 -1
- package/build/inputs/SelectInput/ButtonInput/SelectInputButtonInput.js.map +0 -1
- package/build/inputs/SelectInput/ButtonInput/SelectInputButtonInput.mjs.map +0 -1
- package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.js +0 -27
- package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.js.map +0 -1
- package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.mjs +0 -25
- package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.mjs.map +0 -1
- package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.js +0 -59
- package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.js.map +0 -1
- package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.mjs +0 -56
- package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.mjs.map +0 -1
- package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.js +0 -50
- package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.js.map +0 -1
- package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.mjs +0 -48
- package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.mjs.map +0 -1
- package/build/inputs/SelectInput/ItemView/SelectInputItemView.js +0 -47
- package/build/inputs/SelectInput/ItemView/SelectInputItemView.js.map +0 -1
- package/build/inputs/SelectInput/ItemView/SelectInputItemView.mjs +0 -45
- package/build/inputs/SelectInput/ItemView/SelectInputItemView.mjs.map +0 -1
- package/build/inputs/SelectInput/Option/SelectInputOption.js +0 -42
- package/build/inputs/SelectInput/Option/SelectInputOption.js.map +0 -1
- package/build/inputs/SelectInput/Option/SelectInputOption.mjs +0 -40
- package/build/inputs/SelectInput/Option/SelectInputOption.mjs.map +0 -1
- package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.js +0 -40
- package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.js.map +0 -1
- package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.mjs +0 -38
- package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.mjs.map +0 -1
- package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.js +0 -48
- package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.js.map +0 -1
- package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.mjs +0 -46
- package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.mjs.map +0 -1
- package/build/inputs/SelectInput/Options/SelectInputOptions.js +0 -300
- package/build/inputs/SelectInput/Options/SelectInputOptions.js.map +0 -1
- package/build/inputs/SelectInput/Options/SelectInputOptions.mjs +0 -298
- package/build/inputs/SelectInput/Options/SelectInputOptions.mjs.map +0 -1
- package/build/inputs/SelectInput/Popover/SelectInputPopover.js.map +0 -1
- package/build/inputs/SelectInput/Popover/SelectInputPopover.mjs.map +0 -1
- package/build/inputs/SelectInput/SelectInput.contexts.js +0 -29
- package/build/inputs/SelectInput/SelectInput.contexts.js.map +0 -1
- package/build/inputs/SelectInput/SelectInput.contexts.mjs +0 -24
- package/build/inputs/SelectInput/SelectInput.contexts.mjs.map +0 -1
- package/build/inputs/SelectInput/SelectInput.js +0 -222
- package/build/inputs/SelectInput/SelectInput.js.map +0 -1
- package/build/inputs/SelectInput/SelectInput.messages.js.map +0 -1
- package/build/inputs/SelectInput/SelectInput.messages.mjs.map +0 -1
- package/build/inputs/SelectInput/SelectInput.mjs +0 -216
- package/build/inputs/SelectInput/SelectInput.mjs.map +0 -1
- package/build/inputs/SelectInput/SelectInput.utils.js +0 -164
- package/build/inputs/SelectInput/SelectInput.utils.js.map +0 -1
- package/build/inputs/SelectInput/SelectInput.utils.mjs +0 -154
- package/build/inputs/SelectInput/SelectInput.utils.mjs.map +0 -1
- package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js +0 -43
- package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js.map +0 -1
- package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs +0 -37
- package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs.map +0 -1
- package/build/styles/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.css +0 -96
- package/build/styles/inputs/SelectInput/ButtonInput/SelectInputButtonInput.css +0 -16
- package/build/styles/inputs/SelectInput/ClearButton/SelectInputClearButton.css +0 -46
- package/build/styles/inputs/SelectInput/ItemView/SelectInputItemView.css +0 -16
- package/build/styles/inputs/SelectInput/Option/SelectInputOption.css +0 -33
- package/build/styles/inputs/SelectInput/OptionContent/SelectInputOptionContent.css +0 -37
- package/build/styles/inputs/SelectInput/Options/SelectInputOptions.css +0 -81
- package/build/styles/inputs/SelectInput/Popover/SelectInputPopover.css +0 -46
- package/build/types/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/BottomSheet/index.d.ts +0 -3
- package/build/types/inputs/SelectInput/BottomSheet/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/ButtonInput/SelectInputButtonInput.d.ts +0 -5
- package/build/types/inputs/SelectInput/ButtonInput/SelectInputButtonInput.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/ButtonInput/index.d.ts +0 -3
- package/build/types/inputs/SelectInput/ButtonInput/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/ClearButton/SelectInputClearButton.d.ts +0 -7
- package/build/types/inputs/SelectInput/ClearButton/SelectInputClearButton.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/ClearButton/index.d.ts +0 -3
- package/build/types/inputs/SelectInput/ClearButton/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.d.ts +0 -16
- package/build/types/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/DefaultRenderTrigger/index.d.ts +0 -2
- package/build/types/inputs/SelectInput/DefaultRenderTrigger/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.d.ts +0 -12
- package/build/types/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/ItemView/GroupItemView/index.d.ts +0 -3
- package/build/types/inputs/SelectInput/ItemView/GroupItemView/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/ItemView/SelectInputItemView.d.ts +0 -14
- package/build/types/inputs/SelectInput/ItemView/SelectInputItemView.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/ItemView/index.d.ts +0 -4
- package/build/types/inputs/SelectInput/ItemView/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/Option/SelectInputOption.d.ts +0 -14
- package/build/types/inputs/SelectInput/Option/SelectInputOption.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/Option/index.d.ts +0 -3
- package/build/types/inputs/SelectInput/Option/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/OptionContent/SelectInputOptionContent.d.ts +0 -16
- package/build/types/inputs/SelectInput/OptionContent/SelectInputOptionContent.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/OptionContent/index.d.ts +0 -3
- package/build/types/inputs/SelectInput/OptionContent/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.d.ts +0 -12
- package/build/types/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/Options/OptionsContainer/index.d.ts +0 -3
- package/build/types/inputs/SelectInput/Options/OptionsContainer/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/Options/SelectInputOptions.d.ts +0 -21
- package/build/types/inputs/SelectInput/Options/SelectInputOptions.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/Options/index.d.ts +0 -4
- package/build/types/inputs/SelectInput/Options/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/Popover/SelectInputPopover.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/Popover/index.d.ts +0 -3
- package/build/types/inputs/SelectInput/Popover/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/SelectInput.contexts.d.ts +0 -33
- package/build/types/inputs/SelectInput/SelectInput.contexts.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/SelectInput.d.ts +0 -10
- package/build/types/inputs/SelectInput/SelectInput.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/SelectInput.messages.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/SelectInput.types.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/SelectInput.utils.d.ts +0 -61
- package/build/types/inputs/SelectInput/SelectInput.utils.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts +0 -18
- package/build/types/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/TriggerButton/index.d.ts +0 -3
- package/build/types/inputs/SelectInput/TriggerButton/index.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/components.d.ts +0 -10
- package/build/types/inputs/SelectInput/components.d.ts.map +0 -1
- package/build/types/inputs/SelectInput/index.d.ts +0 -12
- package/build/types/inputs/SelectInput/index.d.ts.map +0 -1
- package/src/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.css +0 -96
- package/src/inputs/SelectInput/BottomSheet/index.ts +0 -2
- package/src/inputs/SelectInput/ButtonInput/SelectInputButtonInput.css +0 -16
- package/src/inputs/SelectInput/ButtonInput/index.ts +0 -2
- package/src/inputs/SelectInput/ClearButton/SelectInputClearButton.css +0 -46
- package/src/inputs/SelectInput/ClearButton/SelectInputClearButton.less +0 -40
- package/src/inputs/SelectInput/ClearButton/SelectInputClearButton.tsx +0 -29
- package/src/inputs/SelectInput/ClearButton/index.ts +0 -2
- package/src/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.tsx +0 -74
- package/src/inputs/SelectInput/DefaultRenderTrigger/index.ts +0 -5
- package/src/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.tsx +0 -64
- package/src/inputs/SelectInput/ItemView/GroupItemView/index.ts +0 -2
- package/src/inputs/SelectInput/ItemView/SelectInputItemView.css +0 -16
- package/src/inputs/SelectInput/ItemView/SelectInputItemView.less +0 -17
- package/src/inputs/SelectInput/ItemView/SelectInputItemView.tsx +0 -51
- package/src/inputs/SelectInput/ItemView/index.ts +0 -3
- package/src/inputs/SelectInput/Option/SelectInputOption.css +0 -33
- package/src/inputs/SelectInput/Option/SelectInputOption.less +0 -32
- package/src/inputs/SelectInput/Option/SelectInputOption.tsx +0 -60
- package/src/inputs/SelectInput/Option/index.ts +0 -2
- package/src/inputs/SelectInput/OptionContent/SelectInputOptionContent.css +0 -37
- package/src/inputs/SelectInput/OptionContent/SelectInputOptionContent.less +0 -38
- package/src/inputs/SelectInput/OptionContent/SelectInputOptionContent.tsx +0 -75
- package/src/inputs/SelectInput/OptionContent/index.ts +0 -2
- package/src/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.tsx +0 -62
- package/src/inputs/SelectInput/Options/OptionsContainer/index.ts +0 -2
- package/src/inputs/SelectInput/Options/SelectInputOptions.css +0 -81
- package/src/inputs/SelectInput/Options/SelectInputOptions.less +0 -77
- package/src/inputs/SelectInput/Options/SelectInputOptions.tsx +0 -418
- package/src/inputs/SelectInput/Options/index.ts +0 -3
- package/src/inputs/SelectInput/Popover/SelectInputPopover.css +0 -46
- package/src/inputs/SelectInput/Popover/index.ts +0 -2
- package/src/inputs/SelectInput/SelectInput.contexts.tsx +0 -40
- package/src/inputs/SelectInput/SelectInput.less +0 -22
- package/src/inputs/SelectInput/SelectInput.tsx +0 -258
- package/src/inputs/SelectInput/SelectInput.types.ts +0 -113
- package/src/inputs/SelectInput/SelectInput.utils.ts +0 -206
- package/src/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx +0 -44
- package/src/inputs/SelectInput/TriggerButton/index.ts +0 -5
- package/src/inputs/SelectInput/components.ts +0 -10
- package/src/inputs/SelectInput/index.ts +0 -14
- package/build/inputs/{SelectInput/SelectInput.messages.js → SelectInput.messages.js} +0 -0
- package/build/inputs/{SelectInput/SelectInput.messages.mjs → SelectInput.messages.mjs} +0 -0
- package/{src/inputs/SelectInput → build/styles/inputs}/SelectInput.css +90 -90
- package/build/types/inputs/{SelectInput/SelectInput.messages.d.ts → SelectInput.messages.d.ts} +0 -0
- package/{build/styles/inputs/SelectInput → src/inputs}/SelectInput.css +90 -90
- /package/src/inputs/{SelectInput/SelectInput.messages.ts → SelectInput.messages.ts} +0 -0
- /package/src/inputs/{SelectInput/BottomSheet/SelectInputBottomSheet.less → _BottomSheet.less} +0 -0
- /package/src/inputs/{SelectInput/ButtonInput/SelectInputButtonInput.less → _ButtonInput.less} +0 -0
- /package/src/inputs/{SelectInput/Popover/SelectInputPopover.less → _Popover.less} +0 -0
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
import { CrossCircle } from '@transferwise/icons';
|
|
2
|
-
import { ListboxOptions } from '@headlessui/react';
|
|
3
|
-
import { clsx } from 'clsx';
|
|
4
|
-
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
5
|
-
import { useIntl } from 'react-intl';
|
|
6
|
-
import { Virtualizer, type VirtualizerHandle } from 'virtua';
|
|
7
|
-
|
|
8
|
-
import { SearchInput } from '../../SearchInput';
|
|
9
|
-
import {
|
|
10
|
-
SelectInputItemsCountContext,
|
|
11
|
-
SelectInputItemPositionContext,
|
|
12
|
-
} from '../SelectInput.contexts';
|
|
13
|
-
import {
|
|
14
|
-
dedupeSelectInputItems,
|
|
15
|
-
filterSelectInputItems,
|
|
16
|
-
MAX_ITEMS_WITHOUT_VIRTUALIZATION,
|
|
17
|
-
searchableString,
|
|
18
|
-
selectInputOptionItemIncludesNeedle,
|
|
19
|
-
sortSelectInputItems,
|
|
20
|
-
} from '../SelectInput.utils';
|
|
21
|
-
import { SelectInputOptionItem, SelectInputProps, SelectInputItem } from '../SelectInput.types';
|
|
22
|
-
import messages from '../SelectInput.messages';
|
|
23
|
-
|
|
24
|
-
import { SelectInputItemView } from '../ItemView';
|
|
25
|
-
import { SelectInputOptionsContainer } from './OptionsContainer';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Props for the SelectInputOptions component.
|
|
29
|
-
*/
|
|
30
|
-
export interface SelectInputOptionsProps<T = string> extends Pick<
|
|
31
|
-
SelectInputProps<T>,
|
|
32
|
-
| 'items'
|
|
33
|
-
| 'renderValue'
|
|
34
|
-
| 'renderFooter'
|
|
35
|
-
| 'filterable'
|
|
36
|
-
| 'filterPlaceholder'
|
|
37
|
-
| 'id'
|
|
38
|
-
| 'parentId'
|
|
39
|
-
| 'compareValues'
|
|
40
|
-
| 'sortFilteredOptions'
|
|
41
|
-
> {
|
|
42
|
-
searchInputRef: React.MutableRefObject<HTMLInputElement | null>;
|
|
43
|
-
listboxRef: React.MutableRefObject<HTMLDivElement | null>;
|
|
44
|
-
filterQuery: string;
|
|
45
|
-
onFilterChange: (query: string) => void;
|
|
46
|
-
listBoxLabel?: string;
|
|
47
|
-
listBoxLabelledBy?: string;
|
|
48
|
-
autocomplete?: string;
|
|
49
|
-
name?: string;
|
|
50
|
-
onAutocompleteSelect?: (value: T) => void;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* The main options container component for SelectInput.
|
|
55
|
-
* Manages filtering, virtualization, and rendering of options.
|
|
56
|
-
*/
|
|
57
|
-
export function SelectInputOptions<T = string>({
|
|
58
|
-
id,
|
|
59
|
-
parentId,
|
|
60
|
-
items,
|
|
61
|
-
compareValues: compareValuesProp,
|
|
62
|
-
renderValue = String,
|
|
63
|
-
renderFooter,
|
|
64
|
-
filterable = false,
|
|
65
|
-
filterPlaceholder,
|
|
66
|
-
sortFilteredOptions,
|
|
67
|
-
searchInputRef,
|
|
68
|
-
listboxRef,
|
|
69
|
-
filterQuery,
|
|
70
|
-
onFilterChange,
|
|
71
|
-
listBoxLabel,
|
|
72
|
-
listBoxLabelledBy,
|
|
73
|
-
autocomplete,
|
|
74
|
-
name,
|
|
75
|
-
onAutocompleteSelect,
|
|
76
|
-
}: SelectInputOptionsProps<T>) {
|
|
77
|
-
const intl = useIntl();
|
|
78
|
-
const virtualiserHandlerRef = useRef<VirtualizerHandle>(null);
|
|
79
|
-
const controllerRef = filterable ? searchInputRef : listboxRef;
|
|
80
|
-
const [initialRender, setInitialRender] = useState(true);
|
|
81
|
-
|
|
82
|
-
const needle = useMemo(() => {
|
|
83
|
-
if (filterable) {
|
|
84
|
-
return filterQuery ? searchableString(filterQuery) : null;
|
|
85
|
-
}
|
|
86
|
-
return undefined;
|
|
87
|
-
}, [filterQuery, filterable]);
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
if (needle) {
|
|
90
|
-
// Ensure having an active option while filtering.
|
|
91
|
-
// Without `requestAnimationFrame` upon which React depends for scheduling
|
|
92
|
-
// updates, the active status would only show for a split second and then
|
|
93
|
-
// disappear inadvertently.
|
|
94
|
-
requestAnimationFrame(() => {
|
|
95
|
-
if (
|
|
96
|
-
controllerRef.current != null &&
|
|
97
|
-
!controllerRef.current.hasAttribute('aria-activedescendant')
|
|
98
|
-
) {
|
|
99
|
-
// Activate first option via synthetic key press
|
|
100
|
-
controllerRef.current.dispatchEvent(
|
|
101
|
-
new KeyboardEvent('keydown', { key: 'Home', bubbles: true }),
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}, [controllerRef, needle]);
|
|
107
|
-
|
|
108
|
-
const compareValues = useMemo(() => {
|
|
109
|
-
if (!compareValuesProp) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (typeof compareValuesProp === 'function') {
|
|
114
|
-
return (a: NonNullable<T>, b: NonNullable<T>) => compareValuesProp(a, b);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const key = compareValuesProp;
|
|
118
|
-
return (a: NonNullable<T>, b: NonNullable<T>) => {
|
|
119
|
-
if (typeof a === 'object' && a != null && typeof b === 'object' && b != null) {
|
|
120
|
-
return (a as Record<string, unknown>)[key] === (b as Record<string, unknown>)[key];
|
|
121
|
-
}
|
|
122
|
-
return a === b;
|
|
123
|
-
};
|
|
124
|
-
}, [compareValuesProp]);
|
|
125
|
-
|
|
126
|
-
const filteredItems: readonly SelectInputItem<NonNullable<T> | undefined>[] = useMemo(() => {
|
|
127
|
-
if (needle == null) {
|
|
128
|
-
return items;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const dedupedItems = dedupeSelectInputItems(items, compareValues);
|
|
132
|
-
|
|
133
|
-
if (sortFilteredOptions) {
|
|
134
|
-
// When sorting, filter out non-matching items completely to avoid ghost items
|
|
135
|
-
const filtered = dedupedItems.map((item) => {
|
|
136
|
-
if (item.type === 'option') {
|
|
137
|
-
return selectInputOptionItemIncludesNeedle(item, needle)
|
|
138
|
-
? item
|
|
139
|
-
: { ...item, value: undefined };
|
|
140
|
-
}
|
|
141
|
-
if (item.type === 'group') {
|
|
142
|
-
return {
|
|
143
|
-
...item,
|
|
144
|
-
options: item.options.map((option) =>
|
|
145
|
-
selectInputOptionItemIncludesNeedle(option, needle)
|
|
146
|
-
? option
|
|
147
|
-
: { ...option, value: undefined },
|
|
148
|
-
),
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
return item;
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
return sortSelectInputItems(filtered, sortFilteredOptions, filterQuery);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return filterSelectInputItems(dedupedItems, (item) =>
|
|
158
|
-
selectInputOptionItemIncludesNeedle(item, needle),
|
|
159
|
-
);
|
|
160
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
161
|
-
}, [needle, items, compareValues]);
|
|
162
|
-
const resultsEmpty = needle != null && filteredItems.length === 0;
|
|
163
|
-
|
|
164
|
-
const virtualized = filteredItems.length > MAX_ITEMS_WITHOUT_VIRTUALIZATION;
|
|
165
|
-
|
|
166
|
-
// Items shown once shall be kept mounted until the needle changes, otherwise
|
|
167
|
-
// the scroll position may jump around inadvertently. Pattern adopted from:
|
|
168
|
-
// https://inokawa.github.io/virtua/?path=/story/advanced-keep-offscreen-items--append-only
|
|
169
|
-
const [mountedIndexes, setMountedIndexes] = useState<number[]>([]);
|
|
170
|
-
const prevNeedleRef = useRef(needle);
|
|
171
|
-
|
|
172
|
-
useEffect(() => {
|
|
173
|
-
const needleChanged = prevNeedleRef.current !== needle;
|
|
174
|
-
prevNeedleRef.current = needle;
|
|
175
|
-
|
|
176
|
-
if (needleChanged) {
|
|
177
|
-
// Reset mounted indexes when search changes to avoid stale scroll positions
|
|
178
|
-
setMountedIndexes([]);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Ensure the 'End' key works as intended by keeping the last item mounted.
|
|
183
|
-
// Skipped on needle change to prevent auto-scrolling on search.
|
|
184
|
-
if (filteredItems.length > 0) {
|
|
185
|
-
setMountedIndexes((prevMountedIndexes) => {
|
|
186
|
-
// Create a new array with existing indexes plus the last item index
|
|
187
|
-
return [...new Set([...prevMountedIndexes, filteredItems.length - 1])]; // Sorting is redundant by nature here
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}, [needle, filteredItems.length]);
|
|
191
|
-
|
|
192
|
-
const listboxContainerRef = useRef<HTMLDivElement>(null);
|
|
193
|
-
useEffect(() => {
|
|
194
|
-
if (listboxContainerRef.current != null) {
|
|
195
|
-
listboxContainerRef.current.style.setProperty(
|
|
196
|
-
'--initial-height',
|
|
197
|
-
`${listboxContainerRef.current.offsetHeight}px`,
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
}, []);
|
|
201
|
-
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
setInitialRender(false);
|
|
204
|
-
}, []);
|
|
205
|
-
|
|
206
|
-
const showStatus = resultsEmpty;
|
|
207
|
-
const statusId = useId();
|
|
208
|
-
const listboxId = useId();
|
|
209
|
-
|
|
210
|
-
const getItemNode = (index: number) => {
|
|
211
|
-
|
|
212
|
-
const item = filteredItems[index];
|
|
213
|
-
return (
|
|
214
|
-
<SelectInputItemView
|
|
215
|
-
key={index}
|
|
216
|
-
|
|
217
|
-
item={item}
|
|
218
|
-
renderValue={renderValue}
|
|
219
|
-
needle={needle}
|
|
220
|
-
/>
|
|
221
|
-
);
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
const findMatchingItem = (autocompleteValue: string): T | null => {
|
|
225
|
-
const flatOptions = items
|
|
226
|
-
.flatMap((item) =>
|
|
227
|
-
item.type === 'group' ? item.options : item.type === 'option' ? [item] : [],
|
|
228
|
-
)
|
|
229
|
-
.filter(
|
|
230
|
-
(item): item is SelectInputOptionItem<NonNullable<T>> =>
|
|
231
|
-
item.type === 'option' && item.value != null,
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
const exactMatch = flatOptions.find(
|
|
235
|
-
(option) =>
|
|
236
|
-
String(option.value) === autocompleteValue ||
|
|
237
|
-
option.filterMatchers?.some((matcher) => matcher === autocompleteValue),
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
if (exactMatch) {
|
|
241
|
-
return exactMatch.value;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const fuzzyMatch = flatOptions.find((option) =>
|
|
245
|
-
option.filterMatchers?.some((matcher) =>
|
|
246
|
-
matcher.toLowerCase().includes(autocompleteValue.toLowerCase()),
|
|
247
|
-
),
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
return fuzzyMatch ? fuzzyMatch.value : null;
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
return (
|
|
254
|
-
<ListboxOptions
|
|
255
|
-
modal
|
|
256
|
-
as={SelectInputOptionsContainer}
|
|
257
|
-
static
|
|
258
|
-
className="np-select-input-options-container"
|
|
259
|
-
onAriaActiveDescendantChange={(value: React.AriaAttributes['aria-activedescendant']) => {
|
|
260
|
-
if (controllerRef.current != null) {
|
|
261
|
-
if (!initialRender && value != null) {
|
|
262
|
-
controllerRef.current.setAttribute('aria-activedescendant', value);
|
|
263
|
-
} else {
|
|
264
|
-
controllerRef.current.removeAttribute('aria-activedescendant');
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}}
|
|
268
|
-
>
|
|
269
|
-
{filterable ? (
|
|
270
|
-
<div className="np-select-input-query-container">
|
|
271
|
-
<SearchInput
|
|
272
|
-
ref={searchInputRef}
|
|
273
|
-
id={id}
|
|
274
|
-
name={name}
|
|
275
|
-
autoComplete={autocomplete}
|
|
276
|
-
role="combobox"
|
|
277
|
-
shape="rectangle"
|
|
278
|
-
placeholder={filterPlaceholder}
|
|
279
|
-
aria-label={filterPlaceholder}
|
|
280
|
-
defaultValue={filterQuery}
|
|
281
|
-
aria-autocomplete="list"
|
|
282
|
-
aria-expanded
|
|
283
|
-
aria-controls={listboxId}
|
|
284
|
-
aria-describedby={showStatus ? statusId : undefined}
|
|
285
|
-
onKeyDown={(event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
286
|
-
// Prevent interfering with the matcher of Headless UI
|
|
287
|
-
// https://mathiasbynens.be/notes/javascript-unicode#regex
|
|
288
|
-
if (/^.$/u.test(event.key)) {
|
|
289
|
-
event.stopPropagation();
|
|
290
|
-
}
|
|
291
|
-
}}
|
|
292
|
-
onChange={(event) => {
|
|
293
|
-
// Free up resources and ensure not to go out of bounds when the
|
|
294
|
-
// resulting item count is less than before
|
|
295
|
-
const inputValue = event.currentTarget.value;
|
|
296
|
-
|
|
297
|
-
// Free up resources and ensure not to go out of bounds
|
|
298
|
-
setMountedIndexes([]);
|
|
299
|
-
onFilterChange(inputValue);
|
|
300
|
-
}}
|
|
301
|
-
onInput={(event) => {
|
|
302
|
-
const inputValue = event.currentTarget.value;
|
|
303
|
-
const inputElement = event.currentTarget;
|
|
304
|
-
|
|
305
|
-
if (autocomplete && onAutocompleteSelect && inputValue) {
|
|
306
|
-
setTimeout(() => {
|
|
307
|
-
if (inputElement.value === inputValue && inputValue.length > 2) {
|
|
308
|
-
const matchedValue = findMatchingItem(inputValue);
|
|
309
|
-
if (matchedValue !== null) {
|
|
310
|
-
onAutocompleteSelect(matchedValue);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}, 50);
|
|
314
|
-
}
|
|
315
|
-
}}
|
|
316
|
-
/>
|
|
317
|
-
</div>
|
|
318
|
-
) : null}
|
|
319
|
-
|
|
320
|
-
<section
|
|
321
|
-
ref={listboxContainerRef}
|
|
322
|
-
tabIndex={-1}
|
|
323
|
-
className={clsx(
|
|
324
|
-
'np-select-input-listbox-container',
|
|
325
|
-
virtualized && 'np-select-input-listbox-container--virtualized',
|
|
326
|
-
needle == null && // Groups aren't shown when filtering
|
|
327
|
-
items.some((item) => item.type === 'group') &&
|
|
328
|
-
'np-select-input-listbox-container--has-group',
|
|
329
|
-
)}
|
|
330
|
-
data-wds-parent={parentId ?? undefined}
|
|
331
|
-
>
|
|
332
|
-
{resultsEmpty ? (
|
|
333
|
-
<div id={statusId} className="np-select-input-options-status">
|
|
334
|
-
<CrossCircle size={16} className="np-select-input-options-status-icon" />
|
|
335
|
-
{intl.formatMessage(messages.noResultsFound)}
|
|
336
|
-
</div>
|
|
337
|
-
) : null}
|
|
338
|
-
|
|
339
|
-
<div
|
|
340
|
-
ref={listboxRef}
|
|
341
|
-
id={listboxId}
|
|
342
|
-
role="listbox"
|
|
343
|
-
aria-orientation="vertical"
|
|
344
|
-
aria-label={listBoxLabel}
|
|
345
|
-
aria-labelledby={listBoxLabelledBy}
|
|
346
|
-
tabIndex={0}
|
|
347
|
-
className="np-select-input-listbox"
|
|
348
|
-
>
|
|
349
|
-
{!virtualized ? (
|
|
350
|
-
filteredItems.map((_, index) => getItemNode(index))
|
|
351
|
-
) : (
|
|
352
|
-
<Virtualizer
|
|
353
|
-
ref={virtualiserHandlerRef}
|
|
354
|
-
data={filteredItems}
|
|
355
|
-
keepMounted={mountedIndexes}
|
|
356
|
-
scrollRef={listboxRef} // `VList` doesn't expose this
|
|
357
|
-
onScroll={async () => {
|
|
358
|
-
if (!virtualiserHandlerRef.current) return;
|
|
359
|
-
|
|
360
|
-
const startIndex = virtualiserHandlerRef.current.findItemIndex(
|
|
361
|
-
virtualiserHandlerRef.current.scrollOffset,
|
|
362
|
-
);
|
|
363
|
-
const endIndex = virtualiserHandlerRef.current.findItemIndex(
|
|
364
|
-
virtualiserHandlerRef.current.scrollOffset +
|
|
365
|
-
virtualiserHandlerRef.current.viewportSize,
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
setMountedIndexes((prevMountedIndexes) => {
|
|
369
|
-
// Create an array of all indexes that should be visible
|
|
370
|
-
|
|
371
|
-
const visibleIndexes = [];
|
|
372
|
-
for (let index = startIndex; index <= endIndex; index += 1) {
|
|
373
|
-
// eslint-disable-next-line functional/immutable-data
|
|
374
|
-
visibleIndexes.push(index);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// Combine with previous indexes and sort
|
|
378
|
-
return [...new Set([...prevMountedIndexes, ...visibleIndexes])].sort(
|
|
379
|
-
(a, b) => a - b,
|
|
380
|
-
);
|
|
381
|
-
});
|
|
382
|
-
}}
|
|
383
|
-
>
|
|
384
|
-
{(item, index) => (
|
|
385
|
-
// The position of each item can't be inferred by browsers when
|
|
386
|
-
// virtualizing, as some of the items may not be in the DOM
|
|
387
|
-
<SelectInputItemsCountContext.Provider value={filteredItems.length}>
|
|
388
|
-
<SelectInputItemPositionContext.Provider value={index + 1}>
|
|
389
|
-
{getItemNode(index)}
|
|
390
|
-
</SelectInputItemPositionContext.Provider>
|
|
391
|
-
</SelectInputItemsCountContext.Provider>
|
|
392
|
-
)}
|
|
393
|
-
</Virtualizer>
|
|
394
|
-
)}
|
|
395
|
-
</div>
|
|
396
|
-
|
|
397
|
-
{renderFooter != null ? (
|
|
398
|
-
<footer className="np-select-input-footer">
|
|
399
|
-
<div
|
|
400
|
-
role="none"
|
|
401
|
-
onKeyDown={(event) => {
|
|
402
|
-
// Prevent interfering with Headless UI
|
|
403
|
-
if (event.key !== 'Escape') {
|
|
404
|
-
event.stopPropagation();
|
|
405
|
-
}
|
|
406
|
-
}}
|
|
407
|
-
>
|
|
408
|
-
{renderFooter({
|
|
409
|
-
resultsEmpty,
|
|
410
|
-
queryNormalized: needle,
|
|
411
|
-
})}
|
|
412
|
-
</div>
|
|
413
|
-
</footer>
|
|
414
|
-
) : null}
|
|
415
|
-
</section>
|
|
416
|
-
</ListboxOptions>
|
|
417
|
-
);
|
|
418
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
.np-popover-v2-container {
|
|
2
|
-
z-index: 1060;
|
|
3
|
-
display: flex;
|
|
4
|
-
max-height: var(--max-height);
|
|
5
|
-
width: var(--width);
|
|
6
|
-
flex-direction: column;
|
|
7
|
-
overflow: hidden;
|
|
8
|
-
border-radius: 10px;
|
|
9
|
-
border-radius: var(--radius-small);
|
|
10
|
-
background-color: #ffffff;
|
|
11
|
-
background-color: var(--color-background-elevated);
|
|
12
|
-
box-shadow: 0 0 40px rgba(69, 71, 69, 0.2);
|
|
13
|
-
}
|
|
14
|
-
.np-popover-v2-container--size-md {
|
|
15
|
-
min-width: 20rem;
|
|
16
|
-
}
|
|
17
|
-
.np-popover-v2-container--size-lg {
|
|
18
|
-
min-width: 24rem;
|
|
19
|
-
}
|
|
20
|
-
.np-popover-v2-container:focus {
|
|
21
|
-
outline: none;
|
|
22
|
-
}
|
|
23
|
-
.np-popover-v2 {
|
|
24
|
-
display: grid;
|
|
25
|
-
grid-row-gap: 8px;
|
|
26
|
-
grid-row-gap: var(--size-8);
|
|
27
|
-
row-gap: 8px;
|
|
28
|
-
row-gap: var(--size-8);
|
|
29
|
-
overflow-y: auto;
|
|
30
|
-
grid-template-rows: minmax(0, 1fr);
|
|
31
|
-
}
|
|
32
|
-
.np-popover-v2--has-title {
|
|
33
|
-
grid-template-rows: auto minmax(0, 1fr);
|
|
34
|
-
}
|
|
35
|
-
.np-popover-v2--padding-md {
|
|
36
|
-
padding: 16px;
|
|
37
|
-
padding: var(--size-16);
|
|
38
|
-
}
|
|
39
|
-
.np-popover-v2-title {
|
|
40
|
-
color: #37517e;
|
|
41
|
-
color: var(--color-content-primary);
|
|
42
|
-
}
|
|
43
|
-
.np-popover-v2-content {
|
|
44
|
-
color: #5d7079;
|
|
45
|
-
color: var(--color-content-secondary);
|
|
46
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import React, { createContext } from 'react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Context for passing props to the SelectInputTriggerButton component.
|
|
5
|
-
*/
|
|
6
|
-
export interface SelectInputTriggerButtonPropsContextValue {
|
|
7
|
-
ref?: React.ForwardedRef<HTMLButtonElement | null>;
|
|
8
|
-
id?: string;
|
|
9
|
-
onClick?: (event: React.MouseEvent) => void;
|
|
10
|
-
onKeyDown?: (event: React.KeyboardEvent) => void;
|
|
11
|
-
size?: 'sm' | 'md' | 'lg';
|
|
12
|
-
[key: string]: unknown;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Context for passing props to the SelectInputTriggerButton component.
|
|
17
|
-
*/
|
|
18
|
-
export const SelectInputTriggerButtonPropsContext =
|
|
19
|
-
createContext<SelectInputTriggerButtonPropsContextValue>({});
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Context for providing the total count of items in a SelectInput.
|
|
23
|
-
* Used for ARIA accessibility to inform screen readers about the total number of options.
|
|
24
|
-
*/
|
|
25
|
-
export const SelectInputItemsCountContext = createContext<number | undefined>(undefined);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Context for providing the current item position in a SelectInput.
|
|
29
|
-
* Used for ARIA accessibility to inform screen readers about the position of the option.
|
|
30
|
-
*/
|
|
31
|
-
export const SelectInputItemPositionContext = createContext<number | undefined>(undefined);
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Context indicating whether an option's content is rendered within the trigger button.
|
|
35
|
-
* When true, certain styling adjustments are applied to make the content fit better in the trigger.
|
|
36
|
-
*/
|
|
37
|
-
export const SelectInputOptionContentWithinTriggerContext = createContext(false);
|
|
38
|
-
|
|
39
|
-
// Re-export types from the original contexts module for backward compatibility
|
|
40
|
-
export type { WithInputAttributesProps } from '../contexts';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
@import (reference) "../../../node_modules/@transferwise/neptune-css/src/less/ring.less";
|
|
2
|
-
|
|
3
|
-
// Import component styles
|
|
4
|
-
@import "./BottomSheet/SelectInputBottomSheet.less";
|
|
5
|
-
@import "./ButtonInput/SelectInputButtonInput.less";
|
|
6
|
-
@import "./Popover/SelectInputPopover.less";
|
|
7
|
-
@import "./Option/SelectInputOption.less";
|
|
8
|
-
@import "./OptionContent/SelectInputOptionContent.less";
|
|
9
|
-
@import "./ItemView/SelectInputItemView.less";
|
|
10
|
-
@import "./Options/SelectInputOptions.less";
|
|
11
|
-
@import "./ClearButton/SelectInputClearButton.less";
|
|
12
|
-
|
|
13
|
-
// Main SelectInput styles
|
|
14
|
-
.np-select-input-content {
|
|
15
|
-
overflow: hidden;
|
|
16
|
-
text-overflow: ellipsis;
|
|
17
|
-
white-space: nowrap;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.np-select-input-placeholder {
|
|
21
|
-
color: var(--color-content-tertiary);
|
|
22
|
-
}
|