@primer/components 0.0.0-2021816151443 → 0.0.0-2021816212749

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/browser.esm.js +667 -621
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +301 -255
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Item.js +3 -3
  7. package/lib/AnchoredOverlay/AnchoredOverlay.js +2 -2
  8. package/lib/Avatar.d.ts +4 -0
  9. package/lib/Dialog/Dialog.js +4 -4
  10. package/lib/FilteredActionList/FilteredActionList.js +3 -3
  11. package/lib/Overlay.d.ts +0 -1
  12. package/lib/Overlay.js +5 -10
  13. package/lib/SelectMenu/SelectMenu.d.ts +11 -327
  14. package/lib/SelectMenu/SelectMenuFilter.d.ts +1 -1
  15. package/lib/TextInput.d.ts +6 -6
  16. package/lib/TextInput.js +21 -16
  17. package/lib/Timeline.js +12 -15
  18. package/lib/hooks/useOverlay.d.ts +1 -2
  19. package/lib/hooks/useOverlay.js +6 -11
  20. package/lib/index.d.ts +1 -0
  21. package/lib/index.js +14 -0
  22. package/lib/theme-preval.js +1705 -1957
  23. package/lib/utils/ssr.d.ts +1 -0
  24. package/lib/utils/ssr.js +19 -0
  25. package/lib/utils/testing.d.ts +2431 -2929
  26. package/lib/utils/uniqueId.js +1 -0
  27. package/lib-esm/ActionList/Item.js +4 -4
  28. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -3
  29. package/lib-esm/Avatar.d.ts +4 -0
  30. package/lib-esm/Dialog/Dialog.js +3 -3
  31. package/lib-esm/FilteredActionList/FilteredActionList.js +3 -3
  32. package/lib-esm/Overlay.d.ts +0 -1
  33. package/lib-esm/Overlay.js +5 -8
  34. package/lib-esm/SelectMenu/SelectMenu.d.ts +11 -327
  35. package/lib-esm/SelectMenu/SelectMenuFilter.d.ts +1 -1
  36. package/lib-esm/TextInput.d.ts +6 -6
  37. package/lib-esm/TextInput.js +22 -16
  38. package/lib-esm/Timeline.js +8 -13
  39. package/lib-esm/hooks/useOverlay.d.ts +1 -2
  40. package/lib-esm/hooks/useOverlay.js +6 -11
  41. package/lib-esm/index.d.ts +1 -0
  42. package/lib-esm/index.js +2 -1
  43. package/lib-esm/theme-preval.js +1705 -1957
  44. package/lib-esm/utils/ssr.d.ts +1 -0
  45. package/lib-esm/utils/ssr.js +1 -0
  46. package/lib-esm/utils/testing.d.ts +2431 -2929
  47. package/lib-esm/utils/uniqueId.js +1 -0
  48. package/package.json +5 -7
  49. package/lib/Autocomplete/Autocomplete.d.ts +0 -8
  50. package/lib/Autocomplete/Autocomplete.js +0 -49
  51. package/lib/Autocomplete/AutocompleteContext.d.ts +0 -13
  52. package/lib/Autocomplete/AutocompleteContext.js +0 -11
  53. package/lib/Autocomplete/AutocompleteInput.d.ts +0 -7
  54. package/lib/Autocomplete/AutocompleteInput.js +0 -78
  55. package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -19
  56. package/lib/Autocomplete/AutocompleteMenu.js +0 -226
  57. package/lib/Badge/Badge.d.ts +0 -8
  58. package/lib/Badge/Badge.js +0 -59
  59. package/lib/Badge/BadgeState.d.ts +0 -13
  60. package/lib/Badge/BadgeState.js +0 -51
  61. package/lib/Badge/_badgeStyleUtils.d.ts +0 -3
  62. package/lib/Badge/_badgeStyleUtils.js +0 -39
  63. package/lib/TextInputTokens.d.ts +0 -32
  64. package/lib/TextInputTokens.js +0 -225
  65. package/lib/TextInputWithTokens.d.ts +0 -41
  66. package/lib/TextInputWithTokens.js +0 -396
  67. package/lib/Token/Token.d.ts +0 -7
  68. package/lib/Token/Token.js +0 -66
  69. package/lib/Token/TokenBase.d.ts +0 -16
  70. package/lib/Token/TokenBase.js +0 -76
  71. package/lib/Token/TokenLabel.d.ts +0 -8
  72. package/lib/Token/TokenLabel.js +0 -116
  73. package/lib/Token/TokenProfile.d.ts +0 -7
  74. package/lib/Token/TokenProfile.js +0 -45
  75. package/lib/Token/_AddTokenButton.d.ts +0 -3
  76. package/lib/Token/_AddTokenButton.js +0 -42
  77. package/lib/Token/_RemoveTokenButton.d.ts +0 -3
  78. package/lib/Token/_RemoveTokenButton.js +0 -42
  79. package/lib/Token/_tokenButtonUtils.d.ts +0 -8
  80. package/lib/Token/_tokenButtonUtils.js +0 -42
  81. package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -8
  82. package/lib-esm/Autocomplete/Autocomplete.js +0 -36
  83. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -13
  84. package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
  85. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -7
  86. package/lib-esm/Autocomplete/AutocompleteInput.js +0 -59
  87. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -19
  88. package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -203
  89. package/lib-esm/Badge/Badge.d.ts +0 -8
  90. package/lib-esm/Badge/Badge.js +0 -44
  91. package/lib-esm/Badge/BadgeState.d.ts +0 -13
  92. package/lib-esm/Badge/BadgeState.js +0 -40
  93. package/lib-esm/Badge/_badgeStyleUtils.d.ts +0 -3
  94. package/lib-esm/Badge/_badgeStyleUtils.js +0 -29
  95. package/lib-esm/TextInputTokens.d.ts +0 -32
  96. package/lib-esm/TextInputTokens.js +0 -195
  97. package/lib-esm/TextInputWithTokens.d.ts +0 -41
  98. package/lib-esm/TextInputWithTokens.js +0 -361
  99. package/lib-esm/Token/Token.d.ts +0 -7
  100. package/lib-esm/Token/Token.js +0 -46
  101. package/lib-esm/Token/TokenBase.d.ts +0 -16
  102. package/lib-esm/Token/TokenBase.js +0 -56
  103. package/lib-esm/Token/TokenLabel.d.ts +0 -8
  104. package/lib-esm/Token/TokenLabel.js +0 -100
  105. package/lib-esm/Token/TokenProfile.d.ts +0 -7
  106. package/lib-esm/Token/TokenProfile.js +0 -28
  107. package/lib-esm/Token/_AddTokenButton.d.ts +0 -3
  108. package/lib-esm/Token/_AddTokenButton.js +0 -27
  109. package/lib-esm/Token/_RemoveTokenButton.d.ts +0 -3
  110. package/lib-esm/Token/_RemoveTokenButton.js +0 -27
  111. package/lib-esm/Token/_tokenButtonUtils.d.ts +0 -8
  112. package/lib-esm/Token/_tokenButtonUtils.js +0 -26
@@ -1,32 +0,0 @@
1
- import React from 'react';
2
- import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
3
- import { SystemCommonProps } from './constants';
4
- import { SxProp } from './sx';
5
- import { ComponentProps } from './utils/types';
6
- import Token from './Token/Token';
7
- declare const Input: import("styled-components").StyledComponent<"input", any, {}, never>;
8
- declare const Wrapper: import("styled-components").StyledComponent<"span", any, {
9
- disabled?: boolean | undefined;
10
- hasIcon?: boolean | undefined;
11
- block?: boolean | undefined;
12
- contrast?: boolean | undefined;
13
- variant?: "large" | "small" | undefined;
14
- maxHeight?: React.CSSProperties['maxHeight'];
15
- } & 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>;
16
- interface Token {
17
- text?: string;
18
- id: string | number;
19
- }
20
- declare type TextInputWithTokensInternalProps = {
21
- as?: any;
22
- icon?: React.ComponentType<{
23
- className?: string;
24
- }>;
25
- tokens: Token[];
26
- onTokenRemove: (tokenId: string | number) => void;
27
- tokenComponent?: React.FunctionComponent<any>;
28
- maxHeight?: React.CSSProperties['maxHeight'];
29
- } & ComponentProps<typeof Wrapper> & ComponentProps<typeof Input>;
30
- 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" | "accept" | "capture" | "checked" | "enterKeyHint" | "maxLength" | "minLength" | "multiple" | "readOnly" | "required" | "as" | "variant" | "hasIcon" | "contrast" | "tokens" | "onTokenRemove" | "tokenComponent"> & React.RefAttributes<HTMLInputElement>>;
31
- export declare type TextInputWithTokensProps = ComponentProps<typeof TextInputWithTokens>;
32
- export default TextInputWithTokens;
@@ -1,195 +0,0 @@
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, 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 { FocusKeys } from './behaviors/focusZone';
9
- import { COMMON, get } from './constants';
10
- import { useCombinedRefs } from './hooks/useCombinedRefs';
11
- import { useFocusZone } from './hooks/useFocusZone';
12
- import sx from './sx';
13
- import Token from './Token/Token';
14
- const sizeVariants = variant({
15
- variants: {
16
- small: {
17
- minHeight: '28px',
18
- px: 2,
19
- py: '3px',
20
- fontSize: 0,
21
- lineHeight: '20px'
22
- },
23
- large: {
24
- px: 2,
25
- py: '10px',
26
- fontSize: 3
27
- }
28
- }
29
- });
30
- const Input = styled.input.withConfig({
31
- displayName: "TextInputTokens__Input",
32
- componentId: "sc-1k54xiz-0"
33
- })(["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;}"]);
34
- const InputWrapper = styled.div.withConfig({
35
- displayName: "TextInputTokens__InputWrapper",
36
- componentId: "sc-1k54xiz-1"
37
- })(["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);}"]);
38
- const Wrapper = styled.span.withConfig({
39
- displayName: "TextInputTokens__Wrapper",
40
- componentId: "sc-1k54xiz-2"
41
- })(["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 => {
42
- if (props.hasIcon) {
43
- return css(["padding:0;"]);
44
- } else {
45
- return css(["padding:6px 12px;"]);
46
- }
47
- }, props => {
48
- if (props.maxHeight) {
49
- return css(["max-height:", ";overflow:auto;"], props.maxHeight);
50
- }
51
- }, 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);
52
- // using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input
53
- const TextInputWithTokens = /*#__PURE__*/React.forwardRef(({
54
- icon: IconComponent,
55
- contrast,
56
- className,
57
- block,
58
- disabled,
59
- theme,
60
- sx: sxProp,
61
- tokens,
62
- onTokenRemove,
63
- tokenComponent: TokenComponent,
64
- ...rest
65
- }, ref) => {
66
- const localInputRef = useRef(null);
67
- const combinedInputRef = useCombinedRefs(localInputRef, ref); // this class is necessary to style FilterSearch, plz no touchy!
68
-
69
- const wrapperClasses = classnames(className, 'TextInput-wrapper');
70
- const wrapperProps = pick(rest);
71
- const {
72
- onChange,
73
- onFocus,
74
- onKeyDown,
75
- value,
76
- ...inputPropsRest
77
- } = omit(rest);
78
- const [selectedTokenIdx, setSelectedTokenIdx] = useState();
79
- const [inputVal, setInputVal] = useState(value);
80
- const [autocompleteSuggestion, setAutocompleteSuggestion] = useState('');
81
- const {
82
- containerRef
83
- } = useFocusZone({
84
- focusOutBehavior: 'wrap',
85
- bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
86
- focusableElementFilter: element => {
87
- return !(element instanceof HTMLButtonElement);
88
- }
89
- });
90
-
91
- const handleTokenRemove = tokenId => {
92
- onTokenRemove(tokenId);
93
- };
94
-
95
- const handleTokenFocus = tokenIdx => () => {
96
- setSelectedTokenIdx(tokenIdx);
97
- };
98
-
99
- const handleTokenBlur = () => {
100
- setSelectedTokenIdx(undefined);
101
- };
102
-
103
- const handleTokenKeyUp = tokenId => e => {
104
- if (e.key === 'Backspace') {
105
- handleTokenRemove(tokenId);
106
- }
107
-
108
- if (e.key === 'Escape') {
109
- var _combinedInputRef$cur;
110
-
111
- combinedInputRef === null || combinedInputRef === void 0 ? void 0 : (_combinedInputRef$cur = combinedInputRef.current) === null || _combinedInputRef$cur === void 0 ? void 0 : _combinedInputRef$cur.focus();
112
- }
113
- };
114
-
115
- const handleInputFocus = e => {
116
- if (onFocus) {
117
- onFocus(e);
118
- }
119
-
120
- setSelectedTokenIdx(undefined);
121
- };
122
-
123
- const handleInputChange = e => {
124
- if (onChange) {
125
- onChange(e);
126
- }
127
-
128
- setInputVal(e.currentTarget.value);
129
- };
130
-
131
- const handleInputKeyDown = e => {
132
- if (onKeyDown) {
133
- onKeyDown(e);
134
- }
135
-
136
- if (inputVal) {
137
- return;
138
- }
139
-
140
- const lastToken = tokens[tokens.length - 1];
141
-
142
- if (e.key === 'Backspace') {
143
- handleTokenRemove(lastToken.id); // HACK: adding an extra space so that when I backspace, it doesn't delete the last letter
144
-
145
- setInputVal(`${lastToken.text} ` || ' '); // TODO: use hooks or something to always trigger `onFilterChange` when `inputVal` is changed
146
- // onFilterChange(lastToken.text || '', e);
147
- // HACK: for some reason we need to wait a tick for `.select()` to work
148
-
149
- setTimeout(() => {
150
- var _combinedInputRef$cur2;
151
-
152
- combinedInputRef === null || combinedInputRef === void 0 ? void 0 : (_combinedInputRef$cur2 = combinedInputRef.current) === null || _combinedInputRef$cur2 === void 0 ? void 0 : _combinedInputRef$cur2.select();
153
- }, 1);
154
- }
155
- };
156
-
157
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Wrapper, _extends({
158
- className: wrapperClasses,
159
- hasIcon: !!IconComponent,
160
- block: block,
161
- theme: theme,
162
- disabled: disabled,
163
- contrast: contrast,
164
- sx: sxProp,
165
- ref: containerRef
166
- }, wrapperProps), /*#__PURE__*/React.createElement(InputWrapper, {
167
- "data-autocompleteSuggestion": autocompleteSuggestion
168
- }, /*#__PURE__*/React.createElement(Input, _extends({
169
- ref: combinedInputRef,
170
- disabled: disabled,
171
- onFocus: handleInputFocus,
172
- onKeyDown: handleInputKeyDown,
173
- onChange: handleInputChange,
174
- type: "text",
175
- value: inputVal
176
- }, inputPropsRest))), tokens !== null && tokens !== void 0 && tokens.length && TokenComponent ? tokens.map((token, i) => /*#__PURE__*/React.createElement(TokenComponent, {
177
- onFocus: handleTokenFocus(i),
178
- onBlur: handleTokenBlur,
179
- onKeyUp: handleTokenKeyUp(token.id),
180
- text: token.text || '' // TODO: just make token.text required
181
- ,
182
- isSelected: selectedTokenIdx === i,
183
- handleRemove: () => {
184
- handleTokenRemove(token.id);
185
- },
186
- variant: "xl",
187
- fillColor: token.labelColor ? token.labelColor : undefined,
188
- tabIndex: 0
189
- })) : null));
190
- });
191
- TextInputWithTokens.defaultProps = {
192
- tokenComponent: Token
193
- };
194
- TextInputWithTokens.displayName = 'TextInputWithTokens';
195
- export default TextInputWithTokens;
@@ -1,41 +0,0 @@
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" | "onFilterChange" | "tokens" | "onTokenRemove" | "tokenComponent" | "selectableItems" | "onItemSelect" | "emptyStateText" | "addNewTokenItem" | "onCloseOptionsList"> & React.RefAttributes<HTMLInputElement>>;
40
- export declare type TextInputWithTokensProps = ComponentProps<typeof TextInputWithTokens>;
41
- export default TextInputWithTokens;
@@ -1,361 +0,0 @@
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;