@transferwise/components 46.130.2 → 46.130.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/build/dateInput/DateInput.js +12 -5
  2. package/build/dateInput/DateInput.js.map +1 -1
  3. package/build/dateInput/DateInput.mjs +11 -4
  4. package/build/dateInput/DateInput.mjs.map +1 -1
  5. package/build/expressiveMoneyInput/currencySelector/CurrencySelector.js +16 -8
  6. package/build/expressiveMoneyInput/currencySelector/CurrencySelector.js.map +1 -1
  7. package/build/expressiveMoneyInput/currencySelector/CurrencySelector.mjs +14 -6
  8. package/build/expressiveMoneyInput/currencySelector/CurrencySelector.mjs.map +1 -1
  9. package/build/index.js +12 -7
  10. package/build/index.js.map +1 -1
  11. package/build/index.mjs +9 -3
  12. package/build/index.mjs.map +1 -1
  13. package/build/inputs/{_BottomSheet.js → SelectInput/BottomSheet/SelectInputBottomSheet.js} +7 -7
  14. package/build/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.js.map +1 -0
  15. package/build/inputs/{_BottomSheet.mjs → SelectInput/BottomSheet/SelectInputBottomSheet.mjs} +7 -7
  16. package/build/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.mjs.map +1 -0
  17. package/build/inputs/{_ButtonInput.js → SelectInput/ButtonInput/SelectInputButtonInput.js} +5 -5
  18. package/build/inputs/SelectInput/ButtonInput/SelectInputButtonInput.js.map +1 -0
  19. package/build/inputs/{_ButtonInput.mjs → SelectInput/ButtonInput/SelectInputButtonInput.mjs} +5 -5
  20. package/build/inputs/SelectInput/ButtonInput/SelectInputButtonInput.mjs.map +1 -0
  21. package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.js +26 -0
  22. package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.js.map +1 -0
  23. package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.mjs +24 -0
  24. package/build/inputs/SelectInput/ClearButton/SelectInputClearButton.mjs.map +1 -0
  25. package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.js +59 -0
  26. package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.js.map +1 -0
  27. package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.mjs +56 -0
  28. package/build/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.mjs.map +1 -0
  29. package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.js +50 -0
  30. package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.js.map +1 -0
  31. package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.mjs +48 -0
  32. package/build/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.mjs.map +1 -0
  33. package/build/inputs/SelectInput/ItemView/SelectInputItemView.js +47 -0
  34. package/build/inputs/SelectInput/ItemView/SelectInputItemView.js.map +1 -0
  35. package/build/inputs/SelectInput/ItemView/SelectInputItemView.mjs +45 -0
  36. package/build/inputs/SelectInput/ItemView/SelectInputItemView.mjs.map +1 -0
  37. package/build/inputs/SelectInput/Option/SelectInputOption.js +42 -0
  38. package/build/inputs/SelectInput/Option/SelectInputOption.js.map +1 -0
  39. package/build/inputs/SelectInput/Option/SelectInputOption.mjs +40 -0
  40. package/build/inputs/SelectInput/Option/SelectInputOption.mjs.map +1 -0
  41. package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.js +40 -0
  42. package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.js.map +1 -0
  43. package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.mjs +38 -0
  44. package/build/inputs/SelectInput/OptionContent/SelectInputOptionContent.mjs.map +1 -0
  45. package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.js +48 -0
  46. package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.js.map +1 -0
  47. package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.mjs +46 -0
  48. package/build/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.mjs.map +1 -0
  49. package/build/inputs/SelectInput/Options/SelectInputOptions.js +300 -0
  50. package/build/inputs/SelectInput/Options/SelectInputOptions.js.map +1 -0
  51. package/build/inputs/SelectInput/Options/SelectInputOptions.mjs +298 -0
  52. package/build/inputs/SelectInput/Options/SelectInputOptions.mjs.map +1 -0
  53. package/build/inputs/{_Popover.js → SelectInput/Popover/SelectInputPopover.js} +7 -7
  54. package/build/inputs/SelectInput/Popover/SelectInputPopover.js.map +1 -0
  55. package/build/inputs/{_Popover.mjs → SelectInput/Popover/SelectInputPopover.mjs} +7 -7
  56. package/build/inputs/SelectInput/Popover/SelectInputPopover.mjs.map +1 -0
  57. package/build/inputs/SelectInput/SelectInput.contexts.js +29 -0
  58. package/build/inputs/SelectInput/SelectInput.contexts.js.map +1 -0
  59. package/build/inputs/SelectInput/SelectInput.contexts.mjs +24 -0
  60. package/build/inputs/SelectInput/SelectInput.contexts.mjs.map +1 -0
  61. package/build/inputs/SelectInput/SelectInput.js +222 -0
  62. package/build/inputs/SelectInput/SelectInput.js.map +1 -0
  63. package/build/inputs/SelectInput/SelectInput.messages.js.map +1 -0
  64. package/build/inputs/SelectInput/SelectInput.messages.mjs.map +1 -0
  65. package/build/inputs/SelectInput/SelectInput.mjs +216 -0
  66. package/build/inputs/SelectInput/SelectInput.mjs.map +1 -0
  67. package/build/inputs/SelectInput/SelectInput.utils.js +164 -0
  68. package/build/inputs/SelectInput/SelectInput.utils.js.map +1 -0
  69. package/build/inputs/SelectInput/SelectInput.utils.mjs +154 -0
  70. package/build/inputs/SelectInput/SelectInput.utils.mjs.map +1 -0
  71. package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js +42 -0
  72. package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js.map +1 -0
  73. package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs +36 -0
  74. package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs.map +1 -0
  75. package/build/main.css +90 -90
  76. package/build/moneyInput/MoneyInput.js +9 -2
  77. package/build/moneyInput/MoneyInput.js.map +1 -1
  78. package/build/moneyInput/MoneyInput.mjs +8 -1
  79. package/build/moneyInput/MoneyInput.mjs.map +1 -1
  80. package/build/phoneNumberInput/PhoneNumberInput.js +10 -3
  81. package/build/phoneNumberInput/PhoneNumberInput.js.map +1 -1
  82. package/build/phoneNumberInput/PhoneNumberInput.mjs +9 -2
  83. package/build/phoneNumberInput/PhoneNumberInput.mjs.map +1 -1
  84. package/build/styles/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.css +96 -0
  85. package/build/styles/inputs/SelectInput/ButtonInput/SelectInputButtonInput.css +16 -0
  86. package/build/styles/inputs/SelectInput/ClearButton/SelectInputClearButton.css +46 -0
  87. package/build/styles/inputs/SelectInput/ItemView/SelectInputItemView.css +16 -0
  88. package/build/styles/inputs/SelectInput/Option/SelectInputOption.css +33 -0
  89. package/build/styles/inputs/SelectInput/OptionContent/SelectInputOptionContent.css +37 -0
  90. package/build/styles/inputs/SelectInput/Options/SelectInputOptions.css +81 -0
  91. package/build/styles/inputs/SelectInput/Popover/SelectInputPopover.css +46 -0
  92. package/build/styles/main.css +90 -90
  93. package/build/types/index.d.ts +1 -1
  94. package/build/types/index.d.ts.map +1 -1
  95. package/build/types/inputs/{_BottomSheet.d.ts → SelectInput/BottomSheet/SelectInputBottomSheet.d.ts} +3 -3
  96. package/build/types/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.d.ts.map +1 -0
  97. package/build/types/inputs/SelectInput/BottomSheet/index.d.ts +3 -0
  98. package/build/types/inputs/SelectInput/BottomSheet/index.d.ts.map +1 -0
  99. package/build/types/inputs/SelectInput/ButtonInput/SelectInputButtonInput.d.ts +5 -0
  100. package/build/types/inputs/SelectInput/ButtonInput/SelectInputButtonInput.d.ts.map +1 -0
  101. package/build/types/inputs/SelectInput/ButtonInput/index.d.ts +3 -0
  102. package/build/types/inputs/SelectInput/ButtonInput/index.d.ts.map +1 -0
  103. package/build/types/inputs/SelectInput/ClearButton/SelectInputClearButton.d.ts +7 -0
  104. package/build/types/inputs/SelectInput/ClearButton/SelectInputClearButton.d.ts.map +1 -0
  105. package/build/types/inputs/SelectInput/ClearButton/index.d.ts +3 -0
  106. package/build/types/inputs/SelectInput/ClearButton/index.d.ts.map +1 -0
  107. package/build/types/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.d.ts +16 -0
  108. package/build/types/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.d.ts.map +1 -0
  109. package/build/types/inputs/SelectInput/DefaultRenderTrigger/index.d.ts +2 -0
  110. package/build/types/inputs/SelectInput/DefaultRenderTrigger/index.d.ts.map +1 -0
  111. package/build/types/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.d.ts +9 -0
  112. package/build/types/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.d.ts.map +1 -0
  113. package/build/types/inputs/SelectInput/ItemView/GroupItemView/index.d.ts +3 -0
  114. package/build/types/inputs/SelectInput/ItemView/GroupItemView/index.d.ts.map +1 -0
  115. package/build/types/inputs/SelectInput/ItemView/SelectInputItemView.d.ts +11 -0
  116. package/build/types/inputs/SelectInput/ItemView/SelectInputItemView.d.ts.map +1 -0
  117. package/build/types/inputs/SelectInput/ItemView/index.d.ts +4 -0
  118. package/build/types/inputs/SelectInput/ItemView/index.d.ts.map +1 -0
  119. package/build/types/inputs/SelectInput/Option/SelectInputOption.d.ts +11 -0
  120. package/build/types/inputs/SelectInput/Option/SelectInputOption.d.ts.map +1 -0
  121. package/build/types/inputs/SelectInput/Option/index.d.ts +3 -0
  122. package/build/types/inputs/SelectInput/Option/index.d.ts.map +1 -0
  123. package/build/types/inputs/SelectInput/OptionContent/SelectInputOptionContent.d.ts +13 -0
  124. package/build/types/inputs/SelectInput/OptionContent/SelectInputOptionContent.d.ts.map +1 -0
  125. package/build/types/inputs/SelectInput/OptionContent/index.d.ts +3 -0
  126. package/build/types/inputs/SelectInput/OptionContent/index.d.ts.map +1 -0
  127. package/build/types/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.d.ts +9 -0
  128. package/build/types/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.d.ts.map +1 -0
  129. package/build/types/inputs/SelectInput/Options/OptionsContainer/index.d.ts +3 -0
  130. package/build/types/inputs/SelectInput/Options/OptionsContainer/index.d.ts.map +1 -0
  131. package/build/types/inputs/SelectInput/Options/SelectInputOptions.d.ts +21 -0
  132. package/build/types/inputs/SelectInput/Options/SelectInputOptions.d.ts.map +1 -0
  133. package/build/types/inputs/SelectInput/Options/index.d.ts +4 -0
  134. package/build/types/inputs/SelectInput/Options/index.d.ts.map +1 -0
  135. package/build/types/inputs/{_Popover.d.ts → SelectInput/Popover/SelectInputPopover.d.ts} +3 -3
  136. package/build/types/inputs/SelectInput/Popover/SelectInputPopover.d.ts.map +1 -0
  137. package/build/types/inputs/SelectInput/Popover/index.d.ts +3 -0
  138. package/build/types/inputs/SelectInput/Popover/index.d.ts.map +1 -0
  139. package/build/types/inputs/SelectInput/SelectInput.contexts.d.ts +33 -0
  140. package/build/types/inputs/SelectInput/SelectInput.contexts.d.ts.map +1 -0
  141. package/build/types/inputs/SelectInput/SelectInput.d.ts +10 -0
  142. package/build/types/inputs/SelectInput/SelectInput.d.ts.map +1 -0
  143. package/build/types/inputs/SelectInput/SelectInput.messages.d.ts.map +1 -0
  144. package/build/types/inputs/{SelectInput.d.ts → SelectInput/SelectInput.types.d.ts} +12 -38
  145. package/build/types/inputs/SelectInput/SelectInput.types.d.ts.map +1 -0
  146. package/build/types/inputs/SelectInput/SelectInput.utils.d.ts +60 -0
  147. package/build/types/inputs/SelectInput/SelectInput.utils.d.ts.map +1 -0
  148. package/build/types/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts +12 -0
  149. package/build/types/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.d.ts.map +1 -0
  150. package/build/types/inputs/SelectInput/TriggerButton/index.d.ts +3 -0
  151. package/build/types/inputs/SelectInput/TriggerButton/index.d.ts.map +1 -0
  152. package/build/types/inputs/SelectInput/components.d.ts +10 -0
  153. package/build/types/inputs/SelectInput/components.d.ts.map +1 -0
  154. package/build/types/inputs/SelectInput/index.d.ts +10 -0
  155. package/build/types/inputs/SelectInput/index.d.ts.map +1 -0
  156. package/package.json +1 -1
  157. package/src/index.ts +0 -1
  158. package/src/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.css +96 -0
  159. package/src/inputs/{_BottomSheet.tsx → SelectInput/BottomSheet/SelectInputBottomSheet.tsx} +7 -7
  160. package/src/inputs/SelectInput/BottomSheet/index.ts +2 -0
  161. package/src/inputs/SelectInput/ButtonInput/SelectInputButtonInput.css +16 -0
  162. package/src/inputs/{_ButtonInput.tsx → SelectInput/ButtonInput/SelectInputButtonInput.tsx} +5 -5
  163. package/src/inputs/SelectInput/ButtonInput/index.ts +2 -0
  164. package/src/inputs/SelectInput/ClearButton/SelectInputClearButton.css +46 -0
  165. package/src/inputs/SelectInput/ClearButton/SelectInputClearButton.less +39 -0
  166. package/src/inputs/SelectInput/ClearButton/SelectInputClearButton.tsx +27 -0
  167. package/src/inputs/SelectInput/ClearButton/index.ts +2 -0
  168. package/src/inputs/SelectInput/DefaultRenderTrigger/SelectInputDefaultRenderTrigger.tsx +74 -0
  169. package/src/inputs/SelectInput/DefaultRenderTrigger/index.ts +5 -0
  170. package/src/inputs/SelectInput/ItemView/GroupItemView/SelectInputGroupItemView.tsx +61 -0
  171. package/src/inputs/SelectInput/ItemView/GroupItemView/index.ts +2 -0
  172. package/src/inputs/SelectInput/ItemView/SelectInputItemView.css +16 -0
  173. package/src/inputs/SelectInput/ItemView/SelectInputItemView.less +17 -0
  174. package/src/inputs/SelectInput/ItemView/SelectInputItemView.tsx +48 -0
  175. package/src/inputs/SelectInput/ItemView/index.ts +3 -0
  176. package/src/inputs/SelectInput/Option/SelectInputOption.css +33 -0
  177. package/src/inputs/SelectInput/Option/SelectInputOption.less +32 -0
  178. package/src/inputs/SelectInput/Option/SelectInputOption.tsx +57 -0
  179. package/src/inputs/SelectInput/Option/index.ts +2 -0
  180. package/src/inputs/SelectInput/OptionContent/SelectInputOptionContent.css +37 -0
  181. package/src/inputs/SelectInput/OptionContent/SelectInputOptionContent.less +38 -0
  182. package/src/inputs/SelectInput/OptionContent/SelectInputOptionContent.tsx +72 -0
  183. package/src/inputs/SelectInput/OptionContent/index.ts +2 -0
  184. package/src/inputs/SelectInput/Options/OptionsContainer/SelectInputOptionsContainer.tsx +59 -0
  185. package/src/inputs/SelectInput/Options/OptionsContainer/index.ts +2 -0
  186. package/src/inputs/SelectInput/Options/SelectInputOptions.css +81 -0
  187. package/src/inputs/SelectInput/Options/SelectInputOptions.less +77 -0
  188. package/src/inputs/SelectInput/Options/SelectInputOptions.tsx +411 -0
  189. package/src/inputs/SelectInput/Options/index.ts +3 -0
  190. package/src/inputs/SelectInput/Popover/SelectInputPopover.css +46 -0
  191. package/src/inputs/{_Popover.tsx → SelectInput/Popover/SelectInputPopover.tsx} +7 -7
  192. package/src/inputs/SelectInput/Popover/index.ts +2 -0
  193. package/src/inputs/SelectInput/SelectInput.contexts.tsx +40 -0
  194. package/src/inputs/SelectInput/SelectInput.less +22 -0
  195. package/src/inputs/{SelectInput.test.tsx → SelectInput/SelectInput.test.tsx} +9 -11
  196. package/src/inputs/SelectInput/SelectInput.tsx +257 -0
  197. package/src/inputs/SelectInput/SelectInput.types.ts +113 -0
  198. package/src/inputs/SelectInput/SelectInput.utils.ts +205 -0
  199. package/src/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx +36 -0
  200. package/src/inputs/SelectInput/TriggerButton/index.ts +5 -0
  201. package/src/inputs/{SelectInput.docs.mdx → SelectInput/_stories/SelectInput.docs.mdx} +0 -1
  202. package/src/inputs/{SelectInput.story.tsx → SelectInput/_stories/SelectInput.story.tsx} +11 -8
  203. package/src/inputs/{SelectInput.test.story.tsx → SelectInput/_stories/SelectInput.test.story.tsx} +6 -10
  204. package/src/inputs/SelectInput/components.ts +10 -0
  205. package/src/inputs/SelectInput/index.ts +12 -0
  206. package/src/main.css +90 -90
  207. package/src/main.less +1 -1
  208. package/build/inputs/SelectInput.js +0 -890
  209. package/build/inputs/SelectInput.js.map +0 -1
  210. package/build/inputs/SelectInput.messages.js.map +0 -1
  211. package/build/inputs/SelectInput.messages.mjs.map +0 -1
  212. package/build/inputs/SelectInput.mjs +0 -881
  213. package/build/inputs/SelectInput.mjs.map +0 -1
  214. package/build/inputs/_BottomSheet.js.map +0 -1
  215. package/build/inputs/_BottomSheet.mjs.map +0 -1
  216. package/build/inputs/_ButtonInput.js.map +0 -1
  217. package/build/inputs/_ButtonInput.mjs.map +0 -1
  218. package/build/inputs/_Popover.js.map +0 -1
  219. package/build/inputs/_Popover.mjs.map +0 -1
  220. package/build/types/inputs/SelectInput.d.ts.map +0 -1
  221. package/build/types/inputs/SelectInput.messages.d.ts.map +0 -1
  222. package/build/types/inputs/_BottomSheet.d.ts.map +0 -1
  223. package/build/types/inputs/_ButtonInput.d.ts +0 -5
  224. package/build/types/inputs/_ButtonInput.d.ts.map +0 -1
  225. package/build/types/inputs/_Popover.d.ts.map +0 -1
  226. package/src/inputs/SelectInput.less +0 -219
  227. package/src/inputs/SelectInput.tsx +0 -1269
  228. package/build/inputs/{SelectInput.messages.js → SelectInput/SelectInput.messages.js} +0 -0
  229. package/build/inputs/{SelectInput.messages.mjs → SelectInput/SelectInput.messages.mjs} +0 -0
  230. package/build/styles/inputs/{SelectInput.css → SelectInput/SelectInput.css} +90 -90
  231. package/build/types/inputs/{SelectInput.messages.d.ts → SelectInput/SelectInput.messages.d.ts} +0 -0
  232. package/src/inputs/{_BottomSheet.less → SelectInput/BottomSheet/SelectInputBottomSheet.less} +0 -0
  233. package/src/inputs/{_ButtonInput.less → SelectInput/ButtonInput/SelectInputButtonInput.less} +0 -0
  234. package/src/inputs/{_Popover.less → SelectInput/Popover/SelectInputPopover.less} +0 -0
  235. package/src/inputs/{SelectInput.css → SelectInput/SelectInput.css} +90 -90
  236. /package/src/inputs/{SelectInput.messages.ts → SelectInput/SelectInput.messages.ts} +0 -0
@@ -1,890 +0,0 @@
1
- 'use strict';
2
-
3
- var react = require('@headlessui/react');
4
- var icons = require('@transferwise/icons');
5
- var clsx = require('clsx');
6
- var mergeProps = require('merge-props');
7
- var React = require('react');
8
- var reactIntl = require('react-intl');
9
- var virtua = require('virtua');
10
- var useEffectEvent = require('../common/hooks/useEffectEvent.js');
11
- var useScreenSize = require('../common/hooks/useScreenSize.js');
12
- var PolymorphicWithOverrides = require('../common/polymorphicWithOverrides/PolymorphicWithOverrides.js');
13
- var breakpoint = require('../common/propsValues/breakpoint.js');
14
- var DateTrigger_messages = require('../dateLookup/dateTrigger/DateTrigger.messages.js');
15
- var _BottomSheet = require('./_BottomSheet.js');
16
- var _ButtonInput = require('./_ButtonInput.js');
17
- var _Popover = require('./_Popover.js');
18
- var contexts = require('./contexts.js');
19
- var InputGroup = require('./InputGroup.js');
20
- var SearchInput = require('./SearchInput.js');
21
- var SelectInput_messages = require('./SelectInput.messages.js');
22
- var Header = require('../header/Header.js');
23
- var Section = require('../section/Section.js');
24
- var jsxRuntime = require('react/jsx-runtime');
25
-
26
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
27
-
28
- var mergeProps__default = /*#__PURE__*/_interopDefault(mergeProps);
29
-
30
- const MAX_ITEMS_WITHOUT_VIRTUALIZATION = 50;
31
- function searchableString(value) {
32
- return value.trim().replace(/\s+/gu, ' ')
33
- // NFD converts an Å to A + ̊ (and other special characters)
34
- .normalize('NFD')
35
- // and then this replaces the ̊ with nothing (and other special characters)
36
- .replace(/[\u0300-\u036f]/g, '').toLowerCase();
37
- }
38
- function inferSearchableStrings(value) {
39
- if (typeof value === 'string') {
40
- return [searchableString(value)];
41
- }
42
- if (typeof value === 'object' && value != null) {
43
- return Object.values(value).filter(innerValue => typeof innerValue === 'string').map(innerValue => searchableString(innerValue));
44
- }
45
- return [];
46
- }
47
- function dedupeSelectInputOptionItem(item, existingValues, compareValues) {
48
- const isDuplicate = compareValues ? Array.from(existingValues).some(existingValue => compareValues(item.value, existingValue)) : existingValues.has(item.value);
49
- if (!isDuplicate) {
50
- existingValues.add(item.value);
51
- return item;
52
- }
53
- return {
54
- ...item,
55
- value: undefined
56
- };
57
- }
58
- /**
59
- * Sets the `value` of duplicate option items to `undefined`, hiding them when
60
- * rendered. Indexes are kept intact within groups to preserve the active item
61
- * between filter changes when possible.
62
- */
63
- function dedupeSelectInputItems(items, compareValues) {
64
- const existingValues = new Set();
65
- return items.map(item => {
66
- switch (item.type) {
67
- case 'option':
68
- {
69
- return dedupeSelectInputOptionItem(item, existingValues, compareValues);
70
- }
71
- case 'group':
72
- {
73
- return {
74
- ...item,
75
- options: item.options.map(option => dedupeSelectInputOptionItem(option, existingValues, compareValues))
76
- };
77
- }
78
- }
79
- return item;
80
- });
81
- }
82
- function selectInputOptionItemIncludesNeedle(item, needle) {
83
- return inferSearchableStrings(item.filterMatchers ?? item.value).some(haystack => haystack.includes(needle));
84
- }
85
- function filterSelectInputItems(items, predicate) {
86
- return items.filter(item => {
87
- switch (item.type) {
88
- case 'option':
89
- {
90
- return predicate(item);
91
- }
92
- case 'group':
93
- {
94
- return item.options.some(option => predicate(option));
95
- }
96
- }
97
- return false;
98
- });
99
- }
100
- /**
101
- * Flattens and sorts filtered options using the provided comparator.
102
- * Extracts all options from groups, filters out undefined values (deduplicated items),
103
- * sorts them, and returns as a flat list of option items.
104
- */
105
- function sortSelectInputItems(items, compareFn, searchQuery) {
106
- const flattenedOption = items.flatMap(item => {
107
- if (item.type === 'option') {
108
- return item.value !== undefined ? [item] : [];
109
- }
110
- if (item.type === 'group') {
111
- return item.options.filter(option => option.value !== undefined);
112
- }
113
- return [];
114
- });
115
- // eslint-disable-next-line functional/immutable-data
116
- return flattenedOption.sort((a, b) => compareFn(a, b, searchQuery));
117
- }
118
- /**
119
- * A prebuilt sort function for `sortFilteredOptions` that sorts options by relevance to the search query.
120
- * Prioritizes: exact matches > starts with > contains > alphabetical.
121
- *
122
- * @param getLabel - Function to extract the label string from the option value. Defaults to using `title` property.
123
- *
124
- * @example
125
- * ```tsx
126
- * <SelectInput
127
- * filterable
128
- * sortFilteredOptions={sortByRelevance((value) => value.name)}
129
- * // ...
130
- * />
131
- * ```
132
- */
133
- function sortByRelevance(getLabel = value => value.title) {
134
- return (a, b, searchQuery) => {
135
- const normalizedQuery = searchQuery.toLowerCase();
136
- const labelA = getLabel(a.value).toLowerCase();
137
- const labelB = getLabel(b.value).toLowerCase();
138
- // Prioritize exact matches
139
- const aExactMatch = labelA === normalizedQuery;
140
- const bExactMatch = labelB === normalizedQuery;
141
- if (aExactMatch && !bExactMatch) return -1;
142
- if (!aExactMatch && bExactMatch) return 1;
143
- // Then prioritize options where label starts with the search query
144
- const aStartsWith = labelA.startsWith(normalizedQuery);
145
- const bStartsWith = labelB.startsWith(normalizedQuery);
146
- if (aStartsWith && !bStartsWith) return -1;
147
- if (!aStartsWith && bStartsWith) return 1;
148
- // Then prioritize options where label contains the search query
149
- const aContains = labelA.includes(normalizedQuery);
150
- const bContains = labelB.includes(normalizedQuery);
151
- if (aContains && !bContains) return -1;
152
- if (!aContains && bContains) return 1;
153
- // Finally sort alphabetically
154
- return labelA.localeCompare(labelB);
155
- };
156
- }
157
- const defaultRenderTrigger = ({
158
- content,
159
- placeholderShown,
160
- clear,
161
- disabled,
162
- size,
163
- className
164
- }) => /*#__PURE__*/jsxRuntime.jsx(InputGroup.InputGroup, {
165
- addonEnd: {
166
- content: /*#__PURE__*/jsxRuntime.jsxs("span", {
167
- className: clsx.clsx('np-select-input-addon-container', disabled && 'disabled'),
168
- children: [clear != null && !placeholderShown ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
169
- children: [/*#__PURE__*/jsxRuntime.jsx(SelectInputClearButton, {
170
- onClick: event => {
171
- event.preventDefault();
172
- clear();
173
- }
174
- }), /*#__PURE__*/jsxRuntime.jsx("span", {
175
- className: "np-select-input-addon-separator"
176
- })]
177
- }) : null, /*#__PURE__*/jsxRuntime.jsx("span", {
178
- className: "np-select-input-addon",
179
- children: /*#__PURE__*/jsxRuntime.jsx(icons.ChevronDown, {
180
- size: 16
181
- })
182
- })]
183
- }),
184
- initialContentWidth: 24 + 4,
185
- padding: 'sm'
186
- },
187
- disabled: disabled,
188
- className: className,
189
- children: /*#__PURE__*/jsxRuntime.jsx(SelectInputTriggerButton, {
190
- as: _ButtonInput.ButtonInput,
191
- size: size,
192
- children: /*#__PURE__*/jsxRuntime.jsx("span", {
193
- className: clsx.clsx('np-select-input-content', placeholderShown && 'np-select-input-placeholder'),
194
- children: content
195
- })
196
- })
197
- });
198
- function SelectInputClearButton({
199
- className,
200
- onClick
201
- }) {
202
- const intl = reactIntl.useIntl();
203
- return /*#__PURE__*/jsxRuntime.jsx("button", {
204
- type: "button",
205
- "aria-label": intl.formatMessage(DateTrigger_messages.default.ariaLabel),
206
- className: clsx.clsx(className, 'np-select-input-addon np-select-input-addon--interactive'),
207
- onClick: onClick,
208
- children: /*#__PURE__*/jsxRuntime.jsx(icons.Cross, {
209
- size: 16
210
- })
211
- });
212
- }
213
- const noop = () => {};
214
- function SelectInput({
215
- id: idProp,
216
- parentId,
217
- name,
218
- multiple,
219
- placeholder,
220
- autocomplete,
221
- items,
222
- defaultValue,
223
- value: controlledValue,
224
- compareValues,
225
- renderValue = String,
226
- renderFooter,
227
- renderTrigger = defaultRenderTrigger,
228
- filterable,
229
- filterPlaceholder,
230
- sortFilteredOptions,
231
- disabled,
232
- size = 'md',
233
- className,
234
- UNSAFE_triggerButtonProps,
235
- triggerRef: externalTriggerRef,
236
- onFilterChange = noop,
237
- onChange,
238
- onOpen,
239
- onClose,
240
- onClear
241
- }) {
242
- const inputAttributes = contexts.useInputAttributes({
243
- nonLabelable: true
244
- });
245
- const id = idProp ?? inputAttributes.id;
246
- const [open, setOpen] = React.useState(false);
247
- const initialized = React.useRef(false);
248
- const handleClose = useEffectEvent.useEffectEvent(onClose ?? (() => {}));
249
- const handleOpen = useEffectEvent.useEffectEvent(onOpen ?? (() => {}));
250
- React.useEffect(() => {
251
- if (initialized.current) {
252
- if (open) {
253
- handleOpen?.();
254
- } else {
255
- handleClose?.();
256
- }
257
- } else {
258
- initialized.current = true;
259
- }
260
- }, [handleClose, handleOpen, open]);
261
- const [filterQuery, _setFilterQuery] = React.useState('');
262
- const deferredFilterQuery = React.useDeferredValue(filterQuery);
263
- const setFilterQuery = useEffectEvent.useEffectEvent(query => {
264
- _setFilterQuery(query);
265
- if (query !== filterQuery) {
266
- onFilterChange({
267
- query,
268
- queryNormalized: query ? searchableString(query) : null
269
- });
270
- }
271
- });
272
- const internalTriggerRef = React.useRef(null);
273
- const screenSm = useScreenSize.useScreenSize(breakpoint.Breakpoint.SMALL);
274
- const OptionsOverlay = screenSm ? _Popover.Popover : _BottomSheet.BottomSheet;
275
- const searchInputRef = React.useRef(null);
276
- const listboxRef = React.useRef(null);
277
- const controllerRef = filterable ? searchInputRef : listboxRef;
278
- /**
279
- * Attempts to resolve the `listbox` label
280
- * @see https://storybook.wise.design/?path=/docs/forms-selectinput-accessibility--docs#labelling
281
- */
282
- const getListBoxLabelProps = () => {
283
- if (UNSAFE_triggerButtonProps?.['aria-label']) {
284
- return {
285
- listBoxLabel: UNSAFE_triggerButtonProps['aria-label']
286
- };
287
- }
288
- if (UNSAFE_triggerButtonProps?.['aria-labelledby']) {
289
- return {
290
- listBoxLabelledBy: UNSAFE_triggerButtonProps['aria-labelledby']
291
- };
292
- }
293
- if (inputAttributes['aria-labelledby']) {
294
- return {
295
- listBoxLabelledBy: inputAttributes['aria-labelledby']
296
- };
297
- }
298
- return {};
299
- };
300
- return /*#__PURE__*/jsxRuntime.jsx(react.Listbox, {
301
- name: name,
302
- multiple: multiple,
303
- defaultValue: defaultValue,
304
- value: controlledValue,
305
- by: compareValues,
306
- disabled: disabled,
307
- onChange: value => {
308
- if (!multiple) {
309
- setOpen(false);
310
- }
311
- onChange?.(value);
312
- },
313
- children: ({
314
- disabled: uiDisabled,
315
- value
316
- }) => {
317
- const placeholderShown = multiple && Array.isArray(value) ? value.length === 0 : value == null;
318
- return /*#__PURE__*/jsxRuntime.jsx(OptionsOverlay, {
319
- placement: "bottom-start",
320
- open: open,
321
- renderTrigger: ({
322
- ref,
323
- getInteractionProps
324
- }) => /*#__PURE__*/jsxRuntime.jsx(SelectInputTriggerButtonPropsContext.Provider, {
325
- // eslint-disable-next-line react/jsx-no-constructed-context-values
326
- value: {
327
- ref: node => {
328
- ref(node);
329
- if (externalTriggerRef) {
330
- // eslint-disable-next-line no-param-reassign
331
- externalTriggerRef.current = node;
332
- } else {
333
- internalTriggerRef.current = node;
334
- }
335
- },
336
- ...inputAttributes,
337
- ...UNSAFE_triggerButtonProps,
338
- id,
339
- ...mergeProps__default.default({
340
- onClick: () => {
341
- setOpen(prev => !prev);
342
- },
343
- onKeyDown: event => {
344
- if (event.key === ' ' || event.key === 'Enter' || event.key === 'ArrowDown' || event.key === 'ArrowUp') {
345
- setOpen(prev => !prev);
346
- }
347
- }
348
- }, getInteractionProps())
349
- },
350
- children: renderTrigger({
351
- content: !placeholderShown ? /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
352
- value: true,
353
- children: multiple && Array.isArray(value) ? value.map(option => renderValue(option, true)).filter(node => node != null).join(', ') : renderValue(value, true)
354
- }) : placeholder,
355
- placeholderShown,
356
- clear: onClear != null ? () => {
357
- onClear();
358
- (externalTriggerRef?.current ?? internalTriggerRef.current)?.focus({
359
- preventScroll: true
360
- });
361
- } : undefined,
362
- disabled: uiDisabled,
363
- size,
364
- className
365
- })
366
- }),
367
- initialFocusRef: controllerRef,
368
- size: filterable ? 'lg' : 'md',
369
- padding: "none",
370
- onClose: () => {
371
- setOpen(false);
372
- },
373
- onCloseEnd: () => {
374
- setFilterQuery('');
375
- },
376
- children: /*#__PURE__*/jsxRuntime.jsx(SelectInputOptions, {
377
- id: id ? `${id}Search` : undefined,
378
- parentId: parentId,
379
- items: items,
380
- compareValues: compareValues,
381
- renderValue: renderValue,
382
- renderFooter: renderFooter,
383
- filterable: filterable,
384
- filterPlaceholder: filterPlaceholder,
385
- sortFilteredOptions: sortFilteredOptions,
386
- searchInputRef: searchInputRef,
387
- listboxRef: listboxRef,
388
- filterQuery: deferredFilterQuery,
389
- autocomplete: autocomplete,
390
- name: name,
391
- onFilterChange: setFilterQuery,
392
- onAutocompleteSelect: matchedValue => {
393
- onChange?.(matchedValue);
394
- if (!multiple) {
395
- setOpen(false);
396
- }
397
- },
398
- ...getListBoxLabelProps()
399
- })
400
- });
401
- }
402
- });
403
- }
404
- SelectInput.sortByRelevance = sortByRelevance;
405
- const SelectInputTriggerButtonPropsContext = /*#__PURE__*/React.createContext({});
406
- function SelectInputTriggerButton({
407
- as = 'button',
408
- ...restProps
409
- }) {
410
- const {
411
- ref,
412
- onClick,
413
- onKeyDown,
414
- ...interactionProps
415
- } = React.useContext(SelectInputTriggerButtonPropsContext);
416
- return /*#__PURE__*/jsxRuntime.jsx(react.ListboxButton, {
417
- ref: ref,
418
- as: PolymorphicWithOverrides.PolymorphicWithOverrides,
419
- role: "combobox",
420
- __overrides: {
421
- as,
422
- ...interactionProps
423
- },
424
- ...mergeProps__default.default({
425
- onClick,
426
- onKeyDown
427
- }, restProps)
428
- });
429
- }
430
- const SelectInputOptionsContainer = /*#__PURE__*/React.forwardRef(function SelectInputOptionsContainer({
431
- 'aria-orientation': ariaOrientation,
432
- 'aria-activedescendant': ariaActiveDescendant,
433
- role,
434
- tabIndex,
435
- onAriaActiveDescendantChange,
436
- onKeyDown,
437
- ...restProps
438
- }, ref) {
439
- const handleAriaActiveDescendantChange = useEffectEvent.useEffectEvent(onAriaActiveDescendantChange);
440
- React.useEffect(() => {
441
- handleAriaActiveDescendantChange(ariaActiveDescendant);
442
- }, [ariaActiveDescendant, handleAriaActiveDescendantChange]);
443
- return /*#__PURE__*/jsxRuntime.jsx("div", {
444
- ref: ref,
445
- role: "none",
446
- onKeyDown: event => {
447
- // Prevent confirmation close without an active item
448
- if (event.key === 'Enter' && ariaActiveDescendant == null) {
449
- return;
450
- }
451
- // Required to make ListBox focusable
452
- if (event.key === 'Tab') {
453
- return;
454
- }
455
- // Prevent absorbing Escape early
456
- if (event.key === 'Escape') {
457
- onKeyDown?.({
458
- ...event,
459
- preventDefault: () => {},
460
- stopPropagation: () => {}
461
- });
462
- return;
463
- }
464
- onKeyDown?.(event);
465
- },
466
- ...restProps
467
- });
468
- });
469
- function SelectInputOptions({
470
- id,
471
- parentId,
472
- items,
473
- compareValues: compareValuesProp,
474
- renderValue = String,
475
- renderFooter,
476
- filterable = false,
477
- filterPlaceholder,
478
- sortFilteredOptions,
479
- searchInputRef,
480
- listboxRef,
481
- filterQuery,
482
- onFilterChange,
483
- listBoxLabel,
484
- listBoxLabelledBy,
485
- autocomplete,
486
- name,
487
- onAutocompleteSelect
488
- }) {
489
- const intl = reactIntl.useIntl();
490
- const virtualiserHandlerRef = React.useRef(null);
491
- const controllerRef = filterable ? searchInputRef : listboxRef;
492
- const [initialRender, setInitialRender] = React.useState(true);
493
- const needle = React.useMemo(() => {
494
- if (filterable) {
495
- return filterQuery ? searchableString(filterQuery) : null;
496
- }
497
- return undefined;
498
- }, [filterQuery, filterable]);
499
- React.useEffect(() => {
500
- if (needle) {
501
- // Ensure having an active option while filtering.
502
- // Without `requestAnimationFrame` upon which React depends for scheduling
503
- // updates, the active status would only show for a split second and then
504
- // disappear inadvertently.
505
- requestAnimationFrame(() => {
506
- if (controllerRef.current != null && !controllerRef.current.hasAttribute('aria-activedescendant')) {
507
- // Activate first option via synthetic key press
508
- controllerRef.current.dispatchEvent(new KeyboardEvent('keydown', {
509
- key: 'Home',
510
- bubbles: true
511
- }));
512
- }
513
- });
514
- }
515
- }, [controllerRef, needle]);
516
- const compareValues = React.useMemo(() => {
517
- if (!compareValuesProp) {
518
- return undefined;
519
- }
520
- if (typeof compareValuesProp === 'function') {
521
- return (a, b) => compareValuesProp(a, b);
522
- }
523
- const key = compareValuesProp;
524
- return (a, b) => {
525
- if (typeof a === 'object' && a != null && typeof b === 'object' && b != null) {
526
- return a[key] === b[key];
527
- }
528
- return a === b;
529
- };
530
- }, [compareValuesProp]);
531
- const filteredItems = React.useMemo(() => {
532
- if (needle == null) {
533
- return items;
534
- }
535
- const dedupedItems = dedupeSelectInputItems(items, compareValues);
536
- if (sortFilteredOptions) {
537
- // When sorting, filter out non-matching items completely to avoid ghost items
538
- const filtered = dedupedItems.map(item => {
539
- if (item.type === 'option') {
540
- return selectInputOptionItemIncludesNeedle(item, needle) ? item : {
541
- ...item,
542
- value: undefined
543
- };
544
- }
545
- if (item.type === 'group') {
546
- return {
547
- ...item,
548
- options: item.options.map(option => selectInputOptionItemIncludesNeedle(option, needle) ? option : {
549
- ...option,
550
- value: undefined
551
- })
552
- };
553
- }
554
- return item;
555
- });
556
- return sortSelectInputItems(filtered, sortFilteredOptions, filterQuery);
557
- }
558
- return filterSelectInputItems(dedupedItems, item => selectInputOptionItemIncludesNeedle(item, needle));
559
- // eslint-disable-next-line react-hooks/exhaustive-deps
560
- }, [needle, items, compareValues]);
561
- const resultsEmpty = needle != null && filteredItems.length === 0;
562
- const virtualized = filteredItems.length > MAX_ITEMS_WITHOUT_VIRTUALIZATION;
563
- // Items shown once shall be kept mounted until the needle changes, otherwise
564
- // the scroll position may jump around inadvertently. Pattern adopted from:
565
- // https://inokawa.github.io/virtua/?path=/story/advanced-keep-offscreen-items--append-only
566
- const [mountedIndexes, setMountedIndexes] = React.useState([]);
567
- const prevNeedleRef = React.useRef(needle);
568
- React.useEffect(() => {
569
- const needleChanged = prevNeedleRef.current !== needle;
570
- prevNeedleRef.current = needle;
571
- if (needleChanged) {
572
- // Reset mounted indexes when search changes to avoid stale scroll positions
573
- setMountedIndexes([]);
574
- return;
575
- }
576
- // Ensure the 'End' key works as intended by keeping the last item mounted.
577
- // Skipped on needle change to prevent auto-scrolling on search.
578
- if (filteredItems.length > 0) {
579
- setMountedIndexes(prevMountedIndexes => {
580
- const indexes = new Set(prevMountedIndexes);
581
- indexes.add(filteredItems.length - 1);
582
- return [...indexes]; // Sorting is redundant by nature here
583
- });
584
- }
585
- }, [needle, filteredItems.length]);
586
- const listboxContainerRef = React.useRef(null);
587
- React.useEffect(() => {
588
- if (listboxContainerRef.current != null) {
589
- listboxContainerRef.current.style.setProperty('--initial-height', `${listboxContainerRef.current.offsetHeight}px`);
590
- }
591
- }, []);
592
- React.useEffect(() => {
593
- setInitialRender(false);
594
- }, []);
595
- const showStatus = resultsEmpty;
596
- const statusId = React.useId();
597
- const listboxId = React.useId();
598
- const getItemNode = index => {
599
- const item = filteredItems[index];
600
- return /*#__PURE__*/jsxRuntime.jsx(SelectInputItemView, {
601
- item: item,
602
- renderValue: renderValue,
603
- needle: needle
604
- }, index);
605
- };
606
- const findMatchingItem = autocompleteValue => {
607
- const flatOptions = items.flatMap(item => item.type === 'group' ? item.options : item.type === 'option' ? [item] : []).filter(item => item.type === 'option' && item.value != null);
608
- const exactMatch = flatOptions.find(option => String(option.value) === autocompleteValue || option.filterMatchers?.some(matcher => matcher === autocompleteValue));
609
- if (exactMatch) {
610
- return exactMatch.value;
611
- }
612
- const fuzzyMatch = flatOptions.find(option => option.filterMatchers?.some(matcher => matcher.toLowerCase().includes(autocompleteValue.toLowerCase())));
613
- return fuzzyMatch ? fuzzyMatch.value : null;
614
- };
615
- return /*#__PURE__*/jsxRuntime.jsxs(react.ListboxOptions, {
616
- modal: true,
617
- as: SelectInputOptionsContainer,
618
- static: true,
619
- className: "np-select-input-options-container",
620
- onAriaActiveDescendantChange: value => {
621
- if (controllerRef.current != null) {
622
- if (!initialRender && value != null) {
623
- controllerRef.current.setAttribute('aria-activedescendant', value);
624
- } else {
625
- controllerRef.current.removeAttribute('aria-activedescendant');
626
- }
627
- }
628
- },
629
- children: [filterable ? /*#__PURE__*/jsxRuntime.jsx("div", {
630
- className: "np-select-input-query-container",
631
- children: /*#__PURE__*/jsxRuntime.jsx(SearchInput.SearchInput, {
632
- ref: searchInputRef,
633
- id: id,
634
- name: name,
635
- autoComplete: autocomplete,
636
- role: "combobox",
637
- shape: "rectangle",
638
- placeholder: filterPlaceholder,
639
- "aria-label": filterPlaceholder,
640
- defaultValue: filterQuery,
641
- "aria-autocomplete": "list",
642
- "aria-expanded": true,
643
- "aria-controls": listboxId,
644
- "aria-describedby": showStatus ? statusId : undefined,
645
- onKeyDown: event => {
646
- // Prevent interfering with the matcher of Headless UI
647
- // https://mathiasbynens.be/notes/javascript-unicode#regex
648
- if (/^.$/u.test(event.key)) {
649
- event.stopPropagation();
650
- }
651
- },
652
- onChange: event => {
653
- // Free up resources and ensure not to go out of bounds when the
654
- // resulting item count is less than before
655
- const inputValue = event.currentTarget.value;
656
- // Free up resources and ensure not to go out of bounds
657
- setMountedIndexes([]);
658
- onFilterChange(inputValue);
659
- },
660
- onInput: event => {
661
- const inputValue = event.currentTarget.value;
662
- const inputElement = event.currentTarget;
663
- if (autocomplete && onAutocompleteSelect && inputValue) {
664
- setTimeout(() => {
665
- if (inputElement.value === inputValue && inputValue.length > 2) {
666
- const matchedValue = findMatchingItem(inputValue);
667
- if (matchedValue !== null) {
668
- onAutocompleteSelect(matchedValue);
669
- }
670
- }
671
- }, 50);
672
- }
673
- }
674
- })
675
- }) : null, /*#__PURE__*/jsxRuntime.jsxs("section", {
676
- ref: listboxContainerRef,
677
- tabIndex: -1,
678
- className: clsx.clsx('np-select-input-listbox-container', virtualized && 'np-select-input-listbox-container--virtualized', needle == null &&
679
- // Groups aren't shown when filtering
680
- items.some(item => item.type === 'group') && 'np-select-input-listbox-container--has-group'),
681
- "data-wds-parent": parentId ?? undefined,
682
- children: [resultsEmpty ? /*#__PURE__*/jsxRuntime.jsxs("div", {
683
- id: statusId,
684
- className: "np-select-input-options-status",
685
- children: [/*#__PURE__*/jsxRuntime.jsx(icons.CrossCircle, {
686
- size: 16,
687
- className: "np-select-input-options-status-icon"
688
- }), intl.formatMessage(SelectInput_messages.default.noResultsFound)]
689
- }) : null, /*#__PURE__*/jsxRuntime.jsx("div", {
690
- ref: listboxRef,
691
- id: listboxId,
692
- role: "listbox",
693
- "aria-orientation": "vertical",
694
- "aria-label": listBoxLabel,
695
- "aria-labelledby": listBoxLabelledBy,
696
- tabIndex: 0,
697
- className: "np-select-input-listbox",
698
- children: !virtualized ? filteredItems.map((_, index) => getItemNode(index)) : /*#__PURE__*/jsxRuntime.jsx(virtua.Virtualizer, {
699
- ref: virtualiserHandlerRef,
700
- data: filteredItems,
701
- keepMounted: mountedIndexes,
702
- scrollRef: listboxRef // `VList` doesn't expose this
703
- ,
704
- onScroll: async () => {
705
- if (!virtualiserHandlerRef.current) return;
706
- const startIndex = virtualiserHandlerRef.current.findItemIndex(virtualiserHandlerRef.current.scrollOffset);
707
- const endIndex = virtualiserHandlerRef.current.findItemIndex(virtualiserHandlerRef.current.scrollOffset + virtualiserHandlerRef.current.viewportSize);
708
- setMountedIndexes(prevMountedIndexes => {
709
- const indexes = new Set(prevMountedIndexes);
710
- for (let index = startIndex; index <= endIndex; index += 1) {
711
- indexes.add(index);
712
- }
713
- return [...indexes].sort((a, b) => a - b);
714
- });
715
- },
716
- children: (item, index) =>
717
- /*#__PURE__*/
718
- // The position of each item can't be inferred by browsers when
719
- // virtualizing, as some of the items may not be in the DOM
720
- jsxRuntime.jsx(SelectInputItemsCountContext.Provider, {
721
- value: filteredItems.length,
722
- children: /*#__PURE__*/jsxRuntime.jsx(SelectInputItemPositionContext.Provider, {
723
- value: index + 1,
724
- children: getItemNode(index)
725
- })
726
- })
727
- })
728
- }), renderFooter != null ? /*#__PURE__*/jsxRuntime.jsx("footer", {
729
- className: "np-select-input-footer",
730
- children: /*#__PURE__*/jsxRuntime.jsx("div", {
731
- role: "none",
732
- onKeyDown: event => {
733
- // Prevent interfering with Headless UI
734
- if (event.key !== 'Escape') {
735
- event.stopPropagation();
736
- }
737
- },
738
- children: renderFooter({
739
- resultsEmpty,
740
- queryNormalized: needle
741
- })
742
- })
743
- }) : null]
744
- })]
745
- });
746
- }
747
- function SelectInputItemView({
748
- item,
749
- renderValue,
750
- needle
751
- }) {
752
- switch (item.type) {
753
- case 'option':
754
- {
755
- if (item.value != null && (needle == null || selectInputOptionItemIncludesNeedle(item, needle))) {
756
- return /*#__PURE__*/jsxRuntime.jsx(SelectInputOption, {
757
- value: item.value,
758
- disabled: item.disabled,
759
- children: renderValue(item.value, false)
760
- });
761
- }
762
- break;
763
- }
764
- case 'group':
765
- {
766
- return /*#__PURE__*/jsxRuntime.jsx(SelectInputGroupItemView, {
767
- item: item,
768
- renderValue: renderValue,
769
- needle: needle
770
- });
771
- }
772
- case 'separator':
773
- {
774
- if (needle == null) {
775
- return /*#__PURE__*/jsxRuntime.jsx("hr", {
776
- className: "np-select-input-separator-item"
777
- });
778
- }
779
- break;
780
- }
781
- }
782
- return null;
783
- }
784
- function SelectInputGroupItemView({
785
- item,
786
- renderValue,
787
- needle
788
- }) {
789
- const headerId = React.useId();
790
- const header = /*#__PURE__*/jsxRuntime.jsx(Header.default, {
791
- as: "header",
792
- role: "none",
793
- id: headerId,
794
- title: item.label
795
- // @ts-expect-error when we migrate ActionButton to new Button this should be sorted
796
- ,
797
- action: item.action && {
798
- text: item.action.label,
799
- onClick: item.action.onClick
800
- },
801
- className: "np-select-input-group-item-header p-x-1"
802
- });
803
- return (
804
- /*#__PURE__*/
805
- // An empty container may be rendered when no options match `needle`
806
- // However, pre-filtering would result in worse performance overall
807
- jsxRuntime.jsxs(Section.default, {
808
- as: "section",
809
- role: "group",
810
- "aria-labelledby": headerId,
811
- className: clsx.clsx('m-y-0', needle === null && 'np-select-input-group-item--without-needle'),
812
- children: [needle == null ? header : null, item.options.map((option, index) => /*#__PURE__*/jsxRuntime.jsx(SelectInputItemView
813
- // eslint-disable-next-line react/no-array-index-key
814
- , {
815
- item: option,
816
- renderValue: renderValue,
817
- needle: needle
818
- }, index))]
819
- })
820
- );
821
- }
822
- const SelectInputItemsCountContext = /*#__PURE__*/React.createContext(undefined);
823
- const SelectInputItemPositionContext = /*#__PURE__*/React.createContext(undefined);
824
- function SelectInputOption({
825
- value,
826
- disabled,
827
- children
828
- }) {
829
- const itemsCount = React.useContext(SelectInputItemsCountContext);
830
- const itemPosition = React.useContext(SelectInputItemPositionContext);
831
- return /*#__PURE__*/jsxRuntime.jsx(react.ListboxOption, {
832
- as: "div",
833
- value: value,
834
- "aria-setsize": itemsCount,
835
- "aria-posinset": itemPosition,
836
- disabled: disabled,
837
- className: ({
838
- active,
839
- disabled: uiDisabled
840
- }) => clsx.clsx('np-select-input-option-container np-text-body-large', active && 'np-select-input-option-container--active', uiDisabled && 'np-select-input-option-container--disabled'),
841
- children: ({
842
- selected
843
- }) => /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
844
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
845
- className: "np-select-input-option",
846
- children: children
847
- }), /*#__PURE__*/jsxRuntime.jsx(icons.Check, {
848
- size: 16,
849
- className: clsx.clsx('np-select-input-option-check', !selected && 'np-select-input-option-check--not-selected')
850
- })]
851
- })
852
- });
853
- }
854
- const SelectInputOptionContentWithinTriggerContext = /*#__PURE__*/React.createContext(false);
855
- function SelectInputOptionContent({
856
- title,
857
- note,
858
- description,
859
- icon
860
- }) {
861
- const withinTrigger = React.useContext(SelectInputOptionContentWithinTriggerContext);
862
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
863
- className: clsx.clsx('np-select-input-option-content-container', (note || description) && 'np-text-body-large'),
864
- children: [icon ? /*#__PURE__*/jsxRuntime.jsx("div", {
865
- className: clsx.clsx('np-select-input-option-content-icon', !withinTrigger && 'np-select-input-option-content-icon--not-within-trigger'),
866
- children: icon
867
- }) : null, /*#__PURE__*/jsxRuntime.jsxs("div", {
868
- className: "np-select-input-option-content-text",
869
- children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
870
- className: clsx.clsx('np-select-input-option-content-text-line-1', withinTrigger && 'np-select-input-option-content-text-within-trigger'),
871
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
872
- className: "d-inline",
873
- children: title
874
- }), note ? /*#__PURE__*/jsxRuntime.jsx("span", {
875
- className: "np-select-input-option-content-text-secondary np-text-body-default",
876
- children: note
877
- }) : null]
878
- }), description ? /*#__PURE__*/jsxRuntime.jsx("div", {
879
- className: clsx.clsx('np-select-input-option-content-text-secondary np-text-body-default', withinTrigger && 'np-select-input-option-content-text-within-trigger np-select-input-option-description-in-trigger'),
880
- children: description
881
- }) : null]
882
- })]
883
- });
884
- }
885
-
886
- exports.SelectInput = SelectInput;
887
- exports.SelectInputOptionContent = SelectInputOptionContent;
888
- exports.SelectInputTriggerButton = SelectInputTriggerButton;
889
- exports.sortByRelevance = sortByRelevance;
890
- //# sourceMappingURL=SelectInput.js.map