@primer/components 0.0.0-202194183411 → 0.0.0-202194215436
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.
- package/CHANGELOG.md +1 -1
- package/dist/browser.esm.js +295 -299
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +358 -362
- package/dist/browser.umd.js.map +1 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
- package/lib/AnchoredOverlay/AnchoredOverlay.js +3 -11
- package/lib/FilteredActionList/FilteredActionList.js +31 -5
- package/lib/Overlay.d.ts +1 -2
- package/lib/Overlay.js +5 -10
- package/lib/SelectMenu/SelectMenu.d.ts +2 -8
- package/lib/TextInput.d.ts +3 -6
- package/lib/TextInput.js +10 -9
- package/{lib-esm/Token/TokenLabel.d.ts → lib/Token/LabelToken.d.ts} +3 -3
- package/lib/Token/{TokenLabel.js → LabelToken.js} +23 -23
- package/lib/Token/Token.d.ts +2 -2
- package/lib/Token/Token.js +13 -13
- package/lib/Token/TokenBase.d.ts +3 -3
- package/lib/Token/TokenBase.js +17 -16
- package/lib/Token/TokenProfile.d.ts +1 -1
- package/lib/Token/TokenProfile.js +3 -3
- package/lib/Token/_RemoveTokenButton.d.ts +7 -1
- package/lib/Token/_RemoveTokenButton.js +40 -11
- package/lib/Token/index.d.ts +1 -1
- package/lib/Token/index.js +3 -3
- package/lib/hooks/useOverlay.d.ts +1 -2
- package/lib/hooks/useOverlay.js +6 -11
- package/lib/index.d.ts +1 -3
- package/lib/index.js +2 -18
- package/lib/utils/types.d.ts +0 -3
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -11
- package/lib-esm/FilteredActionList/FilteredActionList.js +31 -3
- package/lib-esm/Overlay.d.ts +1 -2
- package/lib-esm/Overlay.js +5 -8
- package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -8
- package/lib-esm/TextInput.d.ts +3 -6
- package/lib-esm/TextInput.js +9 -8
- package/{lib/Token/TokenLabel.d.ts → lib-esm/Token/LabelToken.d.ts} +3 -3
- package/lib-esm/Token/{TokenLabel.js → LabelToken.js} +23 -23
- package/lib-esm/Token/Token.d.ts +2 -2
- package/lib-esm/Token/Token.js +13 -13
- package/lib-esm/Token/TokenBase.d.ts +3 -3
- package/lib-esm/Token/TokenBase.js +17 -16
- package/lib-esm/Token/TokenProfile.d.ts +1 -1
- package/lib-esm/Token/TokenProfile.js +3 -3
- package/lib-esm/Token/_RemoveTokenButton.d.ts +7 -1
- package/lib-esm/Token/_RemoveTokenButton.js +36 -10
- package/lib-esm/Token/index.d.ts +1 -1
- package/lib-esm/Token/index.js +1 -1
- package/lib-esm/hooks/useOverlay.d.ts +1 -2
- package/lib-esm/hooks/useOverlay.js +6 -11
- package/lib-esm/index.d.ts +1 -3
- package/lib-esm/index.js +1 -3
- package/lib-esm/utils/types.d.ts +0 -3
- package/package.json +1 -1
- package/lib/Autocomplete/Autocomplete.d.ts +0 -40
- package/lib/Autocomplete/Autocomplete.js +0 -68
- package/lib/Autocomplete/AutocompleteContext.d.ts +0 -17
- package/lib/Autocomplete/AutocompleteContext.js +0 -11
- package/lib/Autocomplete/AutocompleteInput.d.ts +0 -9
- package/lib/Autocomplete/AutocompleteInput.js +0 -146
- package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -71
- package/lib/Autocomplete/AutocompleteMenu.js +0 -223
- package/lib/Autocomplete/AutocompleteOverlay.d.ts +0 -17
- package/lib/Autocomplete/AutocompleteOverlay.js +0 -71
- package/lib/Autocomplete/index.d.ts +0 -2
- package/lib/Autocomplete/index.js +0 -15
- package/lib/TextInputWithTokens.d.ts +0 -43
- package/lib/TextInputWithTokens.js +0 -236
- package/lib/Token/_tokenButtonUtils.d.ts +0 -10
- package/lib/Token/_tokenButtonUtils.js +0 -42
- package/lib/_UnstyledTextInput.d.ts +0 -2
- package/lib/_UnstyledTextInput.js +0 -20
- package/lib/utils/scrollIntoViewingArea.d.ts +0 -1
- package/lib/utils/scrollIntoViewingArea.js +0 -39
- package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -40
- package/lib-esm/Autocomplete/Autocomplete.js +0 -47
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -17
- package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -9
- package/lib-esm/Autocomplete/AutocompleteInput.js +0 -127
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -71
- package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -202
- package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +0 -17
- package/lib-esm/Autocomplete/AutocompleteOverlay.js +0 -53
- package/lib-esm/Autocomplete/index.d.ts +0 -2
- package/lib-esm/Autocomplete/index.js +0 -1
- package/lib-esm/TextInputWithTokens.d.ts +0 -43
- package/lib-esm/TextInputWithTokens.js +0 -209
- package/lib-esm/Token/_tokenButtonUtils.d.ts +0 -10
- package/lib-esm/Token/_tokenButtonUtils.js +0 -26
- package/lib-esm/_UnstyledTextInput.d.ts +0 -2
- package/lib-esm/_UnstyledTextInput.js +0 -7
- package/lib-esm/utils/scrollIntoViewingArea.d.ts +0 -1
- package/lib-esm/utils/scrollIntoViewingArea.js +0 -30
@@ -1,127 +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
|
-
onKeyPress,
|
14
|
-
value,
|
15
|
-
...props
|
16
|
-
}, forwardedRef) => {
|
17
|
-
const {
|
18
|
-
activeDescendantRef,
|
19
|
-
autocompleteSuggestion = '',
|
20
|
-
id,
|
21
|
-
inputRef,
|
22
|
-
inputValue = '',
|
23
|
-
isMenuDirectlyActivated,
|
24
|
-
setInputValue,
|
25
|
-
setShowMenu,
|
26
|
-
showMenu
|
27
|
-
} = useContext(AutocompleteContext);
|
28
|
-
const combinedInputRef = useCombinedRefs(inputRef, forwardedRef);
|
29
|
-
const [highlightRemainingText, setHighlightRemainingText] = useState(true);
|
30
|
-
|
31
|
-
const handleInputFocus = e => {
|
32
|
-
onFocus && onFocus(e);
|
33
|
-
setShowMenu && setShowMenu(true);
|
34
|
-
};
|
35
|
-
|
36
|
-
const handleInputBlur = e => {
|
37
|
-
onBlur && onBlur(e); // HACK: wait a tick and check the focused element before hiding the autocomplete menu
|
38
|
-
// this prevents the menu from hiding when the user is clicking an option in the Autoselect.Menu,
|
39
|
-
// but still hides the menu when the user blurs the input by tabbing out or clicking somewhere else on the page
|
40
|
-
|
41
|
-
setTimeout(() => {
|
42
|
-
if (document.activeElement !== combinedInputRef.current) {
|
43
|
-
setShowMenu && setShowMenu(false);
|
44
|
-
}
|
45
|
-
}, 0);
|
46
|
-
};
|
47
|
-
|
48
|
-
const handleInputChange = e => {
|
49
|
-
onChange && onChange(e);
|
50
|
-
setInputValue && setInputValue(e.currentTarget.value);
|
51
|
-
|
52
|
-
if (!showMenu) {
|
53
|
-
setShowMenu && setShowMenu(true);
|
54
|
-
}
|
55
|
-
};
|
56
|
-
|
57
|
-
const handleInputKeyDown = e => {
|
58
|
-
var _inputRef$current;
|
59
|
-
|
60
|
-
if (e.key === 'Backspace') {
|
61
|
-
setHighlightRemainingText(false);
|
62
|
-
}
|
63
|
-
|
64
|
-
if (e.key === 'Escape' && inputRef !== null && inputRef !== void 0 && (_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.value) {
|
65
|
-
setInputValue && setInputValue('');
|
66
|
-
inputRef.current.value = '';
|
67
|
-
}
|
68
|
-
};
|
69
|
-
|
70
|
-
const handleInputKeyUp = e => {
|
71
|
-
if (e.key === 'Backspace') {
|
72
|
-
setHighlightRemainingText(true);
|
73
|
-
}
|
74
|
-
};
|
75
|
-
|
76
|
-
const onInputKeyPress = useCallback(event => {
|
77
|
-
if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
|
78
|
-
event.preventDefault();
|
79
|
-
event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
|
80
|
-
|
81
|
-
const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
|
82
|
-
activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
|
83
|
-
}
|
84
|
-
}, [activeDescendantRef]);
|
85
|
-
useEffect(() => {
|
86
|
-
if (!(inputRef !== null && inputRef !== void 0 && inputRef.current)) {
|
87
|
-
return;
|
88
|
-
} // resets input value to being empty after a selection has been made
|
89
|
-
|
90
|
-
|
91
|
-
if (!autocompleteSuggestion) {
|
92
|
-
inputRef.current.value = inputValue;
|
93
|
-
} // TODO: fix bug where this function prevents `onChange` from being triggered if the highlighted item text
|
94
|
-
// is the same as what I'm typing
|
95
|
-
// e.g.: typing 'tw' highights 'two', but when I 'two', the text input change does not get triggered
|
96
|
-
|
97
|
-
|
98
|
-
if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
|
99
|
-
inputRef.current.value = autocompleteSuggestion;
|
100
|
-
|
101
|
-
if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
|
102
|
-
inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
|
103
|
-
}
|
104
|
-
}
|
105
|
-
}, [autocompleteSuggestion, inputValue]);
|
106
|
-
useEffect(() => {
|
107
|
-
if (value) {
|
108
|
-
setInputValue && setInputValue(value.toString());
|
109
|
-
}
|
110
|
-
}, [value]);
|
111
|
-
return /*#__PURE__*/React.createElement(Component, _extends({
|
112
|
-
onFocus: handleInputFocus,
|
113
|
-
onBlur: handleInputBlur,
|
114
|
-
onChange: handleInputChange,
|
115
|
-
onKeyDown: handleInputKeyDown,
|
116
|
-
onKeyPress: onInputKeyPress,
|
117
|
-
onKeyUp: handleInputKeyUp,
|
118
|
-
ref: combinedInputRef,
|
119
|
-
"aria-controls": `${id}-listbox`,
|
120
|
-
"aria-autocomplete": "both",
|
121
|
-
role: "combobox",
|
122
|
-
"aria-expanded": showMenu,
|
123
|
-
"aria-haspopup": "listbox",
|
124
|
-
"aria-owns": `${id}-listbox`
|
125
|
-
}, props));
|
126
|
-
});
|
127
|
-
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
|
-
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;
|
@@ -1,202 +0,0 @@
|
|
1
|
-
import React, { useContext, useEffect, useRef, useState } from 'react';
|
2
|
-
import { ActionList } from '../ActionList';
|
3
|
-
import { useFocusZone } from '../hooks/useFocusZone';
|
4
|
-
import { Box, Spinner } from '../';
|
5
|
-
import { registerPortalRoot } from '../Portal';
|
6
|
-
import { AutocompleteContext } from './AutocompleteContext';
|
7
|
-
import { PlusIcon } from '@primer/octicons-react';
|
8
|
-
import { uniqueId } from '../utils/uniqueId';
|
9
|
-
import { scrollIntoViewingArea } from '../utils/scrollIntoViewingArea';
|
10
|
-
const DROPDOWN_PORTAL_CONTAINER_NAME = '__listcontainerportal__';
|
11
|
-
|
12
|
-
const getDefaultSortFn = isItemSelectedFn => (itemIdA, itemIdB) => isItemSelectedFn(itemIdA) === isItemSelectedFn(itemIdB) ? 0 : isItemSelectedFn(itemIdA) ? -1 : 1;
|
13
|
-
|
14
|
-
function getDefaultItemFilter(filterValue) {
|
15
|
-
return function (item, _i) {
|
16
|
-
var _item$text;
|
17
|
-
|
18
|
-
return Boolean((_item$text = item.text) === null || _item$text === void 0 ? void 0 : _item$text.toLowerCase().startsWith(filterValue.toLowerCase()));
|
19
|
-
};
|
20
|
-
}
|
21
|
-
|
22
|
-
const getDefaultOnSelectionChange = setInputValueFn => {
|
23
|
-
return function (itemOrItems) {
|
24
|
-
const {
|
25
|
-
text = ''
|
26
|
-
} = Array.isArray(itemOrItems) ? itemOrItems.slice(-1)[0] : itemOrItems;
|
27
|
-
setInputValueFn && setInputValueFn(text);
|
28
|
-
};
|
29
|
-
};
|
30
|
-
|
31
|
-
// TODO: consider making 'aria-labelledby' required
|
32
|
-
function AutocompleteMenu(props) {
|
33
|
-
const {
|
34
|
-
activeDescendantRef,
|
35
|
-
id,
|
36
|
-
inputRef,
|
37
|
-
inputValue = '',
|
38
|
-
scrollContainerRef,
|
39
|
-
setAutocompleteSuggestion,
|
40
|
-
setShowMenu,
|
41
|
-
setInputValue,
|
42
|
-
setIsMenuDirectlyActivated,
|
43
|
-
setSelectedItemLength,
|
44
|
-
showMenu
|
45
|
-
} = useContext(AutocompleteContext);
|
46
|
-
const {
|
47
|
-
items,
|
48
|
-
selectedItemIds,
|
49
|
-
sortOnCloseFn,
|
50
|
-
emptyStateText,
|
51
|
-
addNewItem,
|
52
|
-
loading,
|
53
|
-
selectionVariant,
|
54
|
-
filterFn = getDefaultItemFilter(inputValue),
|
55
|
-
"aria-labelledby": ariaLabelledBy,
|
56
|
-
onOpenChange,
|
57
|
-
onSelectedChange = getDefaultOnSelectionChange(setInputValue),
|
58
|
-
customScrollContainerRef
|
59
|
-
} = props;
|
60
|
-
const listContainerRef = useRef(null);
|
61
|
-
const [highlightedItem, setHighlightedItem] = useState();
|
62
|
-
const [sortedItemIds, setSortedItemIds] = useState(items.map(({
|
63
|
-
id
|
64
|
-
}) => id));
|
65
|
-
|
66
|
-
const isItemSelected = itemId => selectedItemIds.includes(itemId);
|
67
|
-
|
68
|
-
const getItemById = itemId => items.find(item => item.id === itemId);
|
69
|
-
|
70
|
-
const selectableItems = items.map(selectableItem => {
|
71
|
-
return { ...selectableItem,
|
72
|
-
role: "option",
|
73
|
-
id: selectableItem.id,
|
74
|
-
selected: selectionVariant === 'multiple' ? selectedItemIds.includes(selectableItem.id) : undefined,
|
75
|
-
onAction: item => {
|
76
|
-
const otherSelectedItemIds = selectedItemIds.filter(selectedItemId => selectedItemId !== item.id);
|
77
|
-
const newSelectedItemIds = selectedItemIds.includes(item.id) ? otherSelectedItemIds : [...otherSelectedItemIds, item.id];
|
78
|
-
onSelectedChange && onSelectedChange(newSelectedItemIds.map(getItemById));
|
79
|
-
|
80
|
-
if (selectionVariant === 'multiple') {
|
81
|
-
setInputValue && setInputValue('');
|
82
|
-
setAutocompleteSuggestion && setAutocompleteSuggestion('');
|
83
|
-
} else {
|
84
|
-
var _inputRef$current;
|
85
|
-
|
86
|
-
setShowMenu && setShowMenu(false);
|
87
|
-
inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.setSelectionRange(inputRef.current.value.length, inputRef.current.value.length);
|
88
|
-
}
|
89
|
-
}
|
90
|
-
};
|
91
|
-
});
|
92
|
-
const itemSortOrderData = sortedItemIds.reduce((acc, curr, i) => {
|
93
|
-
acc[curr] = i;
|
94
|
-
return acc;
|
95
|
-
}, {});
|
96
|
-
const sortedAndFilteredItemsToRender = selectableItems.filter((item, i) => filterFn(item, i)).sort((a, b) => itemSortOrderData[a.id] - itemSortOrderData[b.id]);
|
97
|
-
const allItemsToRender = [// sorted and filtered selectable items
|
98
|
-
...sortedAndFilteredItemsToRender, // menu item used for creating a token from whatever is in the text input
|
99
|
-
...(addNewItem ? [{ ...addNewItem,
|
100
|
-
leadingVisual: () => /*#__PURE__*/React.createElement(PlusIcon, null),
|
101
|
-
onAction: (item, e) => {
|
102
|
-
// TODO: make it possible to pass a leadingVisual when using `addNewItem`
|
103
|
-
addNewItem.handleAddItem({ ...item,
|
104
|
-
id: item.id || uniqueId(),
|
105
|
-
leadingVisual: undefined
|
106
|
-
});
|
107
|
-
|
108
|
-
if (selectionVariant === 'multiple') {
|
109
|
-
setInputValue && setInputValue('');
|
110
|
-
setAutocompleteSuggestion && setAutocompleteSuggestion('');
|
111
|
-
}
|
112
|
-
}
|
113
|
-
}] : [])];
|
114
|
-
useFocusZone({
|
115
|
-
containerRef: listContainerRef,
|
116
|
-
focusOutBehavior: 'wrap',
|
117
|
-
focusableElementFilter: element => {
|
118
|
-
return !(element instanceof HTMLInputElement);
|
119
|
-
},
|
120
|
-
activeDescendantFocus: inputRef,
|
121
|
-
onActiveDescendantChanged: (current, _previous, directlyActivated) => {
|
122
|
-
if (activeDescendantRef) {
|
123
|
-
activeDescendantRef.current = current || null;
|
124
|
-
}
|
125
|
-
|
126
|
-
if (current) {
|
127
|
-
const selectedItem = selectableItems.find(item => item.id.toString() === (current === null || current === void 0 ? void 0 : current.dataset.id));
|
128
|
-
setHighlightedItem(selectedItem);
|
129
|
-
setIsMenuDirectlyActivated && setIsMenuDirectlyActivated(directlyActivated);
|
130
|
-
}
|
131
|
-
|
132
|
-
if (current && customScrollContainerRef && customScrollContainerRef.current && directlyActivated) {
|
133
|
-
scrollIntoViewingArea(current, customScrollContainerRef.current);
|
134
|
-
} else if (current && scrollContainerRef && scrollContainerRef.current && directlyActivated) {
|
135
|
-
scrollIntoViewingArea(current, scrollContainerRef.current);
|
136
|
-
}
|
137
|
-
}
|
138
|
-
}, [loading]);
|
139
|
-
useEffect(() => {
|
140
|
-
var _highlightedItem$text;
|
141
|
-
|
142
|
-
if (!setAutocompleteSuggestion) {
|
143
|
-
return;
|
144
|
-
}
|
145
|
-
|
146
|
-
if (highlightedItem !== null && highlightedItem !== void 0 && (_highlightedItem$text = highlightedItem.text) !== null && _highlightedItem$text !== void 0 && _highlightedItem$text.startsWith(inputValue) && !selectedItemIds.includes(highlightedItem.id)) {
|
147
|
-
setAutocompleteSuggestion(highlightedItem.text);
|
148
|
-
} else {
|
149
|
-
setAutocompleteSuggestion('');
|
150
|
-
}
|
151
|
-
}, [highlightedItem, inputValue]);
|
152
|
-
useEffect(() => {
|
153
|
-
setSortedItemIds([...sortedItemIds].sort(sortOnCloseFn ? sortOnCloseFn : getDefaultSortFn(isItemSelected)));
|
154
|
-
onOpenChange && onOpenChange(Boolean(showMenu));
|
155
|
-
}, [showMenu]);
|
156
|
-
useEffect(() => {
|
157
|
-
setSelectedItemLength && setSelectedItemLength(selectedItemIds.length);
|
158
|
-
}, [selectedItemIds]);
|
159
|
-
|
160
|
-
if (listContainerRef.current) {
|
161
|
-
registerPortalRoot(listContainerRef.current, DROPDOWN_PORTAL_CONTAINER_NAME);
|
162
|
-
}
|
163
|
-
|
164
|
-
return /*#__PURE__*/React.createElement(Box, {
|
165
|
-
sx: !showMenu ? {
|
166
|
-
// visually hides this label for sighted users
|
167
|
-
position: 'absolute',
|
168
|
-
width: '1px',
|
169
|
-
height: '1px',
|
170
|
-
padding: '0',
|
171
|
-
margin: '-1px',
|
172
|
-
overflow: 'hidden',
|
173
|
-
clip: 'rect(0, 0, 0, 0)',
|
174
|
-
whiteSpace: 'nowrap',
|
175
|
-
borderWidth: '0'
|
176
|
-
} : {}
|
177
|
-
}, loading ? /*#__PURE__*/React.createElement(Box, {
|
178
|
-
p: 3,
|
179
|
-
display: "flex",
|
180
|
-
justifyContent: "center"
|
181
|
-
}, /*#__PURE__*/React.createElement(Spinner, null)) : /*#__PURE__*/React.createElement("div", {
|
182
|
-
ref: listContainerRef
|
183
|
-
}, allItemsToRender.length ? /*#__PURE__*/React.createElement(ActionList, {
|
184
|
-
selectionVariant: "multiple" // have to typecast to `ItemProps` because we have an extra property
|
185
|
-
// on `items` for Autocomplete: `metadata`
|
186
|
-
,
|
187
|
-
items: allItemsToRender,
|
188
|
-
role: "listbox",
|
189
|
-
id: `${id}-listbox`,
|
190
|
-
"aria-labelledby": ariaLabelledBy
|
191
|
-
}) : /*#__PURE__*/React.createElement(Box, {
|
192
|
-
p: 3
|
193
|
-
}, emptyStateText)));
|
194
|
-
}
|
195
|
-
|
196
|
-
AutocompleteMenu.displayName = "AutocompleteMenu";
|
197
|
-
AutocompleteMenu.defaultProps = {
|
198
|
-
emptyStateText: 'No selectable options',
|
199
|
-
selectionVariant: 'single'
|
200
|
-
};
|
201
|
-
AutocompleteMenu.displayName = 'AutocompleteMenu';
|
202
|
-
export default AutocompleteMenu;
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { OverlayProps } from '../Overlay';
|
3
|
-
import { ComponentProps } from '../utils/types';
|
4
|
-
declare type AutocompleteOverlayInternalProps = {
|
5
|
-
/**
|
6
|
-
* The ref of the element that the position of the menu is based on. By default, the menu is positioned based on the text input
|
7
|
-
*/
|
8
|
-
menuAnchorRef?: React.RefObject<HTMLElement>;
|
9
|
-
/**
|
10
|
-
* Props to be spread on the internal `Overlay` component.
|
11
|
-
*/
|
12
|
-
overlayProps?: Partial<OverlayProps>;
|
13
|
-
children?: React.ReactNode;
|
14
|
-
} & Pick<React.AriaAttributes, 'aria-labelledby'>;
|
15
|
-
declare const AutocompleteOverlay: React.FC<AutocompleteOverlayInternalProps>;
|
16
|
-
export declare type AutocompleteOverlayProps = ComponentProps<typeof AutocompleteOverlay>;
|
17
|
-
export default AutocompleteOverlay;
|
@@ -1,53 +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, { useContext } from 'react';
|
4
|
-
import { useAnchoredPosition } from '../hooks';
|
5
|
-
import Overlay from '../Overlay';
|
6
|
-
import { AutocompleteContext } from './AutocompleteContext';
|
7
|
-
import { useCombinedRefs } from '../hooks/useCombinedRefs';
|
8
|
-
|
9
|
-
// TODO: consider making 'aria-labelledby' required
|
10
|
-
const AutocompleteOverlay = ({
|
11
|
-
menuAnchorRef,
|
12
|
-
overlayProps,
|
13
|
-
children
|
14
|
-
}) => {
|
15
|
-
const {
|
16
|
-
inputRef,
|
17
|
-
scrollContainerRef,
|
18
|
-
selectedItemLength,
|
19
|
-
setShowMenu,
|
20
|
-
showMenu = false
|
21
|
-
} = useContext(AutocompleteContext);
|
22
|
-
const {
|
23
|
-
floatingElementRef,
|
24
|
-
position
|
25
|
-
} = useAnchoredPosition({
|
26
|
-
side: 'outside-bottom',
|
27
|
-
align: 'start',
|
28
|
-
anchorElementRef: menuAnchorRef ? menuAnchorRef : inputRef
|
29
|
-
}, [showMenu, selectedItemLength]);
|
30
|
-
const combinedOverlayRef = useCombinedRefs(scrollContainerRef, floatingElementRef);
|
31
|
-
|
32
|
-
const closeOptionList = () => {
|
33
|
-
setShowMenu && setShowMenu(false);
|
34
|
-
};
|
35
|
-
|
36
|
-
return /*#__PURE__*/React.createElement(Overlay, _extends({
|
37
|
-
returnFocusRef: inputRef,
|
38
|
-
preventFocusOnOpen: true,
|
39
|
-
onClickOutside: closeOptionList,
|
40
|
-
onEscape: closeOptionList,
|
41
|
-
ref: combinedOverlayRef,
|
42
|
-
top: position === null || position === void 0 ? void 0 : position.top,
|
43
|
-
left: position === null || position === void 0 ? void 0 : position.left,
|
44
|
-
visibility: showMenu ? 'visible' : 'hidden',
|
45
|
-
sx: {
|
46
|
-
overflow: "auto"
|
47
|
-
}
|
48
|
-
}, overlayProps), children);
|
49
|
-
};
|
50
|
-
|
51
|
-
AutocompleteOverlay.displayName = "AutocompleteOverlay";
|
52
|
-
AutocompleteOverlay.displayName = 'AutocompleteOverlay';
|
53
|
-
export default AutocompleteOverlay;
|
@@ -1 +0,0 @@
|
|
1
|
-
export { default } from './Autocomplete';
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import React, { ComponentPropsWithoutRef } from 'react';
|
2
|
-
import { ComponentProps, MandateProps } from './utils/types';
|
3
|
-
import Token, { TokenProps } from './Token/Token';
|
4
|
-
import TokenLabel, { TokenLabelProps } from './Token/TokenLabel';
|
5
|
-
import TokenProfile, { TokenProfileProps } from './Token/TokenProfile';
|
6
|
-
import { TokenSizeKeys } from './Token/TokenBase';
|
7
|
-
import { TextInputProps } from './TextInput';
|
8
|
-
declare type AnyTokenProps = Partial<TokenProps & TokenLabelProps & TokenProfileProps>;
|
9
|
-
declare type TokenDatum = MandateProps<AnyTokenProps, 'id' | 'text'>;
|
10
|
-
declare type TextInputWithTokensInternalProps = {
|
11
|
-
/**
|
12
|
-
* The array of tokens to render
|
13
|
-
*/
|
14
|
-
tokens: TokenDatum[];
|
15
|
-
/**
|
16
|
-
* The function that gets called when a token is removed
|
17
|
-
*/
|
18
|
-
onTokenRemove: (tokenId: string | number) => void;
|
19
|
-
/**
|
20
|
-
* The component used to render each token
|
21
|
-
*/
|
22
|
-
tokenComponent?: React.ComponentType<ComponentPropsWithoutRef<typeof Token> | ComponentPropsWithoutRef<typeof TokenLabel> | ComponentPropsWithoutRef<typeof TokenProfile>>;
|
23
|
-
/**
|
24
|
-
* The maximum height of the component. If the content in the input exceeds this height,
|
25
|
-
* it will scroll vertically
|
26
|
-
*/
|
27
|
-
maxHeight?: React.CSSProperties['maxHeight'];
|
28
|
-
/**
|
29
|
-
* Whether tokens should render inline horizontally. By default, tokens wrap to new lines.
|
30
|
-
*/
|
31
|
-
preventTokenWrapping?: boolean;
|
32
|
-
/**
|
33
|
-
* The size of the tokens
|
34
|
-
*/
|
35
|
-
tokenSizeVariant?: TokenSizeKeys;
|
36
|
-
/**
|
37
|
-
* Whether the remove buttons should be rendered in the tokens
|
38
|
-
*/
|
39
|
-
hideTokenRemoveButtons?: boolean;
|
40
|
-
} & TextInputProps;
|
41
|
-
declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<TextInputWithTokensInternalProps, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
42
|
-
export declare type TextInputWithTokensProps = ComponentProps<typeof TextInputWithTokens>;
|
43
|
-
export default TextInputWithTokens;
|