@primer/components 0.0.0-202182720420 → 0.0.0-202182722258

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 (246) hide show
  1. package/CHANGELOG.md +2 -40
  2. package/dist/browser.esm.js +627 -670
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +389 -432
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Divider.js +1 -1
  7. package/lib/ActionList/Header.js +2 -2
  8. package/lib/ActionList/Item.js +13 -13
  9. package/lib/ActionList/List.js +1 -1
  10. package/lib/AnchoredOverlay/AnchoredOverlay.js +2 -2
  11. package/lib/Autocomplete/Autocomplete.d.ts +26 -0
  12. package/lib/Autocomplete/Autocomplete.js +55 -0
  13. package/lib/Autocomplete/AutocompleteContext.d.ts +13 -0
  14. package/lib/Autocomplete/AutocompleteContext.js +15 -0
  15. package/lib/Autocomplete/AutocompleteInput.d.ts +9 -0
  16. package/lib/Autocomplete/AutocompleteInput.js +139 -0
  17. package/lib/Autocomplete/AutocompleteMenu.d.ts +67 -0
  18. package/lib/Autocomplete/AutocompleteMenu.js +284 -0
  19. package/lib/Autocomplete/index.d.ts +2 -0
  20. package/lib/Autocomplete/index.js +15 -0
  21. package/lib/Avatar.d.ts +0 -4
  22. package/lib/AvatarPair.js +1 -1
  23. package/lib/AvatarStack.d.ts +8 -4
  24. package/lib/AvatarStack.js +7 -6
  25. package/lib/Badge/Badge.d.ts +8 -0
  26. package/lib/Badge/Badge.js +59 -0
  27. package/lib/Badge/BadgeState.d.ts +13 -0
  28. package/lib/Badge/BadgeState.js +51 -0
  29. package/lib/Badge/_badgeStyleUtils.d.ts +3 -0
  30. package/lib/Badge/_badgeStyleUtils.js +39 -0
  31. package/lib/BranchName.js +1 -1
  32. package/lib/Breadcrumb.d.ts +23 -0
  33. package/lib/{Breadcrumbs.js → Breadcrumb.js} +23 -33
  34. package/lib/Button/Button.d.ts +1 -0
  35. package/lib/Button/Button.js +1 -1
  36. package/lib/Button/ButtonClose.d.ts +2 -1
  37. package/lib/Button/ButtonClose.js +1 -1
  38. package/lib/Button/ButtonDanger.d.ts +1 -0
  39. package/lib/Button/ButtonInvisible.d.ts +1 -0
  40. package/lib/Button/ButtonInvisible.js +1 -1
  41. package/lib/Button/ButtonOutline.d.ts +1 -0
  42. package/lib/Button/ButtonPrimary.d.ts +1 -0
  43. package/lib/Button/ButtonTableList.js +1 -1
  44. package/lib/CircleBadge.js +1 -1
  45. package/lib/CircleOcticon.d.ts +1 -0
  46. package/lib/CircleOcticon.js +1 -1
  47. package/lib/CounterLabel.js +2 -2
  48. package/lib/Dialog/ConfirmationDialog.js +1 -1
  49. package/lib/Dialog/Dialog.js +9 -9
  50. package/lib/Dialog.d.ts +3 -2
  51. package/lib/Dialog.js +4 -4
  52. package/lib/Dropdown.d.ts +4 -0
  53. package/lib/Dropdown.js +2 -2
  54. package/lib/DropdownMenu/DropdownButton.d.ts +2 -1
  55. package/lib/DropdownStyles.js +6 -6
  56. package/lib/FilterList.d.ts +1 -0
  57. package/lib/FilterList.js +1 -1
  58. package/lib/FilteredActionList/FilteredActionList.js +8 -34
  59. package/lib/Flash.js +1 -1
  60. package/lib/Label.js +2 -2
  61. package/lib/Link.js +1 -1
  62. package/lib/Overlay.d.ts +2 -1
  63. package/lib/Overlay.js +11 -6
  64. package/lib/Pagehead.js +1 -1
  65. package/lib/Pagination/Pagination.js +1 -1
  66. package/lib/Popover.js +1 -1
  67. package/lib/Position.d.ts +4 -4
  68. package/lib/ProgressBar.js +1 -1
  69. package/lib/SelectMenu/SelectMenu.d.ts +344 -15
  70. package/lib/SelectMenu/SelectMenuDivider.js +1 -1
  71. package/lib/SelectMenu/SelectMenuFilter.d.ts +1 -1
  72. package/lib/SelectMenu/SelectMenuFilter.js +1 -1
  73. package/lib/SelectMenu/SelectMenuFooter.js +1 -1
  74. package/lib/SelectMenu/SelectMenuHeader.js +2 -2
  75. package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
  76. package/lib/SelectMenu/SelectMenuItem.js +1 -1
  77. package/lib/SelectMenu/SelectMenuList.js +1 -1
  78. package/lib/SelectMenu/SelectMenuLoadingAnimation.js +1 -1
  79. package/lib/SelectMenu/SelectMenuModal.d.ts +1 -1
  80. package/lib/SelectMenu/SelectMenuModal.js +2 -2
  81. package/lib/SelectMenu/SelectMenuTab.js +1 -1
  82. package/lib/SelectMenu/SelectMenuTabPanel.js +1 -1
  83. package/lib/SelectPanel/SelectPanel.js +2 -3
  84. package/lib/SideNav.js +5 -5
  85. package/lib/StateLabel.js +1 -1
  86. package/lib/SubNav.js +1 -1
  87. package/lib/TabNav.js +2 -2
  88. package/lib/TextInput.d.ts +10 -7
  89. package/lib/TextInput.js +24 -29
  90. package/lib/TextInputTokens.d.ts +43 -0
  91. package/lib/TextInputTokens.js +227 -0
  92. package/lib/TextInputWithTokens.d.ts +41 -0
  93. package/lib/TextInputWithTokens.js +396 -0
  94. package/lib/Timeline.d.ts +1 -0
  95. package/lib/Timeline.js +19 -16
  96. package/lib/Token/Token.d.ts +7 -0
  97. package/lib/Token/Token.js +63 -0
  98. package/lib/Token/TokenBase.d.ts +16 -0
  99. package/lib/Token/TokenBase.js +76 -0
  100. package/lib/Token/TokenLabel.d.ts +10 -0
  101. package/lib/Token/TokenLabel.js +115 -0
  102. package/lib/Token/TokenProfile.d.ts +7 -0
  103. package/lib/Token/TokenProfile.js +45 -0
  104. package/lib/Token/_RemoveTokenButton.d.ts +3 -0
  105. package/lib/Token/_RemoveTokenButton.js +43 -0
  106. package/lib/Token/_tokenButtonUtils.d.ts +9 -0
  107. package/lib/Token/_tokenButtonUtils.js +42 -0
  108. package/lib/Tooltip.js +1 -1
  109. package/lib/UnderlineNav.js +2 -2
  110. package/lib/_UnstyledTextInput.d.ts +2 -0
  111. package/lib/_UnstyledTextInput.js +20 -0
  112. package/lib/hooks/useOverlay.d.ts +2 -1
  113. package/lib/hooks/useOverlay.js +11 -6
  114. package/lib/index.d.ts +2 -3
  115. package/lib/index.js +2 -22
  116. package/lib/theme-preval.d.ts +6 -12
  117. package/lib/theme-preval.js +0 -940
  118. package/lib/utils/scrollIntoViewingArea.d.ts +1 -0
  119. package/lib/utils/scrollIntoViewingArea.js +39 -0
  120. package/lib/utils/testing.d.ts +0 -1854
  121. package/lib/utils/types.d.ts +3 -0
  122. package/lib/utils/uniqueId.js +0 -1
  123. package/lib-esm/ActionList/Divider.js +1 -1
  124. package/lib-esm/ActionList/Header.js +2 -2
  125. package/lib-esm/ActionList/Item.js +14 -14
  126. package/lib-esm/ActionList/List.js +1 -1
  127. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -3
  128. package/lib-esm/Autocomplete/Autocomplete.d.ts +26 -0
  129. package/lib-esm/Autocomplete/Autocomplete.js +36 -0
  130. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +13 -0
  131. package/lib-esm/Autocomplete/AutocompleteContext.js +6 -0
  132. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +9 -0
  133. package/lib-esm/Autocomplete/AutocompleteInput.js +120 -0
  134. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +67 -0
  135. package/lib-esm/Autocomplete/AutocompleteMenu.js +258 -0
  136. package/lib-esm/Autocomplete/index.d.ts +2 -0
  137. package/lib-esm/Autocomplete/index.js +1 -0
  138. package/lib-esm/Avatar.d.ts +0 -4
  139. package/lib-esm/AvatarPair.js +1 -1
  140. package/lib-esm/AvatarStack.d.ts +8 -4
  141. package/lib-esm/AvatarStack.js +8 -7
  142. package/lib-esm/Badge/Badge.d.ts +8 -0
  143. package/lib-esm/Badge/Badge.js +44 -0
  144. package/lib-esm/Badge/BadgeState.d.ts +13 -0
  145. package/lib-esm/Badge/BadgeState.js +40 -0
  146. package/lib-esm/Badge/_badgeStyleUtils.d.ts +3 -0
  147. package/lib-esm/Badge/_badgeStyleUtils.js +29 -0
  148. package/lib-esm/BranchName.js +1 -1
  149. package/lib-esm/Breadcrumb.d.ts +23 -0
  150. package/lib-esm/{Breadcrumbs.js → Breadcrumb.js} +21 -30
  151. package/lib-esm/Button/Button.d.ts +1 -0
  152. package/lib-esm/Button/Button.js +1 -1
  153. package/lib-esm/Button/ButtonClose.d.ts +2 -1
  154. package/lib-esm/Button/ButtonClose.js +1 -1
  155. package/lib-esm/Button/ButtonDanger.d.ts +1 -0
  156. package/lib-esm/Button/ButtonInvisible.d.ts +1 -0
  157. package/lib-esm/Button/ButtonInvisible.js +1 -1
  158. package/lib-esm/Button/ButtonOutline.d.ts +1 -0
  159. package/lib-esm/Button/ButtonPrimary.d.ts +1 -0
  160. package/lib-esm/Button/ButtonTableList.js +1 -1
  161. package/lib-esm/CircleBadge.js +1 -1
  162. package/lib-esm/CircleOcticon.d.ts +1 -0
  163. package/lib-esm/CircleOcticon.js +1 -1
  164. package/lib-esm/CounterLabel.js +2 -2
  165. package/lib-esm/Dialog/ConfirmationDialog.js +1 -1
  166. package/lib-esm/Dialog/Dialog.js +8 -8
  167. package/lib-esm/Dialog.d.ts +3 -2
  168. package/lib-esm/Dialog.js +4 -4
  169. package/lib-esm/Dropdown.d.ts +4 -0
  170. package/lib-esm/Dropdown.js +2 -2
  171. package/lib-esm/DropdownMenu/DropdownButton.d.ts +2 -1
  172. package/lib-esm/DropdownStyles.js +6 -6
  173. package/lib-esm/FilterList.d.ts +1 -0
  174. package/lib-esm/FilterList.js +1 -1
  175. package/lib-esm/FilteredActionList/FilteredActionList.js +6 -34
  176. package/lib-esm/Flash.js +1 -1
  177. package/lib-esm/Label.js +2 -2
  178. package/lib-esm/Link.js +1 -1
  179. package/lib-esm/Overlay.d.ts +2 -1
  180. package/lib-esm/Overlay.js +9 -6
  181. package/lib-esm/Pagehead.js +1 -1
  182. package/lib-esm/Pagination/Pagination.js +1 -1
  183. package/lib-esm/Popover.js +1 -1
  184. package/lib-esm/Position.d.ts +4 -4
  185. package/lib-esm/ProgressBar.js +1 -1
  186. package/lib-esm/SelectMenu/SelectMenu.d.ts +344 -15
  187. package/lib-esm/SelectMenu/SelectMenuDivider.js +1 -1
  188. package/lib-esm/SelectMenu/SelectMenuFilter.d.ts +1 -1
  189. package/lib-esm/SelectMenu/SelectMenuFilter.js +1 -1
  190. package/lib-esm/SelectMenu/SelectMenuFooter.js +1 -1
  191. package/lib-esm/SelectMenu/SelectMenuHeader.js +2 -2
  192. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
  193. package/lib-esm/SelectMenu/SelectMenuItem.js +1 -1
  194. package/lib-esm/SelectMenu/SelectMenuList.js +1 -1
  195. package/lib-esm/SelectMenu/SelectMenuLoadingAnimation.js +1 -1
  196. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +1 -1
  197. package/lib-esm/SelectMenu/SelectMenuModal.js +2 -2
  198. package/lib-esm/SelectMenu/SelectMenuTab.js +1 -1
  199. package/lib-esm/SelectMenu/SelectMenuTabPanel.js +1 -1
  200. package/lib-esm/SelectPanel/SelectPanel.js +2 -3
  201. package/lib-esm/SideNav.js +5 -5
  202. package/lib-esm/StateLabel.js +1 -1
  203. package/lib-esm/SubNav.js +1 -1
  204. package/lib-esm/TabNav.js +2 -2
  205. package/lib-esm/TextInput.d.ts +10 -7
  206. package/lib-esm/TextInput.js +23 -29
  207. package/lib-esm/TextInputTokens.d.ts +43 -0
  208. package/lib-esm/TextInputTokens.js +200 -0
  209. package/lib-esm/TextInputWithTokens.d.ts +41 -0
  210. package/lib-esm/TextInputWithTokens.js +361 -0
  211. package/lib-esm/Timeline.d.ts +1 -0
  212. package/lib-esm/Timeline.js +17 -12
  213. package/lib-esm/Token/Token.d.ts +7 -0
  214. package/lib-esm/Token/Token.js +44 -0
  215. package/lib-esm/Token/TokenBase.d.ts +16 -0
  216. package/lib-esm/Token/TokenBase.js +56 -0
  217. package/lib-esm/Token/TokenLabel.d.ts +10 -0
  218. package/lib-esm/Token/TokenLabel.js +99 -0
  219. package/lib-esm/Token/TokenProfile.d.ts +7 -0
  220. package/lib-esm/Token/TokenProfile.js +28 -0
  221. package/lib-esm/Token/_RemoveTokenButton.d.ts +3 -0
  222. package/lib-esm/Token/_RemoveTokenButton.js +28 -0
  223. package/lib-esm/Token/_tokenButtonUtils.d.ts +9 -0
  224. package/lib-esm/Token/_tokenButtonUtils.js +26 -0
  225. package/lib-esm/Tooltip.js +1 -1
  226. package/lib-esm/UnderlineNav.js +2 -2
  227. package/lib-esm/_UnstyledTextInput.d.ts +2 -0
  228. package/lib-esm/_UnstyledTextInput.js +7 -0
  229. package/lib-esm/hooks/useOverlay.d.ts +2 -1
  230. package/lib-esm/hooks/useOverlay.js +11 -6
  231. package/lib-esm/index.d.ts +2 -3
  232. package/lib-esm/index.js +2 -3
  233. package/lib-esm/theme-preval.d.ts +6 -12
  234. package/lib-esm/theme-preval.js +0 -940
  235. package/lib-esm/utils/scrollIntoViewingArea.d.ts +1 -0
  236. package/lib-esm/utils/scrollIntoViewingArea.js +30 -0
  237. package/lib-esm/utils/testing.d.ts +0 -1854
  238. package/lib-esm/utils/types.d.ts +3 -0
  239. package/lib-esm/utils/uniqueId.js +0 -1
  240. package/package.json +14 -14
  241. package/lib/Breadcrumbs.d.ts +0 -40
  242. package/lib/utils/ssr.d.ts +0 -1
  243. package/lib/utils/ssr.js +0 -19
  244. package/lib-esm/Breadcrumbs.d.ts +0 -40
  245. package/lib-esm/utils/ssr.d.ts +0 -1
  246. package/lib-esm/utils/ssr.js +0 -1
@@ -0,0 +1,200 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React, { useRef, useState } from 'react';
4
+ import { omit } from '@styled-system/props';
5
+ import styled from 'styled-components';
6
+ import { FocusKeys } from './behaviors/focusZone';
7
+ import { useCombinedRefs } from './hooks/useCombinedRefs';
8
+ import { useFocusZone } from './hooks/useFocusZone';
9
+ import Token from './Token/Token';
10
+ import TextInput from './TextInput';
11
+ import { useProvidedRefOrCreate } from './hooks';
12
+ import UnstyledTextInput from './_UnstyledTextInput';
13
+ const InputWrapper = styled.div.withConfig({
14
+ displayName: "TextInputTokens__InputWrapper",
15
+ componentId: "sc-1k54xiz-0"
16
+ })(["order:1;flex-grow:1;"]);
17
+ // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
18
+ const TextInputWithTokensComponent = /*#__PURE__*/React.forwardRef(({
19
+ icon: IconComponent,
20
+ contrast,
21
+ className,
22
+ block,
23
+ disabled,
24
+ theme,
25
+ sx: sxProp,
26
+ tokens,
27
+ onTokenRemove,
28
+ tokenComponent: TokenComponent,
29
+ preventTokenWrapping,
30
+ tokenSizeVariant,
31
+ hideTokenRemoveButtons,
32
+ selectedTokenIdx,
33
+ setSelectedTokenIdx,
34
+ ...rest
35
+ }, externalRef) => {
36
+ const ref = useProvidedRefOrCreate(externalRef);
37
+ const {
38
+ onFocus,
39
+ onKeyDown,
40
+ ...inputPropsRest
41
+ } = omit(rest);
42
+
43
+ const handleTokenRemove = tokenId => {
44
+ onTokenRemove(tokenId);
45
+ };
46
+
47
+ const handleTokenFocus = tokenIdx => () => {
48
+ setSelectedTokenIdx(tokenIdx);
49
+ };
50
+
51
+ const handleTokenBlur = () => {
52
+ setSelectedTokenIdx(undefined);
53
+ };
54
+
55
+ const handleTokenKeyUp = tokenId => e => {
56
+ if (e.key === 'Backspace') {
57
+ handleTokenRemove(tokenId);
58
+ }
59
+
60
+ if (e.key === 'Escape') {
61
+ var _ref$current;
62
+
63
+ ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
64
+ }
65
+ };
66
+
67
+ const handleInputFocus = e => {
68
+ onFocus && onFocus(e);
69
+ setSelectedTokenIdx(undefined);
70
+ };
71
+
72
+ const handleInputKeyDown = e => {
73
+ var _ref$current2;
74
+
75
+ if (onKeyDown) {
76
+ onKeyDown(e);
77
+ }
78
+
79
+ if (ref !== null && ref !== void 0 && (_ref$current2 = ref.current) !== null && _ref$current2 !== void 0 && _ref$current2.value) {
80
+ return;
81
+ }
82
+
83
+ const lastToken = tokens[tokens.length - 1];
84
+
85
+ if (e.key === 'Backspace' && lastToken) {
86
+ handleTokenRemove(lastToken.id);
87
+
88
+ if (ref !== null && ref !== void 0 && ref.current) {
89
+ // TODO: eliminate the first hack by making changes to the Autocomplete component
90
+ // COLEHELP
91
+ //
92
+ // HACKS:
93
+ // 1. Directly setting `ref.current.value` instead of updating state because the autocomplete
94
+ // highlight behavior doesn't work correctly if we update the value with a setState action in onChange
95
+ // 2. Adding an extra space so that when I backspace, it doesn't delete the last letter
96
+ ref.current.value = `${lastToken.text} `;
97
+ } // HACK: for some reason we need to wait a tick for `.select()` to work
98
+
99
+
100
+ setTimeout(() => {
101
+ var _ref$current3;
102
+
103
+ ref === null || ref === void 0 ? void 0 : (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.select();
104
+ }, 1);
105
+ }
106
+ };
107
+
108
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(InputWrapper, null, /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
109
+ ref: ref,
110
+ disabled: disabled,
111
+ onFocus: handleInputFocus,
112
+ onKeyDown: handleInputKeyDown,
113
+ type: "text",
114
+ sx: {
115
+ height: '100%'
116
+ }
117
+ }, inputPropsRest))), tokens !== null && tokens !== void 0 && tokens.length && TokenComponent ? tokens.map(({
118
+ id,
119
+ ...tokenRest
120
+ }, i) => /*#__PURE__*/React.createElement(TokenComponent, _extends({
121
+ onFocus: handleTokenFocus(i),
122
+ onBlur: handleTokenBlur,
123
+ onKeyUp: handleTokenKeyUp(id),
124
+ isSelected: selectedTokenIdx === i,
125
+ handleRemove: !hideTokenRemoveButtons ? () => {
126
+ handleTokenRemove(id);
127
+ } : undefined,
128
+ variant: tokenSizeVariant,
129
+ tabIndex: 0
130
+ }, tokenRest))) : null);
131
+ });
132
+ const TextInputWithTokens = /*#__PURE__*/React.forwardRef(({
133
+ tokens,
134
+ sx: sxProp,
135
+ ...props
136
+ }, ref) => {
137
+ const localInputRef = useRef(null);
138
+ const combinedInputRef = useCombinedRefs(localInputRef, ref);
139
+ const [selectedTokenIdx, setSelectedTokenIdx] = useState();
140
+ const {
141
+ containerRef
142
+ } = useFocusZone({
143
+ focusOutBehavior: 'wrap',
144
+ bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
145
+ focusableElementFilter: element => {
146
+ return !(element instanceof HTMLButtonElement);
147
+ },
148
+ getNextFocusable: direction => {
149
+ var _containerRef$current;
150
+
151
+ if (!selectedTokenIdx && selectedTokenIdx !== 0) {
152
+ return undefined;
153
+ }
154
+
155
+ let nextIndex = selectedTokenIdx + 1;
156
+
157
+ if (direction === 'next') {
158
+ nextIndex += 1;
159
+ }
160
+
161
+ if (direction === 'previous') {
162
+ nextIndex -= 1;
163
+ }
164
+
165
+ if (nextIndex > tokens.length || nextIndex < 1) {
166
+ return combinedInputRef.current || undefined;
167
+ }
168
+
169
+ return containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
170
+ }
171
+ }, [selectedTokenIdx]);
172
+ return /*#__PURE__*/React.createElement(TextInput, _extends({
173
+ ref: combinedInputRef,
174
+ wrapperRef: containerRef,
175
+ as: TextInputWithTokensComponent,
176
+ selectedTokenIdx: selectedTokenIdx,
177
+ setSelectedTokenIdx: setSelectedTokenIdx,
178
+ tokens: tokens,
179
+ sx: {
180
+ 'alignItems': props.preventTokenWrapping ? 'center' : undefined,
181
+ 'flexWrap': props.preventTokenWrapping ? 'nowrap' : 'wrap',
182
+ 'gap': '0.25rem',
183
+ '> *': {
184
+ 'flexShrink': 0
185
+ },
186
+ ...(props.block ? {
187
+ display: 'flex',
188
+ width: '100%'
189
+ } : {}),
190
+ ...sxProp
191
+ }
192
+ }, props));
193
+ });
194
+ TextInputWithTokens.defaultProps = {
195
+ tokenComponent: Token,
196
+ tokenSizeVariant: "xl",
197
+ hideTokenRemoveButtons: false
198
+ };
199
+ TextInputWithTokens.displayName = 'TextInputWithTokens';
200
+ export default TextInputWithTokens;
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
3
+ import { ItemProps } from './ActionList';
4
+ import { ItemInput } from './ActionList/List';
5
+ import { SystemCommonProps } from './constants';
6
+ import { SxProp } from './sx';
7
+ import { ComponentProps } from './utils/types';
8
+ import Token from './Token/Token';
9
+ declare const Input: import("styled-components").StyledComponent<"input", any, {}, never>;
10
+ declare const Wrapper: import("styled-components").StyledComponent<"span", any, {
11
+ disabled?: boolean | undefined;
12
+ hasIcon?: boolean | undefined;
13
+ block?: boolean | undefined;
14
+ contrast?: boolean | undefined;
15
+ variant?: "large" | "small" | undefined;
16
+ maxHeight?: React.CSSProperties['maxHeight'];
17
+ } & SystemCommonProps & WidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Width<import("styled-system").TLengthStyledSystem>> & MinWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MinWidth<import("styled-system").TLengthStyledSystem>> & MaxWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>> & SxProp, never>;
18
+ interface Token {
19
+ text?: string;
20
+ id: string | number;
21
+ }
22
+ declare type TextInputWithTokensInternalProps = {
23
+ as?: any;
24
+ icon?: React.ComponentType<{
25
+ className?: string;
26
+ }>;
27
+ tokens: Token[];
28
+ onTokenRemove: (tokenId: string | number) => void;
29
+ selectableItems: ItemInput[];
30
+ onFilterChange: (value: string, e: React.ChangeEvent<HTMLInputElement>) => void;
31
+ onItemSelect: NonNullable<ItemProps['onAction']>;
32
+ tokenComponent?: React.FunctionComponent<any>;
33
+ emptyStateText?: React.ReactNode | false;
34
+ addNewTokenItem?: Omit<ItemInput, 'onAction'>;
35
+ onCloseOptionsList?: () => void;
36
+ maxHeight?: React.CSSProperties['maxHeight'];
37
+ loading?: boolean;
38
+ } & ComponentProps<typeof Wrapper> & ComponentProps<typeof Input>;
39
+ declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<TextInputWithTokensInternalProps, "backgroundColor" | "color" | "display" | "height" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minWidth" | "opacity" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "translate" | "width" | "margin" | "padding" | "hidden" | "children" | "theme" | "value" | "form" | "p" | "slot" | "style" | "title" | "pattern" | "list" | "type" | "name" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "css" | "block" | "bg" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "px" | "paddingX" | "py" | "paddingY" | "step" | "size" | "icon" | "sx" | "max" | "min" | "crossOrigin" | "alt" | "src" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "autoComplete" | "loading" | "accept" | "capture" | "checked" | "enterKeyHint" | "maxLength" | "minLength" | "multiple" | "readOnly" | "required" | "as" | "variant" | "hasIcon" | "contrast" | "onItemSelect" | "emptyStateText" | "onFilterChange" | "tokens" | "onTokenRemove" | "tokenComponent" | "selectableItems" | "addNewTokenItem" | "onCloseOptionsList"> & React.RefAttributes<HTMLInputElement>>;
40
+ export declare type TextInputWithTokensProps = ComponentProps<typeof TextInputWithTokens>;
41
+ export default TextInputWithTokens;
@@ -0,0 +1,361 @@
1
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+
3
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { omit, pick } from '@styled-system/props';
5
+ import classnames from 'classnames';
6
+ import styled, { css } from 'styled-components';
7
+ import { maxWidth, minWidth, variant, width } from 'styled-system';
8
+ import { ActionList } from './ActionList';
9
+ import { FocusKeys } from './behaviors/focusZone';
10
+ import { COMMON, get } from './constants';
11
+ import { useAnchoredPosition } from './hooks';
12
+ import { useCombinedRefs } from './hooks/useCombinedRefs';
13
+ import { useFocusZone } from './hooks/useFocusZone';
14
+ import Overlay from './Overlay';
15
+ import sx from './sx';
16
+ import Token from './Token/Token';
17
+ import { Box, Spinner } from '.';
18
+ import { registerPortalRoot } from './Portal';
19
+ const DROPDOWN_PORTAL_CONTAINER_NAME = '__listcontainerportal__';
20
+
21
+ function scrollIntoViewingArea(child, container, margin = 8, behavior = 'smooth') {
22
+ const {
23
+ top: childTop,
24
+ bottom: childBottom
25
+ } = child.getBoundingClientRect();
26
+ const {
27
+ top: containerTop,
28
+ bottom: containerBottom
29
+ } = container.getBoundingClientRect();
30
+ const isChildTopAboveViewingArea = childTop < containerTop + margin;
31
+ const isChildBottomBelowViewingArea = childBottom > containerBottom - margin;
32
+
33
+ if (isChildTopAboveViewingArea) {
34
+ const scrollHeightToChildTop = childTop - containerTop + container.scrollTop;
35
+ container.scrollTo({
36
+ behavior,
37
+ top: scrollHeightToChildTop - margin
38
+ });
39
+ } else if (isChildBottomBelowViewingArea) {
40
+ const scrollHeightToChildBottom = childBottom - containerBottom + container.scrollTop;
41
+ container.scrollTo({
42
+ behavior,
43
+ top: scrollHeightToChildBottom + margin
44
+ });
45
+ } // either completely in view or outside viewing area on both ends, don't scroll
46
+
47
+ }
48
+
49
+ const sizeVariants = variant({
50
+ variants: {
51
+ small: {
52
+ minHeight: '28px',
53
+ px: 2,
54
+ py: '3px',
55
+ fontSize: 0,
56
+ lineHeight: '20px'
57
+ },
58
+ large: {
59
+ px: 2,
60
+ py: '10px',
61
+ fontSize: 3
62
+ }
63
+ }
64
+ });
65
+ const Input = styled.input.withConfig({
66
+ displayName: "TextInputWithTokens__Input",
67
+ componentId: "sc-8z94t5-0"
68
+ })(["border:0;font-size:inherit;font-family:inherit;background-color:transparent;-webkit-appearance:none;color:inherit;height:100%;width:100%;padding:0;&:focus{outline:0;}"]);
69
+ const InputWrapper = styled.div.withConfig({
70
+ displayName: "TextInputWithTokens__InputWrapper",
71
+ componentId: "sc-8z94t5-1"
72
+ })(["position:relative;order:1;flex-grow:1;&:after{content:attr(data-autocompleteSuggestion);pointer-events:none;display:flex;align-items:center;position:absolute;left:0;top:1px;width:100%;height:100%;display:flex;align-items:center;color:rgba(0,0,0,0.5);}"]);
73
+ const Wrapper = styled.span.withConfig({
74
+ displayName: "TextInputWithTokens__Wrapper",
75
+ componentId: "sc-8z94t5-2"
76
+ })(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";flex-wrap:wrap;gap:0.25rem;", " ", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.text.primary'), get('colors.border.primary'), get('radii.2'), get('shadows.shadow.inset'), props => {
77
+ if (props.hasIcon) {
78
+ return css(["padding:0;"]);
79
+ } else {
80
+ return css(["padding:6px 12px;"]);
81
+ }
82
+ }, props => {
83
+ if (props.maxHeight) {
84
+ return css(["max-height:", ";overflow:auto;"], props.maxHeight);
85
+ }
86
+ }, get('colors.icon.tertiary'), get('space.2'), get('colors.state.focus.border'), get('shadows.state.focus.shadow'), props => props.contrast && css(["background-color:", ";"], get('colors.input.contrastBg')), props => props.disabled && css(["color:", ";background-color:", ";border-color:", ";"], get('colors.text.secondary'), get('colors.input.disabledBg'), get('colors.input.disabledBorder')), props => props.block && css(["display:block;width:100%;"]), get('breakpoints.1'), get('fontSizes.1'), COMMON, width, minWidth, maxWidth, sizeVariants, sx);
87
+ // using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input
88
+ const TextInputWithTokens = /*#__PURE__*/React.forwardRef(({
89
+ icon: IconComponent,
90
+ contrast,
91
+ className,
92
+ block,
93
+ disabled,
94
+ theme,
95
+ sx: sxProp,
96
+ tokens,
97
+ selectableItems,
98
+ onFilterChange,
99
+ onItemSelect,
100
+ onTokenRemove,
101
+ tokenComponent: TokenComponent,
102
+ emptyStateText,
103
+ addNewTokenItem,
104
+ onCloseOptionsList,
105
+ loading,
106
+ ...rest
107
+ }, ref) => {
108
+ const listContainerRef = useRef(null);
109
+ const localInputRef = useRef(null);
110
+ const scrollContainerRef = useRef(null);
111
+ const activeDescendantRef = useRef();
112
+ const combinedInputRef = useCombinedRefs(localInputRef, ref); // this class is necessary to style FilterSearch, plz no touchy!
113
+
114
+ const wrapperClasses = classnames(className, 'TextInput-wrapper');
115
+ const wrapperProps = pick(rest);
116
+ const inputProps = omit(rest);
117
+ const [selectedTokenIdx, setSelectedTokenIdx] = useState();
118
+ const [inputVal, setInputVal] = useState('');
119
+ const [showMenu, setShowMenu] = useState(false);
120
+ const [selectedItems, setSelectedItems] = useState(tokens.map(({
121
+ id,
122
+ text
123
+ }) => ({
124
+ id,
125
+ text
126
+ })));
127
+ const [autocompleteSuggestion, setAutocompleteSuggestion] = useState('');
128
+ const [highlightedItem, setHighlightedItem] = useState();
129
+ const {
130
+ containerRef
131
+ } = useFocusZone({
132
+ focusOutBehavior: 'wrap',
133
+ bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
134
+ focusableElementFilter: element => {
135
+ return !(element instanceof HTMLButtonElement);
136
+ }
137
+ });
138
+ const {
139
+ floatingElementRef,
140
+ position
141
+ } = useAnchoredPosition({
142
+ side: 'outside-bottom',
143
+ align: 'start',
144
+ anchorElementRef: combinedInputRef
145
+ }, [showMenu, tokens]);
146
+
147
+ const closeOptionList = () => {
148
+ setShowMenu(false);
149
+
150
+ if (onCloseOptionsList) {
151
+ onCloseOptionsList();
152
+ }
153
+ };
154
+
155
+ const showOptionList = () => {
156
+ setShowMenu(true);
157
+ };
158
+
159
+ const handleTokenRemove = tokenId => {
160
+ onTokenRemove(tokenId);
161
+ setSelectedItems(selectedItems.filter(selectedItem => selectedItem.id !== tokenId));
162
+ };
163
+
164
+ const handleTokenFocus = tokenIdx => () => {
165
+ setSelectedTokenIdx(tokenIdx);
166
+ closeOptionList();
167
+ };
168
+
169
+ const handleTokenBlur = () => {
170
+ setSelectedTokenIdx(undefined);
171
+ };
172
+
173
+ const handleTokenKeyUp = tokenId => e => {
174
+ if (e.key === 'Backspace') {
175
+ handleTokenRemove(tokenId);
176
+ }
177
+
178
+ if (e.key === 'Escape') {
179
+ var _combinedInputRef$cur;
180
+
181
+ combinedInputRef === null || combinedInputRef === void 0 ? void 0 : (_combinedInputRef$cur = combinedInputRef.current) === null || _combinedInputRef$cur === void 0 ? void 0 : _combinedInputRef$cur.focus();
182
+ }
183
+ };
184
+
185
+ const handleInputFocus = () => {
186
+ setSelectedTokenIdx(undefined);
187
+ showOptionList();
188
+ };
189
+
190
+ const handleInputChange = e => {
191
+ onFilterChange(e.currentTarget.value, e);
192
+ setInputVal(e.currentTarget.value);
193
+ };
194
+
195
+ const handleInputKeyDown = e => {
196
+ if (e.key === 'ArrowRight' && autocompleteSuggestion) {
197
+ setInputVal(autocompleteSuggestion); // TODO: use hooks or something to always trigger `onFilterChange` when `inputVal` is changed
198
+
199
+ onFilterChange(autocompleteSuggestion, e);
200
+ }
201
+
202
+ if (inputVal) {
203
+ return;
204
+ }
205
+
206
+ const lastToken = tokens[tokens.length - 1];
207
+
208
+ if (e.key === 'Backspace') {
209
+ handleTokenRemove(lastToken.id);
210
+ setInputVal(`${lastToken.text}` || ''); // TODO: use hooks or something to always trigger `onFilterChange` when `inputVal` is changed
211
+
212
+ onFilterChange(lastToken.text || '', e); // HACK: for some reason we need to wait a tick for `.select()` to work
213
+
214
+ setTimeout(() => {
215
+ var _combinedInputRef$cur2;
216
+
217
+ combinedInputRef === null || combinedInputRef === void 0 ? void 0 : (_combinedInputRef$cur2 = combinedInputRef.current) === null || _combinedInputRef$cur2 === void 0 ? void 0 : _combinedInputRef$cur2.select();
218
+ }, 1);
219
+ }
220
+ };
221
+
222
+ const onInputKeyPress = useCallback(event => {
223
+ if (event.key === 'Enter' && activeDescendantRef.current) {
224
+ event.preventDefault();
225
+ event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
226
+
227
+ const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
228
+ activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
229
+ }
230
+ }, [activeDescendantRef]);
231
+
232
+ const getSelectedItems = (itemId, checked) => {
233
+ const newlySelectedItem = selectableItems.find(item => item.id === itemId);
234
+
235
+ if (checked) {
236
+ return [...selectedItems, ...(newlySelectedItem ? [newlySelectedItem] : [])];
237
+ }
238
+
239
+ return selectedItems.filter(selectedChoice => selectedChoice.id !== itemId);
240
+ };
241
+
242
+ const itemsToRender = [// selectable tokens
243
+ ...selectableItems.map(selectableItem => ({ ...selectableItem,
244
+ selected: selectableItem.selected || selectedItems.map(item => item.id).includes(selectableItem.id),
245
+ onAction: (item, e) => {
246
+ setSelectedItems(getSelectedItems(item.id, !item.selected) || []);
247
+
248
+ if (!item.selected) {
249
+ onItemSelect(item, e);
250
+ setInputVal('');
251
+ setAutocompleteSuggestion('');
252
+ } else {
253
+ handleTokenRemove(item.id !== null && item.id !== undefined ? item.id : '');
254
+ }
255
+ }
256
+ })), // menu item used for creating a token from whatever is in the text input
257
+ ...(addNewTokenItem ? [{ ...addNewTokenItem,
258
+ onAction: (_item, e) => {
259
+ onItemSelect({
260
+ text: inputVal,
261
+ id: `randomlyGeneratedId-${inputVal}`
262
+ }, e);
263
+ }
264
+ }] : [])];
265
+ useFocusZone({
266
+ containerRef: listContainerRef,
267
+ focusOutBehavior: 'wrap',
268
+ focusableElementFilter: element => {
269
+ return !(element instanceof HTMLInputElement);
270
+ },
271
+ activeDescendantFocus: combinedInputRef,
272
+ onActiveDescendantChanged: (current, _previous, directlyActivated) => {
273
+ activeDescendantRef.current = current;
274
+ const selectedItem = itemsToRender.find(item => {
275
+ var _item$id;
276
+
277
+ return ((_item$id = item.id) === null || _item$id === void 0 ? void 0 : _item$id.toString()) === (current === null || current === void 0 ? void 0 : current.dataset.id);
278
+ });
279
+ setHighlightedItem(selectedItem);
280
+
281
+ if (current && scrollContainerRef.current && directlyActivated) {
282
+ scrollIntoViewingArea(current, scrollContainerRef.current);
283
+ }
284
+ }
285
+ });
286
+ useEffect(() => {
287
+ var _highlightedItem$text;
288
+
289
+ if (highlightedItem !== null && highlightedItem !== void 0 && (_highlightedItem$text = highlightedItem.text) !== null && _highlightedItem$text !== void 0 && _highlightedItem$text.startsWith(inputVal)) {
290
+ setAutocompleteSuggestion(highlightedItem.text);
291
+ } else {
292
+ setAutocompleteSuggestion('');
293
+ }
294
+ }, [highlightedItem, inputVal]);
295
+
296
+ if (listContainerRef.current) {
297
+ registerPortalRoot(listContainerRef.current, DROPDOWN_PORTAL_CONTAINER_NAME);
298
+ }
299
+
300
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Wrapper, _extends({
301
+ className: wrapperClasses,
302
+ hasIcon: !!IconComponent,
303
+ block: block,
304
+ theme: theme,
305
+ disabled: disabled,
306
+ contrast: contrast,
307
+ sx: sxProp,
308
+ ref: containerRef
309
+ }, wrapperProps), /*#__PURE__*/React.createElement(InputWrapper, {
310
+ "data-autocompleteSuggestion": autocompleteSuggestion
311
+ }, /*#__PURE__*/React.createElement(Input, _extends({
312
+ ref: combinedInputRef,
313
+ disabled: disabled,
314
+ onFocus: handleInputFocus,
315
+ onKeyPress: onInputKeyPress,
316
+ onKeyDown: handleInputKeyDown,
317
+ onChange: handleInputChange,
318
+ type: "text",
319
+ value: inputVal
320
+ }, inputProps))), tokens !== null && tokens !== void 0 && tokens.length && TokenComponent ? tokens.map((token, i) => /*#__PURE__*/React.createElement(TokenComponent, {
321
+ onFocus: handleTokenFocus(i),
322
+ onBlur: handleTokenBlur,
323
+ onKeyUp: handleTokenKeyUp(token.id),
324
+ text: token.text || '' // TODO: just make token.text required
325
+ ,
326
+ isSelected: selectedTokenIdx === i,
327
+ handleRemove: () => {
328
+ handleTokenRemove(token.id);
329
+ },
330
+ variant: "xl",
331
+ fillColor: token.labelColor ? token.labelColor : undefined,
332
+ tabIndex: 0
333
+ })) : null), /*#__PURE__*/React.createElement("div", {
334
+ ref: listContainerRef
335
+ }, showMenu && emptyStateText ? /*#__PURE__*/React.createElement(Overlay, {
336
+ returnFocusRef: combinedInputRef,
337
+ portalContainerName: DROPDOWN_PORTAL_CONTAINER_NAME,
338
+ preventFocusOnOpen: true,
339
+ onClickOutside: closeOptionList,
340
+ onEscape: closeOptionList,
341
+ ref: floatingElementRef,
342
+ top: position === null || position === void 0 ? void 0 : position.top,
343
+ left: position === null || position === void 0 ? void 0 : position.left
344
+ }, loading ? /*#__PURE__*/React.createElement(Box, {
345
+ p: 3,
346
+ display: "flex",
347
+ justifyContent: "center"
348
+ }, /*#__PURE__*/React.createElement(Spinner, null)) : /*#__PURE__*/React.createElement(React.Fragment, null, itemsToRender.length ? /*#__PURE__*/React.createElement(ActionList, {
349
+ selectionVariant: "multiple",
350
+ items: itemsToRender,
351
+ role: "listbox"
352
+ }) : /*#__PURE__*/React.createElement(Box, {
353
+ p: 3
354
+ }, emptyStateText))) : null));
355
+ });
356
+ TextInputWithTokens.defaultProps = {
357
+ tokenComponent: Token,
358
+ emptyStateText: 'No selectable options'
359
+ };
360
+ TextInputWithTokens.displayName = 'TextInputWithTokens';
361
+ export default TextInputWithTokens;
@@ -374,6 +374,7 @@ declare const _default: string & import("styled-components").StyledComponentBase
374
374
  onAnimationIterationCapture?: React.AnimationEventHandler<HTMLDivElement> | undefined;
375
375
  onTransitionEnd?: React.TransitionEventHandler<HTMLDivElement> | undefined;
376
376
  onTransitionEndCapture?: React.TransitionEventHandler<HTMLDivElement> | undefined;
377
+ css?: import("@emotion/core").InterpolationWithTheme<any>;
377
378
  bg?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
378
379
  m?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
379
380
  mt?: import("styled-system").ResponsiveValue<string | number | symbol, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;