@primer/components 0.0.0-20219815255 → 0.0.0-20219835928

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 (78) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/browser.esm.js +252 -256
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +331 -335
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -1
  7. package/lib/AnchoredOverlay/AnchoredOverlay.js +11 -3
  8. package/lib/Autocomplete/Autocomplete.d.ts +40 -0
  9. package/lib/Autocomplete/Autocomplete.js +68 -0
  10. package/lib/Autocomplete/AutocompleteContext.d.ts +17 -0
  11. package/lib/Autocomplete/AutocompleteContext.js +11 -0
  12. package/lib/Autocomplete/AutocompleteInput.d.ts +9 -0
  13. package/lib/Autocomplete/AutocompleteInput.js +150 -0
  14. package/lib/Autocomplete/AutocompleteMenu.d.ts +71 -0
  15. package/lib/Autocomplete/AutocompleteMenu.js +223 -0
  16. package/lib/Autocomplete/AutocompleteOverlay.d.ts +17 -0
  17. package/lib/Autocomplete/AutocompleteOverlay.js +69 -0
  18. package/lib/Autocomplete/index.d.ts +2 -0
  19. package/lib/Autocomplete/index.js +15 -0
  20. package/lib/FilteredActionList/FilteredActionList.js +5 -31
  21. package/lib/Overlay.d.ts +2 -1
  22. package/lib/Overlay.js +10 -5
  23. package/lib/SelectMenu/SelectMenu.d.ts +3 -8
  24. package/lib/TextInput.d.ts +3 -13
  25. package/lib/TextInput.js +3 -43
  26. package/lib/TextInputWithTokens.d.ts +11 -14
  27. package/lib/TextInputWithTokens.js +119 -119
  28. package/lib/_TextInputWrapper.d.ts +10 -0
  29. package/lib/_TextInputWrapper.js +51 -0
  30. package/lib/hooks/useOpenAndCloseFocus.d.ts +2 -1
  31. package/lib/hooks/useOpenAndCloseFocus.js +7 -2
  32. package/lib/hooks/useOverlay.d.ts +2 -1
  33. package/lib/hooks/useOverlay.js +4 -2
  34. package/lib/index.d.ts +1 -0
  35. package/lib/index.js +8 -0
  36. package/lib/utils/scrollIntoViewingArea.d.ts +1 -0
  37. package/lib/utils/scrollIntoViewingArea.js +39 -0
  38. package/lib/utils/types/MandateProps.d.ts +3 -0
  39. package/lib/utils/types/MandateProps.js +1 -0
  40. package/lib/utils/types/index.d.ts +1 -0
  41. package/lib/utils/types/index.js +13 -0
  42. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -1
  43. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +11 -3
  44. package/lib-esm/Autocomplete/Autocomplete.d.ts +40 -0
  45. package/lib-esm/Autocomplete/Autocomplete.js +47 -0
  46. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +17 -0
  47. package/lib-esm/Autocomplete/AutocompleteContext.js +2 -0
  48. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +9 -0
  49. package/lib-esm/Autocomplete/AutocompleteInput.js +131 -0
  50. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +71 -0
  51. package/lib-esm/Autocomplete/AutocompleteMenu.js +204 -0
  52. package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +17 -0
  53. package/lib-esm/Autocomplete/AutocompleteOverlay.js +51 -0
  54. package/lib-esm/Autocomplete/index.d.ts +2 -0
  55. package/lib-esm/Autocomplete/index.js +1 -0
  56. package/lib-esm/FilteredActionList/FilteredActionList.js +3 -31
  57. package/lib-esm/Overlay.d.ts +2 -1
  58. package/lib-esm/Overlay.js +8 -5
  59. package/lib-esm/SelectMenu/SelectMenu.d.ts +3 -8
  60. package/lib-esm/TextInput.d.ts +3 -13
  61. package/lib-esm/TextInput.js +3 -34
  62. package/lib-esm/TextInputWithTokens.d.ts +11 -14
  63. package/lib-esm/TextInputWithTokens.js +117 -115
  64. package/lib-esm/_TextInputWrapper.d.ts +10 -0
  65. package/lib-esm/_TextInputWrapper.js +31 -0
  66. package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +2 -1
  67. package/lib-esm/hooks/useOpenAndCloseFocus.js +7 -2
  68. package/lib-esm/hooks/useOverlay.d.ts +2 -1
  69. package/lib-esm/hooks/useOverlay.js +4 -2
  70. package/lib-esm/index.d.ts +1 -0
  71. package/lib-esm/index.js +1 -0
  72. package/lib-esm/utils/scrollIntoViewingArea.d.ts +1 -0
  73. package/lib-esm/utils/scrollIntoViewingArea.js +30 -0
  74. package/lib-esm/utils/types/MandateProps.d.ts +3 -0
  75. package/lib-esm/utils/types/MandateProps.js +1 -0
  76. package/lib-esm/utils/types/index.d.ts +1 -0
  77. package/lib-esm/utils/types/index.js +2 -1
  78. package/package.json +1 -1
@@ -9,8 +9,6 @@ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _props = require("@styled-system/props");
11
11
 
12
- var _styledComponents = _interopRequireDefault(require("styled-components"));
13
-
14
12
  var _focusZone = require("./behaviors/focusZone");
15
13
 
16
14
  var _useCombinedRefs = require("./hooks/useCombinedRefs");
@@ -19,12 +17,14 @@ var _useFocusZone = require("./hooks/useFocusZone");
19
17
 
20
18
  var _Token = _interopRequireDefault(require("./Token/Token"));
21
19
 
22
- var _TextInput = _interopRequireDefault(require("./TextInput"));
23
-
24
20
  var _hooks = require("./hooks");
25
21
 
26
22
  var _UnstyledTextInput = _interopRequireDefault(require("./_UnstyledTextInput"));
27
23
 
24
+ var _TextInputWrapper = _interopRequireDefault(require("./_TextInputWrapper"));
25
+
26
+ var _Box = _interopRequireDefault(require("./Box"));
27
+
28
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
29
 
30
30
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -33,30 +33,80 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
33
33
 
34
34
  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); }
35
35
 
36
- const InputWrapper = _styledComponents.default.div.withConfig({
37
- displayName: "TextInputWithTokens__InputWrapper",
38
- componentId: "sc-8z94t5-0"
39
- })(["order:1;flex-grow:1;"]); // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
-
41
-
42
- // The inner contents of `TextInputWithTokens` are separated so they may be passed to the `as`
43
- // prop of the `TextInput` component
36
+ // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
44
37
  function TextInputWithTokensInnerComponent({
38
+ icon: IconComponent,
39
+ contrast,
40
+ className,
41
+ block,
42
+ disabled,
43
+ theme,
44
+ sx: sxProp,
45
45
  tokens,
46
46
  onTokenRemove,
47
47
  tokenComponent: TokenComponent,
48
+ preventTokenWrapping,
48
49
  size,
49
50
  hideTokenRemoveButtons,
50
- selectedTokenIndex,
51
- setSelectedTokenIndex,
51
+ maxHeight,
52
+ width: widthProp,
53
+ minWidth: minWidthProp,
54
+ maxWidth: maxWidthProp,
55
+ variant: variantProp,
52
56
  ...rest
53
57
  }, externalRef) {
54
- const ref = (0, _hooks.useProvidedRefOrCreate)(externalRef);
55
58
  const {
56
59
  onFocus,
57
60
  onKeyDown,
58
61
  ...inputPropsRest
59
62
  } = (0, _props.omit)(rest);
63
+ const ref = (0, _hooks.useProvidedRefOrCreate)(externalRef);
64
+ const localInputRef = (0, _react.useRef)(null);
65
+ const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(localInputRef, ref);
66
+ const [selectedTokenIndex, setSelectedTokenIndex] = (0, _react.useState)();
67
+ const {
68
+ containerRef
69
+ } = (0, _useFocusZone.useFocusZone)({
70
+ focusOutBehavior: 'wrap',
71
+ bindKeys: _focusZone.FocusKeys.ArrowHorizontal | _focusZone.FocusKeys.HomeAndEnd,
72
+ focusableElementFilter: element => {
73
+ return !element.getAttributeNames().includes('aria-hidden');
74
+ },
75
+ getNextFocusable: direction => {
76
+ var _containerRef$current;
77
+
78
+ if (!selectedTokenIndex && selectedTokenIndex !== 0) {
79
+ return undefined;
80
+ }
81
+
82
+ let nextIndex = selectedTokenIndex + 1; // "+ 1" accounts for the first element: the text input
83
+
84
+ if (direction === 'next') {
85
+ nextIndex += 1;
86
+ }
87
+
88
+ if (direction === 'previous') {
89
+ nextIndex -= 1;
90
+ }
91
+
92
+ if (nextIndex > tokens.length || nextIndex < 1) {
93
+ return combinedInputRef.current || undefined;
94
+ }
95
+
96
+ return (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
97
+ }
98
+ }, [selectedTokenIndex]);
99
+
100
+ const handleTokenRemove = tokenId => {
101
+ onTokenRemove(tokenId);
102
+
103
+ if (selectedTokenIndex) {
104
+ var _containerRef$current2;
105
+
106
+ const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
107
+ nextElementToFocus.focus();
108
+ }
109
+ };
60
110
 
61
111
  const handleTokenFocus = tokenIndex => () => {
62
112
  setSelectedTokenIndex(tokenIndex);
@@ -66,24 +116,24 @@ function TextInputWithTokensInnerComponent({
66
116
  setSelectedTokenIndex(undefined);
67
117
  };
68
118
 
69
- const handleTokenKeyUp = event => {
70
- if (event.key === 'Escape') {
119
+ const handleTokenKeyUp = e => {
120
+ if (e.key === 'Escape') {
71
121
  var _ref$current;
72
122
 
73
123
  (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
74
124
  }
75
125
  };
76
126
 
77
- const handleInputFocus = event => {
78
- onFocus && onFocus(event);
127
+ const handleInputFocus = e => {
128
+ onFocus && onFocus(e);
79
129
  setSelectedTokenIndex(undefined);
80
130
  };
81
131
 
82
- const handleInputKeyDown = event => {
132
+ const handleInputKeyDown = e => {
83
133
  var _ref$current2;
84
134
 
85
135
  if (onKeyDown) {
86
- onKeyDown(event);
136
+ onKeyDown(e);
87
137
  }
88
138
 
89
139
  if ((_ref$current2 = ref.current) !== null && _ref$current2 !== void 0 && _ref$current2.value) {
@@ -92,8 +142,8 @@ function TextInputWithTokensInnerComponent({
92
142
 
93
143
  const lastToken = tokens[tokens.length - 1];
94
144
 
95
- if (event.key === 'Backspace' && lastToken) {
96
- onTokenRemove(lastToken.id);
145
+ if (e.key === 'Backspace' && lastToken) {
146
+ handleTokenRemove(lastToken.id);
97
147
 
98
148
  if (ref.current) {
99
149
  // TODO: eliminate the first hack by making changes to the Autocomplete component
@@ -114,10 +164,48 @@ function TextInputWithTokensInnerComponent({
114
164
  }
115
165
  };
116
166
 
117
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(InputWrapper, {
118
- key: "inputWrapper"
119
- }, /*#__PURE__*/_react.default.createElement(_UnstyledTextInput.default, _extends({
120
- ref: ref,
167
+ return /*#__PURE__*/_react.default.createElement(_TextInputWrapper.default, {
168
+ block: block,
169
+ className: className,
170
+ contrast: contrast,
171
+ disabled: disabled,
172
+ hasIcon: !!IconComponent,
173
+ theme: theme,
174
+ width: widthProp,
175
+ minWidth: minWidthProp,
176
+ maxWidth: maxWidthProp,
177
+ variant: variantProp,
178
+ ref: containerRef,
179
+ sx: {
180
+ alignItems: 'center',
181
+ flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
182
+ gap: '0.25rem',
183
+ '> *': {
184
+ flexShrink: 0
185
+ },
186
+ ...(block ? {
187
+ display: 'flex',
188
+ width: '100%'
189
+ } : {}),
190
+ ...(maxHeight ? {
191
+ maxHeight,
192
+ overflow: 'auto'
193
+ } : {}),
194
+ ...(preventTokenWrapping ? {
195
+ overflow: 'auto'
196
+ } : {}),
197
+ ...sxProp
198
+ }
199
+ }, /*#__PURE__*/_react.default.createElement(_Box.default, {
200
+ sx: {
201
+ order: 1,
202
+ flexGrow: 1
203
+ }
204
+ }, IconComponent && /*#__PURE__*/_react.default.createElement(IconComponent, {
205
+ className: "TextInput-icon"
206
+ }), /*#__PURE__*/_react.default.createElement(_UnstyledTextInput.default, _extends({
207
+ ref: combinedInputRef,
208
+ disabled: disabled,
121
209
  onFocus: handleInputFocus,
122
210
  onKeyDown: handleInputKeyDown,
123
211
  type: "text",
@@ -134,109 +222,21 @@ function TextInputWithTokensInnerComponent({
134
222
  onKeyUp: handleTokenKeyUp,
135
223
  isSelected: selectedTokenIndex === i,
136
224
  onRemove: () => {
137
- onTokenRemove(id);
225
+ handleTokenRemove(id);
138
226
  },
139
227
  hideRemoveButton: hideTokenRemoveButtons,
140
228
  size: size,
141
229
  tabIndex: 0
142
230
  }, tokenRest))) : null);
143
- } // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
144
-
145
-
146
- const TextInputWithTokensInnerComponentWithRef = /*#__PURE__*/_react.default.forwardRef(TextInputWithTokensInnerComponent);
147
-
148
- function TextInputWithTokensComponent({
149
- tokens,
150
- onTokenRemove,
151
- sx: sxProp,
152
- ...props
153
- }, ref) {
154
- const localInputRef = (0, _react.useRef)(null);
155
- const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(localInputRef, ref);
156
- const [selectedTokenIndex, setSelectedTokenIndex] = (0, _react.useState)();
157
- const {
158
- containerRef
159
- } = (0, _useFocusZone.useFocusZone)({
160
- focusOutBehavior: 'wrap',
161
- bindKeys: _focusZone.FocusKeys.ArrowHorizontal | _focusZone.FocusKeys.HomeAndEnd,
162
- focusableElementFilter: element => {
163
- return !element.getAttributeNames().includes('aria-hidden');
164
- },
165
- getNextFocusable: direction => {
166
- var _containerRef$current;
167
-
168
- if (!selectedTokenIndex && selectedTokenIndex !== 0) {
169
- return undefined;
170
- }
171
-
172
- let nextIndex = selectedTokenIndex + 1; // "+ 1" accounts for the first element: the text input
173
-
174
- if (direction === 'next') {
175
- nextIndex += 1;
176
- }
177
-
178
- if (direction === 'previous') {
179
- nextIndex -= 1;
180
- }
181
-
182
- if (nextIndex > tokens.length || nextIndex < 1) {
183
- return combinedInputRef.current || undefined;
184
- }
185
-
186
- return (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
187
- }
188
- }, [selectedTokenIndex]);
189
-
190
- const handleTokenRemove = tokenId => {
191
- onTokenRemove(tokenId);
192
-
193
- if (selectedTokenIndex) {
194
- var _containerRef$current2;
195
-
196
- const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
197
- nextElementToFocus.focus();
198
- }
199
- };
200
-
201
- return /*#__PURE__*/_react.default.createElement(_TextInput.default, _extends({
202
- ref: combinedInputRef,
203
- wrapperRef: containerRef,
204
- as: TextInputWithTokensInnerComponentWithRef,
205
- selectedTokenIndex: selectedTokenIndex,
206
- setSelectedTokenIndex: setSelectedTokenIndex,
207
- tokens: tokens,
208
- onTokenRemove: handleTokenRemove,
209
- sx: {
210
- alignItems: 'center',
211
- flexWrap: props.preventTokenWrapping ? 'nowrap' : 'wrap',
212
- gap: '0.25rem',
213
- '> *': {
214
- flexShrink: 0
215
- },
216
- ...(props.block ? {
217
- display: 'flex',
218
- width: '100%'
219
- } : {}),
220
- ...(props.maxHeight ? {
221
- maxHeight: props.maxHeight,
222
- overflow: 'auto'
223
- } : {}),
224
- ...(props.preventTokenWrapping ? {
225
- overflow: 'auto'
226
- } : {}),
227
- ...sxProp
228
- }
229
- }, props));
230
231
  }
231
232
 
232
- TextInputWithTokensComponent.displayName = "TextInputWithTokensComponent";
233
+ TextInputWithTokensInnerComponent.displayName = "TextInputWithTokensInnerComponent";
233
234
 
234
- // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
235
- const TextInputWithTokens = /*#__PURE__*/_react.default.forwardRef(TextInputWithTokensComponent);
235
+ const TextInputWithTokens = /*#__PURE__*/_react.default.forwardRef(TextInputWithTokensInnerComponent);
236
236
 
237
237
  TextInputWithTokens.defaultProps = {
238
238
  tokenComponent: _Token.default,
239
- size: 'xlarge',
239
+ size: 'extralarge',
240
240
  hideTokenRemoveButtons: false
241
241
  };
242
242
  TextInputWithTokens.displayName = 'TextInputWithTokens';
@@ -0,0 +1,10 @@
1
+ import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
2
+ import { SxProp } from './sx';
3
+ declare const TextInputWrapper: import("styled-components").StyledComponent<"span", any, {
4
+ disabled?: boolean | undefined;
5
+ hasIcon?: boolean | undefined;
6
+ block?: boolean | undefined;
7
+ contrast?: boolean | undefined;
8
+ variant?: "large" | "small" | undefined;
9
+ } & 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>;
10
+ export default TextInputWrapper;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
9
+
10
+ var _styledSystem = require("styled-system");
11
+
12
+ var _constants = require("./constants");
13
+
14
+ var _sx = _interopRequireDefault(require("./sx"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
22
+ const sizeVariants = (0, _styledSystem.variant)({
23
+ variants: {
24
+ small: {
25
+ minHeight: '28px',
26
+ px: 2,
27
+ py: '3px',
28
+ fontSize: 0,
29
+ lineHeight: '20px'
30
+ },
31
+ large: {
32
+ px: 2,
33
+ py: '10px',
34
+ fontSize: 3
35
+ }
36
+ }
37
+ });
38
+
39
+ const TextInputWrapper = _styledComponents.default.span.withConfig({
40
+ displayName: "_TextInputWrapper__TextInputWrapper",
41
+ componentId: "sc-5vfcis-0"
42
+ })(["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:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('colors.fg.default'), (0, _constants.get)('colors.border.default'), (0, _constants.get)('radii.2'), (0, _constants.get)('shadows.primer.shadow.inset'), props => {
43
+ if (props.hasIcon) {
44
+ return (0, _styledComponents.css)(["padding:0;"]);
45
+ } else {
46
+ return (0, _styledComponents.css)(["padding:6px 12px;"]);
47
+ }
48
+ }, (0, _constants.get)('colors.fg.muted'), (0, _constants.get)('space.2'), (0, _constants.get)('colors.accent.emphasis'), (0, _constants.get)('shadows.primer.shadow.focus'), props => props.contrast && (0, _styledComponents.css)(["background-color:", ";"], (0, _constants.get)('colors.canvas.inset')), props => props.disabled && (0, _styledComponents.css)(["color:", ";background-color:", ";border-color:", ";"], (0, _constants.get)('colors.fg.muted'), (0, _constants.get)('colors.input.disabledBg'), (0, _constants.get)('colors.border.default')), props => props.block && (0, _styledComponents.css)(["display:block;width:100%;"]), (0, _constants.get)('breakpoints.1'), (0, _constants.get)('fontSizes.1'), _styledSystem.width, _styledSystem.minWidth, _styledSystem.maxWidth, sizeVariants, _sx.default);
49
+
50
+ var _default = TextInputWrapper;
51
+ exports.default = _default;
@@ -3,5 +3,6 @@ export declare type UseOpenAndCloseFocusSettings = {
3
3
  initialFocusRef?: React.RefObject<HTMLElement>;
4
4
  containerRef: React.RefObject<HTMLElement>;
5
5
  returnFocusRef: React.RefObject<HTMLElement>;
6
+ preventFocusOnOpen?: boolean;
6
7
  };
7
- export declare function useOpenAndCloseFocus({ initialFocusRef, returnFocusRef, containerRef }: UseOpenAndCloseFocusSettings): void;
8
+ export declare function useOpenAndCloseFocus({ initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen }: UseOpenAndCloseFocusSettings): void;
@@ -12,9 +12,14 @@ var _iterateFocusableElements = require("../utils/iterateFocusableElements");
12
12
  function useOpenAndCloseFocus({
13
13
  initialFocusRef,
14
14
  returnFocusRef,
15
- containerRef
15
+ containerRef,
16
+ preventFocusOnOpen
16
17
  }) {
17
18
  (0, _react.useEffect)(() => {
19
+ if (preventFocusOnOpen) {
20
+ return;
21
+ }
22
+
18
23
  const returnRef = returnFocusRef.current;
19
24
 
20
25
  if (initialFocusRef && initialFocusRef.current) {
@@ -27,5 +32,5 @@ function useOpenAndCloseFocus({
27
32
  return function () {
28
33
  returnRef === null || returnRef === void 0 ? void 0 : returnRef.focus();
29
34
  };
30
- }, [initialFocusRef, returnFocusRef, containerRef]);
35
+ }, [initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen]);
31
36
  }
@@ -7,8 +7,9 @@ export declare type UseOverlaySettings = {
7
7
  onEscape: (e: KeyboardEvent) => void;
8
8
  onClickOutside: (e: TouchOrMouseEvent) => void;
9
9
  overlayRef?: React.RefObject<HTMLDivElement>;
10
+ preventFocusOnOpen?: boolean;
10
11
  };
11
12
  export declare type OverlayReturnProps = {
12
13
  ref: React.RefObject<HTMLDivElement>;
13
14
  };
14
- export declare const useOverlay: ({ overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside }: UseOverlaySettings) => OverlayReturnProps;
15
+ export declare const useOverlay: ({ overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside, preventFocusOnOpen }: UseOverlaySettings) => OverlayReturnProps;
@@ -19,13 +19,15 @@ const useOverlay = ({
19
19
  initialFocusRef,
20
20
  onEscape,
21
21
  ignoreClickRefs,
22
- onClickOutside
22
+ onClickOutside,
23
+ preventFocusOnOpen
23
24
  }) => {
24
25
  const overlayRef = (0, _useProvidedRefOrCreate.useProvidedRefOrCreate)(_overlayRef);
25
26
  (0, _useOpenAndCloseFocus.useOpenAndCloseFocus)({
26
27
  containerRef: overlayRef,
27
28
  returnFocusRef,
28
- initialFocusRef
29
+ initialFocusRef,
30
+ preventFocusOnOpen
29
31
  });
30
32
  (0, _useOnOutsideClick.useOnOutsideClick)({
31
33
  containerRef: overlayRef,
package/lib/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export { useConfirm } from './Dialog/ConfirmationDialog';
24
24
  export { ActionList } from './ActionList';
25
25
  export { ActionMenu } from './ActionMenu';
26
26
  export type { ActionMenuProps } from './ActionMenu';
27
+ export { default as Autocomplete } from './Autocomplete';
27
28
  export { default as Avatar } from './Avatar';
28
29
  export type { AvatarProps } from './Avatar';
29
30
  export { default as AvatarPair } from './AvatarPair';
package/lib/index.js CHANGED
@@ -153,6 +153,12 @@ Object.defineProperty(exports, "ActionMenu", {
153
153
  return _ActionMenu.ActionMenu;
154
154
  }
155
155
  });
156
+ Object.defineProperty(exports, "Autocomplete", {
157
+ enumerable: true,
158
+ get: function () {
159
+ return _Autocomplete.default;
160
+ }
161
+ });
156
162
  Object.defineProperty(exports, "Avatar", {
157
163
  enumerable: true,
158
164
  get: function () {
@@ -532,6 +538,8 @@ var _ActionList = require("./ActionList");
532
538
 
533
539
  var _ActionMenu = require("./ActionMenu");
534
540
 
541
+ var _Autocomplete = _interopRequireDefault(require("./Autocomplete"));
542
+
535
543
  var _Avatar = _interopRequireDefault(require("./Avatar"));
536
544
 
537
545
  var _AvatarPair = _interopRequireDefault(require("./AvatarPair"));
@@ -0,0 +1 @@
1
+ export declare const scrollIntoViewingArea: (child: HTMLElement, container: HTMLElement, direction?: 'horizontal' | 'vertical', startMargin?: number, endMargin?: number, behavior?: ScrollBehavior) => void;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.scrollIntoViewingArea = void 0;
7
+
8
+ const scrollIntoViewingArea = (child, container, direction = 'vertical', startMargin = 8, endMargin = 0, behavior = 'smooth') => {
9
+ const startSide = direction === 'vertical' ? 'top' : 'left';
10
+ const endSide = direction === 'vertical' ? 'bottom' : 'right';
11
+ const scrollSide = direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
12
+ const {
13
+ [startSide]: childStart,
14
+ [endSide]: childEnd
15
+ } = child.getBoundingClientRect();
16
+ const {
17
+ [startSide]: containerStart,
18
+ [endSide]: containerEnd
19
+ } = container.getBoundingClientRect();
20
+ const isChildStartAboveViewingArea = childStart < containerStart + endMargin;
21
+ const isChildBottomBelowViewingArea = childEnd > containerEnd - startMargin;
22
+
23
+ if (isChildStartAboveViewingArea) {
24
+ const scrollHeightToChildStart = childStart - containerStart + container[scrollSide];
25
+ container.scrollTo({
26
+ behavior,
27
+ [startSide]: scrollHeightToChildStart - endMargin
28
+ });
29
+ } else if (isChildBottomBelowViewingArea) {
30
+ const scrollHeightToChildBottom = childEnd - containerEnd + container[scrollSide];
31
+ container.scrollTo({
32
+ behavior,
33
+ [startSide]: scrollHeightToChildBottom + startMargin
34
+ });
35
+ } // either completely in view or outside viewing area on both ends, don't scroll
36
+
37
+ };
38
+
39
+ exports.scrollIntoViewingArea = scrollIntoViewingArea;
@@ -0,0 +1,3 @@
1
+ export declare type MandateProps<T extends unknown, K extends keyof T> = Omit<T, K> & {
2
+ [MK in K]-?: NonNullable<T[MK]>;
3
+ };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -2,3 +2,4 @@ export * from './AriaRole';
2
2
  export * from './ComponentProps';
3
3
  export * from './Flatten';
4
4
  export * from './Merge';
5
+ export * from './MandateProps';
@@ -54,4 +54,17 @@ Object.keys(_Merge).forEach(function (key) {
54
54
  return _Merge[key];
55
55
  }
56
56
  });
57
+ });
58
+
59
+ var _MandateProps = require("./MandateProps");
60
+
61
+ Object.keys(_MandateProps).forEach(function (key) {
62
+ if (key === "default" || key === "__esModule") return;
63
+ if (key in exports && exports[key] === _MandateProps[key]) return;
64
+ Object.defineProperty(exports, key, {
65
+ enumerable: true,
66
+ get: function () {
67
+ return _MandateProps[key];
68
+ }
69
+ });
57
70
  });
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { OverlayProps } from '../Overlay';
3
3
  import { FocusTrapHookSettings } from '../hooks/useFocusTrap';
4
4
  import { FocusZoneHookSettings } from '../hooks/useFocusZone';
5
+ import { PositionSettings } from '../behaviors/anchoredPosition';
5
6
  interface AnchoredOverlayPropsWithAnchor {
6
7
  /**
7
8
  * A custom function component used to render the anchor element.
@@ -52,7 +53,7 @@ interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width'
52
53
  */
53
54
  focusZoneSettings?: Partial<FocusZoneHookSettings>;
54
55
  }
55
- export declare type AnchoredOverlayProps = AnchoredOverlayBaseProps & (AnchoredOverlayPropsWithAnchor | AnchoredOverlayPropsWithoutAnchor);
56
+ export declare type AnchoredOverlayProps = AnchoredOverlayBaseProps & (AnchoredOverlayPropsWithAnchor | AnchoredOverlayPropsWithoutAnchor) & Partial<Pick<PositionSettings, 'align' | 'side'>>;
56
57
  /**
57
58
  * An `AnchoredOverlay` provides an anchor that will open a floating overlay positioned relative to the anchor.
58
59
  * The overlay can be opened and navigated using keyboard or mouse.
@@ -22,7 +22,9 @@ export const AnchoredOverlay = ({
22
22
  width,
23
23
  overlayProps,
24
24
  focusTrapSettings,
25
- focusZoneSettings
25
+ focusZoneSettings,
26
+ side,
27
+ align
26
28
  }) => {
27
29
  const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
28
30
  const [overlayRef, updateOverlayRef] = useRenderForcingRef();
@@ -52,7 +54,9 @@ export const AnchoredOverlay = ({
52
54
  position
53
55
  } = useAnchoredPosition({
54
56
  anchorElementRef: anchorRef,
55
- floatingElementRef: overlayRef
57
+ floatingElementRef: overlayRef,
58
+ side,
59
+ align
56
60
  }, [overlayRef.current]);
57
61
  useEffect(() => {
58
62
  // ensure overlay ref gets cleared when closed, so position can reset between closing/re-opening
@@ -93,4 +97,8 @@ export const AnchoredOverlay = ({
93
97
  anchorSide: position === null || position === void 0 ? void 0 : position.anchorSide
94
98
  }, overlayProps), children) : null);
95
99
  };
96
- AnchoredOverlay.displayName = 'AnchoredOverlay';
100
+ AnchoredOverlay.displayName = 'AnchoredOverlay';
101
+ AnchoredOverlay.defaultProps = {
102
+ side: 'outside-bottom',
103
+ align: 'start'
104
+ };
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import { ComponentProps } from '../utils/types';
3
+ import AutocompleteMenu from './AutocompleteMenu';
4
+ declare const Autocomplete: React.FC<{
5
+ id?: string;
6
+ }>;
7
+ export declare type AutocompleteProps = ComponentProps<typeof Autocomplete>;
8
+ export type { AutocompleteInputProps } from './AutocompleteInput';
9
+ export type { AutocompleteMenuProps } from './AutocompleteMenu';
10
+ export type { AutocompleteOverlayProps } from './AutocompleteOverlay';
11
+ declare const _default: React.FC<{
12
+ id?: string | undefined;
13
+ }> & {
14
+ AutocompleteContext: React.Context<{
15
+ activeDescendantRef?: React.MutableRefObject<HTMLElement | null> | undefined;
16
+ autocompleteSuggestion?: string | undefined;
17
+ id?: string | undefined;
18
+ inputRef?: React.MutableRefObject<HTMLInputElement | null> | undefined;
19
+ inputValue?: string | undefined;
20
+ isMenuDirectlyActivated?: boolean | undefined;
21
+ scrollContainerRef?: React.MutableRefObject<HTMLElement | null> | undefined;
22
+ selectedItemLength?: number | undefined;
23
+ setAutocompleteSuggestion?: React.Dispatch<React.SetStateAction<string>> | undefined;
24
+ setInputValue?: React.Dispatch<React.SetStateAction<string>> | undefined;
25
+ setIsMenuDirectlyActivated?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
26
+ setSelectedItemLength?: React.Dispatch<React.SetStateAction<number | undefined>> | undefined;
27
+ setShowMenu?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
28
+ showMenu?: boolean | undefined;
29
+ }>;
30
+ Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<"input", {
31
+ as?: React.ComponentType<any> | undefined;
32
+ }>;
33
+ Menu: typeof AutocompleteMenu;
34
+ Overlay: React.FC<{
35
+ menuAnchorRef?: React.RefObject<HTMLElement> | undefined;
36
+ overlayProps?: Partial<import("..").OverlayProps> | undefined;
37
+ children?: React.ReactNode;
38
+ } & Pick<React.AriaAttributes, "aria-labelledby">>;
39
+ };
40
+ export default _default;