@primer/components 0.0.0-20219819465 → 0.0.0-202198201647

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 (66) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/browser.esm.js +254 -253
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +332 -331
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
  7. package/lib/AnchoredOverlay/AnchoredOverlay.js +3 -11
  8. package/lib/FilteredActionList/FilteredActionList.js +31 -5
  9. package/lib/Overlay.d.ts +1 -2
  10. package/lib/Overlay.js +5 -10
  11. package/lib/Token/TokenBase.d.ts +15 -1
  12. package/lib/hooks/useOpenAndCloseFocus.d.ts +1 -2
  13. package/lib/hooks/useOpenAndCloseFocus.js +2 -7
  14. package/lib/hooks/useOverlay.d.ts +1 -2
  15. package/lib/hooks/useOverlay.js +2 -4
  16. package/lib/index.d.ts +0 -1
  17. package/lib/index.js +0 -8
  18. package/lib/utils/types/index.d.ts +0 -1
  19. package/lib/utils/types/index.js +0 -13
  20. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
  21. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -11
  22. package/lib-esm/FilteredActionList/FilteredActionList.js +31 -3
  23. package/lib-esm/Overlay.d.ts +1 -2
  24. package/lib-esm/Overlay.js +5 -8
  25. package/lib-esm/Token/TokenBase.d.ts +15 -1
  26. package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +1 -2
  27. package/lib-esm/hooks/useOpenAndCloseFocus.js +2 -7
  28. package/lib-esm/hooks/useOverlay.d.ts +1 -2
  29. package/lib-esm/hooks/useOverlay.js +2 -4
  30. package/lib-esm/index.d.ts +0 -1
  31. package/lib-esm/index.js +0 -1
  32. package/lib-esm/utils/types/index.d.ts +0 -1
  33. package/lib-esm/utils/types/index.js +1 -2
  34. package/package.json +1 -1
  35. package/lib/Autocomplete/Autocomplete.d.ts +0 -40
  36. package/lib/Autocomplete/Autocomplete.js +0 -68
  37. package/lib/Autocomplete/AutocompleteContext.d.ts +0 -17
  38. package/lib/Autocomplete/AutocompleteContext.js +0 -11
  39. package/lib/Autocomplete/AutocompleteInput.d.ts +0 -9
  40. package/lib/Autocomplete/AutocompleteInput.js +0 -150
  41. package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -71
  42. package/lib/Autocomplete/AutocompleteMenu.js +0 -223
  43. package/lib/Autocomplete/AutocompleteOverlay.d.ts +0 -17
  44. package/lib/Autocomplete/AutocompleteOverlay.js +0 -74
  45. package/lib/Autocomplete/index.d.ts +0 -2
  46. package/lib/Autocomplete/index.js +0 -15
  47. package/lib/utils/scrollIntoViewingArea.d.ts +0 -1
  48. package/lib/utils/scrollIntoViewingArea.js +0 -39
  49. package/lib/utils/types/MandateProps.d.ts +0 -3
  50. package/lib/utils/types/MandateProps.js +0 -1
  51. package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -40
  52. package/lib-esm/Autocomplete/Autocomplete.js +0 -47
  53. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -17
  54. package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
  55. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -9
  56. package/lib-esm/Autocomplete/AutocompleteInput.js +0 -131
  57. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -71
  58. package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -204
  59. package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +0 -17
  60. package/lib-esm/Autocomplete/AutocompleteOverlay.js +0 -56
  61. package/lib-esm/Autocomplete/index.d.ts +0 -2
  62. package/lib-esm/Autocomplete/index.js +0 -1
  63. package/lib-esm/utils/scrollIntoViewingArea.d.ts +0 -1
  64. package/lib-esm/utils/scrollIntoViewingArea.js +0 -30
  65. package/lib-esm/utils/types/MandateProps.d.ts +0 -3
  66. package/lib-esm/utils/types/MandateProps.js +0 -1
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _hooks = require("../hooks");
11
-
12
- var _Overlay = _interopRequireDefault(require("../Overlay"));
13
-
14
- var _AutocompleteContext = require("./AutocompleteContext");
15
-
16
- var _useCombinedRefs = require("../hooks/useCombinedRefs");
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- 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); }
21
-
22
- 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; }
23
-
24
- 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); }
25
-
26
- // TODO: consider making 'aria-labelledby' required
27
- const AutocompleteOverlay = ({
28
- menuAnchorRef,
29
- overlayProps,
30
- children
31
- }) => {
32
- const {
33
- inputRef,
34
- scrollContainerRef,
35
- selectedItemLength,
36
- setShowMenu,
37
- showMenu = false
38
- } = (0, _react.useContext)(_AutocompleteContext.AutocompleteContext);
39
- const {
40
- floatingElementRef,
41
- position
42
- } = (0, _hooks.useAnchoredPosition)({
43
- side: 'outside-bottom',
44
- align: 'start',
45
- anchorElementRef: menuAnchorRef ? menuAnchorRef : inputRef
46
- }, [showMenu, selectedItemLength]);
47
- const combinedOverlayRef = (0, _useCombinedRefs.useCombinedRefs)(scrollContainerRef, floatingElementRef);
48
- const closeOptionList = (0, _react.useCallback)(() => {
49
- setShowMenu && setShowMenu(false);
50
- }, [setShowMenu]);
51
-
52
- if (typeof window === 'undefined') {
53
- return null;
54
- }
55
-
56
- return /*#__PURE__*/_react.default.createElement(_Overlay.default, _extends({
57
- returnFocusRef: inputRef,
58
- preventFocusOnOpen: true,
59
- onClickOutside: closeOptionList,
60
- onEscape: closeOptionList,
61
- ref: combinedOverlayRef,
62
- top: position === null || position === void 0 ? void 0 : position.top,
63
- left: position === null || position === void 0 ? void 0 : position.left,
64
- visibility: showMenu ? 'visible' : 'hidden',
65
- sx: {
66
- overflow: 'auto'
67
- }
68
- }, overlayProps), children);
69
- };
70
-
71
- AutocompleteOverlay.displayName = "AutocompleteOverlay";
72
- AutocompleteOverlay.displayName = 'AutocompleteOverlay';
73
- var _default = AutocompleteOverlay;
74
- exports.default = _default;
@@ -1,2 +0,0 @@
1
- export { default } from './Autocomplete';
2
- export type { AutocompleteMenuProps, AutocompleteInputProps, AutocompleteOverlayProps } from './Autocomplete';
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "default", {
7
- enumerable: true,
8
- get: function () {
9
- return _Autocomplete.default;
10
- }
11
- });
12
-
13
- var _Autocomplete = _interopRequireDefault(require("./Autocomplete"));
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -1 +0,0 @@
1
- export declare const scrollIntoViewingArea: (child: HTMLElement, container: HTMLElement, direction?: 'horizontal' | 'vertical', startMargin?: number, endMargin?: number, behavior?: ScrollBehavior) => void;
@@ -1,39 +0,0 @@
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;
@@ -1,3 +0,0 @@
1
- export declare type MandateProps<T extends unknown, K extends keyof T> = Omit<T, K> & {
2
- [MK in K]-?: NonNullable<T[MK]>;
3
- };
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,40 +0,0 @@
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;
@@ -1,47 +0,0 @@
1
- import React, { useRef, useState } from 'react';
2
- import { uniqueId } from '../utils/uniqueId';
3
- import { AutocompleteContext } from './AutocompleteContext';
4
- import AutocompleteInput from './AutocompleteInput';
5
- import AutocompleteMenu from './AutocompleteMenu';
6
- import AutocompleteOverlay from './AutocompleteOverlay';
7
-
8
- const Autocomplete = ({
9
- children,
10
- id: idProp
11
- }) => {
12
- const activeDescendantRef = useRef(null);
13
- const scrollContainerRef = useRef(null);
14
- const inputRef = useRef(null);
15
- const [inputValue, setInputValue] = useState('');
16
- const [showMenu, setShowMenu] = useState(false);
17
- const [autocompleteSuggestion, setAutocompleteSuggestion] = useState('');
18
- const [isMenuDirectlyActivated, setIsMenuDirectlyActivated] = useState(false);
19
- const [selectedItemLength, setSelectedItemLength] = useState();
20
- const id = idProp || uniqueId();
21
- return /*#__PURE__*/React.createElement(AutocompleteContext.Provider, {
22
- value: {
23
- activeDescendantRef,
24
- autocompleteSuggestion,
25
- id,
26
- inputRef,
27
- inputValue,
28
- isMenuDirectlyActivated,
29
- scrollContainerRef,
30
- selectedItemLength,
31
- setAutocompleteSuggestion,
32
- setInputValue,
33
- setIsMenuDirectlyActivated,
34
- setShowMenu,
35
- setSelectedItemLength,
36
- showMenu
37
- }
38
- }, children);
39
- };
40
-
41
- Autocomplete.displayName = "Autocomplete";
42
- export default Object.assign(Autocomplete, {
43
- AutocompleteContext,
44
- Input: AutocompleteInput,
45
- Menu: AutocompleteMenu,
46
- Overlay: AutocompleteOverlay
47
- });
@@ -1,17 +0,0 @@
1
- /// <reference types="react" />
2
- export declare const AutocompleteContext: import("react").Context<{
3
- activeDescendantRef?: import("react").MutableRefObject<HTMLElement | null> | undefined;
4
- autocompleteSuggestion?: string | undefined;
5
- id?: string | undefined;
6
- inputRef?: import("react").MutableRefObject<HTMLInputElement | null> | undefined;
7
- inputValue?: string | undefined;
8
- isMenuDirectlyActivated?: boolean | undefined;
9
- scrollContainerRef?: import("react").MutableRefObject<HTMLElement | null> | undefined;
10
- selectedItemLength?: number | undefined;
11
- setAutocompleteSuggestion?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
12
- setInputValue?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
13
- setIsMenuDirectlyActivated?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
14
- setSelectedItemLength?: import("react").Dispatch<import("react").SetStateAction<number | undefined>> | undefined;
15
- setShowMenu?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
16
- showMenu?: boolean | undefined;
17
- }>;
@@ -1,2 +0,0 @@
1
- import { createContext } from 'react';
2
- export const AutocompleteContext = /*#__PURE__*/createContext({});
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
3
- import { ComponentProps } from '../utils/types';
4
- declare type InternalAutocompleteInputProps = {
5
- as?: React.ComponentType<any>;
6
- };
7
- declare const AutocompleteInput: PolymorphicForwardRefComponent<"input", InternalAutocompleteInputProps>;
8
- export declare type AutocompleteInputProps = ComponentProps<typeof AutocompleteInput>;
9
- export default AutocompleteInput;
@@ -1,131 +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, useContext, useEffect, useState } from 'react';
4
- import { AutocompleteContext } from './AutocompleteContext';
5
- import TextInput from '../TextInput';
6
- import { useCombinedRefs } from '../hooks/useCombinedRefs';
7
- const AutocompleteInput = /*#__PURE__*/React.forwardRef(({
8
- as: Component = TextInput,
9
- onFocus,
10
- onBlur,
11
- onChange,
12
- onKeyDown,
13
- onKeyUp,
14
- onKeyPress,
15
- value,
16
- ...props
17
- }, forwardedRef) => {
18
- const {
19
- activeDescendantRef,
20
- autocompleteSuggestion = '',
21
- id,
22
- inputRef,
23
- inputValue = '',
24
- isMenuDirectlyActivated,
25
- setInputValue,
26
- setShowMenu,
27
- showMenu
28
- } = useContext(AutocompleteContext);
29
- const combinedInputRef = useCombinedRefs(inputRef, forwardedRef);
30
- const [highlightRemainingText, setHighlightRemainingText] = useState(true);
31
- const handleInputFocus = useCallback(event => {
32
- onFocus && onFocus(event);
33
- setShowMenu && setShowMenu(true);
34
- }, [onFocus, setShowMenu]);
35
- const handleInputBlur = useCallback(event => {
36
- onBlur && onBlur(event); // HACK: wait a tick and check the focused element before hiding the autocomplete menu
37
- // this prevents the menu from hiding when the user is clicking an option in the Autoselect.Menu,
38
- // but still hides the menu when the user blurs the input by tabbing out or clicking somewhere else on the page
39
-
40
- setTimeout(() => {
41
- if (document.activeElement !== combinedInputRef.current) {
42
- setShowMenu && setShowMenu(false);
43
- }
44
- }, 0);
45
- }, [onBlur, setShowMenu, combinedInputRef]);
46
- const handleInputChange = useCallback(event => {
47
- onChange && onChange(event);
48
- setInputValue && setInputValue(event.currentTarget.value);
49
-
50
- if (!showMenu) {
51
- setShowMenu && setShowMenu(true);
52
- }
53
- }, [onChange, setInputValue, setShowMenu, showMenu]);
54
- const handleInputKeyDown = useCallback(event => {
55
- var _inputRef$current;
56
-
57
- onKeyDown && onKeyDown(event);
58
-
59
- if (event.key === 'Backspace') {
60
- setHighlightRemainingText(false);
61
- }
62
-
63
- if (event.key === 'Escape' && inputRef !== null && inputRef !== void 0 && (_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.value) {
64
- setInputValue && setInputValue('');
65
- inputRef.current.value = '';
66
- }
67
- }, [inputRef, setInputValue, setHighlightRemainingText, onKeyDown]);
68
- const handleInputKeyUp = useCallback(event => {
69
- onKeyUp && onKeyUp(event);
70
-
71
- if (event.key === 'Backspace') {
72
- setHighlightRemainingText(true);
73
- }
74
- }, [setHighlightRemainingText, onKeyUp]);
75
- const onInputKeyPress = useCallback(event => {
76
- onKeyPress && onKeyPress(event);
77
-
78
- if (showMenu && activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
79
- event.preventDefault();
80
- event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
81
-
82
- const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
83
- activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
84
- }
85
- }, [activeDescendantRef, showMenu, onKeyPress]);
86
- useEffect(() => {
87
- if (!(inputRef !== null && inputRef !== void 0 && inputRef.current)) {
88
- return;
89
- } // resets input value to being empty after a selection has been made
90
-
91
-
92
- if (!autocompleteSuggestion) {
93
- inputRef.current.value = inputValue;
94
- } // TODO: fix bug where this function prevents `onChange` from being triggered if the highlighted item text
95
- // is the same as what I'm typing
96
- // e.g.: typing 'tw' highights 'two', but when I 'two', the text input change does not get triggered
97
-
98
-
99
- if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
100
- inputRef.current.value = autocompleteSuggestion;
101
-
102
- if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
103
- inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
104
- }
105
- } // calling this useEffeect when `highlightRemainingText` changes breaks backspace functionality
106
- // eslint-disable-next-line react-hooks/exhaustive-deps
107
-
108
- }, [autocompleteSuggestion, inputValue, inputRef, isMenuDirectlyActivated]);
109
- useEffect(() => {
110
- if (value) {
111
- setInputValue && setInputValue(value.toString());
112
- }
113
- }, [value, setInputValue]);
114
- return /*#__PURE__*/React.createElement(Component, _extends({
115
- onFocus: handleInputFocus,
116
- onBlur: handleInputBlur,
117
- onChange: handleInputChange,
118
- onKeyDown: handleInputKeyDown,
119
- onKeyPress: onInputKeyPress,
120
- onKeyUp: handleInputKeyUp,
121
- ref: combinedInputRef,
122
- "aria-controls": `${id}-listbox`,
123
- "aria-autocomplete": "both",
124
- role: "combobox",
125
- "aria-expanded": showMenu,
126
- "aria-haspopup": "listbox",
127
- "aria-owns": `${id}-listbox`,
128
- autocomplete: "off"
129
- }, props));
130
- });
131
- export default AutocompleteInput;
@@ -1,71 +0,0 @@
1
- import React from 'react';
2
- import { ItemProps } from '../ActionList';
3
- import { ComponentProps, MandateProps } from '../utils/types';
4
- declare type OnSelectedChange<T> = (item: T | T[]) => void;
5
- declare type AutocompleteItemProps<T = Record<string, any>> = MandateProps<ItemProps, 'id'> & {
6
- metadata?: T;
7
- };
8
- export declare type AutocompleteMenuInternalProps<T extends AutocompleteItemProps> = {
9
- /**
10
- * A menu item that is used to allow users make a selection that is not available in the array passed to the `items` prop.
11
- * This menu item gets appended to the end of the list of options.
12
- */
13
- addNewItem?: Omit<T, 'onAction' | 'leadingVisual' | 'id'> & {
14
- handleAddItem: (item: Omit<T, 'onAction' | 'leadingVisual'>) => void;
15
- };
16
- /**
17
- * The text that appears in the menu when there are no options in the array passed to the `items` prop.
18
- */
19
- emptyStateText?: React.ReactNode | false;
20
- /**
21
- * A custom function used to filter the options in the array passed to the `items` prop.
22
- * By default, we filter out items that don't match the value of the autocomplete text input. The default filter is not case-sensitive.
23
- */
24
- filterFn?: (item: T, i: number) => boolean;
25
- /**
26
- * The options for field values that are displayed in the dropdown menu.
27
- * One or more may be selected depending on the value of the `selectionVariant` prop.
28
- */
29
- items: T[];
30
- /**
31
- * Whether the data is loaded for the menu items
32
- */
33
- loading?: boolean;
34
- /**
35
- * The IDs of the selected items
36
- */
37
- selectedItemIds: Array<string | number>;
38
- /**
39
- * The sort function that is applied to the options in the array passed to the `items` prop after the user closes the menu.
40
- * By default, selected items are sorted to the top after the user closes the menu.
41
- */
42
- sortOnCloseFn?: (itemIdA: string | number, itemIdB: string | number) => number;
43
- /**
44
- * Whether there can be one item selected from the menu or multiple items selected from the menu
45
- */
46
- selectionVariant?: 'single' | 'multiple';
47
- /**
48
- * Function that gets called when the menu is opened or closed
49
- */
50
- onOpenChange?: (open: boolean) => void;
51
- /**
52
- * The function that is called when an item in the list is selected or deselected
53
- */
54
- onSelectedChange?: OnSelectedChange<T>;
55
- /**
56
- * If the menu is rendered in a scrolling element other than the `Autocomplete.Overlay` component,
57
- * pass the ref of that element to `customScrollContainerRef` to ensure the container automatically
58
- * scrolls when the user highlights an item in the menu that is outside the scroll container
59
- */
60
- customScrollContainerRef?: React.MutableRefObject<HTMLElement | null>;
61
- } & Pick<React.AriaAttributes, 'aria-labelledby'>;
62
- declare function AutocompleteMenu<T extends AutocompleteItemProps>(props: AutocompleteMenuInternalProps<T>): JSX.Element;
63
- declare namespace AutocompleteMenu {
64
- var defaultProps: {
65
- emptyStateText: string;
66
- selectionVariant: string;
67
- };
68
- var displayName: string;
69
- }
70
- export declare type AutocompleteMenuProps = ComponentProps<typeof AutocompleteMenu>;
71
- export default AutocompleteMenu;