@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.
- package/CHANGELOG.md +15 -1
- package/dist/browser.esm.js +667 -621
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +301 -255
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +3 -3
- package/lib/AnchoredOverlay/AnchoredOverlay.js +2 -2
- package/lib/Avatar.d.ts +4 -0
- package/lib/Dialog/Dialog.js +4 -4
- package/lib/FilteredActionList/FilteredActionList.js +3 -3
- package/lib/Overlay.d.ts +0 -1
- package/lib/Overlay.js +5 -10
- package/lib/SelectMenu/SelectMenu.d.ts +11 -327
- package/lib/SelectMenu/SelectMenuFilter.d.ts +1 -1
- package/lib/TextInput.d.ts +6 -6
- package/lib/TextInput.js +21 -16
- package/lib/Timeline.js +12 -15
- package/lib/hooks/useOverlay.d.ts +1 -2
- package/lib/hooks/useOverlay.js +6 -11
- package/lib/index.d.ts +1 -0
- package/lib/index.js +14 -0
- package/lib/theme-preval.js +1705 -1957
- package/lib/utils/ssr.d.ts +1 -0
- package/lib/utils/ssr.js +19 -0
- package/lib/utils/testing.d.ts +2431 -2929
- package/lib/utils/uniqueId.js +1 -0
- package/lib-esm/ActionList/Item.js +4 -4
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -3
- package/lib-esm/Avatar.d.ts +4 -0
- package/lib-esm/Dialog/Dialog.js +3 -3
- package/lib-esm/FilteredActionList/FilteredActionList.js +3 -3
- package/lib-esm/Overlay.d.ts +0 -1
- package/lib-esm/Overlay.js +5 -8
- package/lib-esm/SelectMenu/SelectMenu.d.ts +11 -327
- package/lib-esm/SelectMenu/SelectMenuFilter.d.ts +1 -1
- package/lib-esm/TextInput.d.ts +6 -6
- package/lib-esm/TextInput.js +22 -16
- package/lib-esm/Timeline.js +8 -13
- package/lib-esm/hooks/useOverlay.d.ts +1 -2
- package/lib-esm/hooks/useOverlay.js +6 -11
- package/lib-esm/index.d.ts +1 -0
- package/lib-esm/index.js +2 -1
- package/lib-esm/theme-preval.js +1705 -1957
- package/lib-esm/utils/ssr.d.ts +1 -0
- package/lib-esm/utils/ssr.js +1 -0
- package/lib-esm/utils/testing.d.ts +2431 -2929
- package/lib-esm/utils/uniqueId.js +1 -0
- package/package.json +5 -7
- package/lib/Autocomplete/Autocomplete.d.ts +0 -8
- package/lib/Autocomplete/Autocomplete.js +0 -49
- package/lib/Autocomplete/AutocompleteContext.d.ts +0 -13
- package/lib/Autocomplete/AutocompleteContext.js +0 -11
- package/lib/Autocomplete/AutocompleteInput.d.ts +0 -7
- package/lib/Autocomplete/AutocompleteInput.js +0 -78
- package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -19
- package/lib/Autocomplete/AutocompleteMenu.js +0 -226
- package/lib/Badge/Badge.d.ts +0 -8
- package/lib/Badge/Badge.js +0 -59
- package/lib/Badge/BadgeState.d.ts +0 -13
- package/lib/Badge/BadgeState.js +0 -51
- package/lib/Badge/_badgeStyleUtils.d.ts +0 -3
- package/lib/Badge/_badgeStyleUtils.js +0 -39
- package/lib/TextInputTokens.d.ts +0 -32
- package/lib/TextInputTokens.js +0 -225
- package/lib/TextInputWithTokens.d.ts +0 -41
- package/lib/TextInputWithTokens.js +0 -396
- package/lib/Token/Token.d.ts +0 -7
- package/lib/Token/Token.js +0 -66
- package/lib/Token/TokenBase.d.ts +0 -16
- package/lib/Token/TokenBase.js +0 -76
- package/lib/Token/TokenLabel.d.ts +0 -8
- package/lib/Token/TokenLabel.js +0 -116
- package/lib/Token/TokenProfile.d.ts +0 -7
- package/lib/Token/TokenProfile.js +0 -45
- package/lib/Token/_AddTokenButton.d.ts +0 -3
- package/lib/Token/_AddTokenButton.js +0 -42
- package/lib/Token/_RemoveTokenButton.d.ts +0 -3
- package/lib/Token/_RemoveTokenButton.js +0 -42
- package/lib/Token/_tokenButtonUtils.d.ts +0 -8
- package/lib/Token/_tokenButtonUtils.js +0 -42
- package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -8
- package/lib-esm/Autocomplete/Autocomplete.js +0 -36
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -13
- package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -7
- package/lib-esm/Autocomplete/AutocompleteInput.js +0 -59
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -19
- package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -203
- package/lib-esm/Badge/Badge.d.ts +0 -8
- package/lib-esm/Badge/Badge.js +0 -44
- package/lib-esm/Badge/BadgeState.d.ts +0 -13
- package/lib-esm/Badge/BadgeState.js +0 -40
- package/lib-esm/Badge/_badgeStyleUtils.d.ts +0 -3
- package/lib-esm/Badge/_badgeStyleUtils.js +0 -29
- package/lib-esm/TextInputTokens.d.ts +0 -32
- package/lib-esm/TextInputTokens.js +0 -195
- package/lib-esm/TextInputWithTokens.d.ts +0 -41
- package/lib-esm/TextInputWithTokens.js +0 -361
- package/lib-esm/Token/Token.d.ts +0 -7
- package/lib-esm/Token/Token.js +0 -46
- package/lib-esm/Token/TokenBase.d.ts +0 -16
- package/lib-esm/Token/TokenBase.js +0 -56
- package/lib-esm/Token/TokenLabel.d.ts +0 -8
- package/lib-esm/Token/TokenLabel.js +0 -100
- package/lib-esm/Token/TokenProfile.d.ts +0 -7
- package/lib-esm/Token/TokenProfile.js +0 -28
- package/lib-esm/Token/_AddTokenButton.d.ts +0 -3
- package/lib-esm/Token/_AddTokenButton.js +0 -27
- package/lib-esm/Token/_RemoveTokenButton.d.ts +0 -3
- package/lib-esm/Token/_RemoveTokenButton.js +0 -27
- package/lib-esm/Token/_tokenButtonUtils.d.ts +0 -8
- package/lib-esm/Token/_tokenButtonUtils.js +0 -26
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@primer/components",
|
3
|
-
"version": "0.0.0-
|
3
|
+
"version": "0.0.0-2021816212749",
|
4
4
|
"description": "Primer react components",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"module": "lib-esm/index.js",
|
@@ -44,8 +44,8 @@
|
|
44
44
|
"license": "MIT",
|
45
45
|
"dependencies": {
|
46
46
|
"@primer/octicons-react": "^13.0.0",
|
47
|
-
"@primer/primitives": "4.
|
48
|
-
"@
|
47
|
+
"@primer/primitives": "4.6.4",
|
48
|
+
"@react-aria/ssr": "3.1.0",
|
49
49
|
"@styled-system/css": "5.1.5",
|
50
50
|
"@styled-system/props": "5.1.5",
|
51
51
|
"@styled-system/theme-get": "5.1.2",
|
@@ -57,8 +57,7 @@
|
|
57
57
|
"classnames": "2.3.1",
|
58
58
|
"deepmerge": "4.2.2",
|
59
59
|
"focus-visible": "5.2.0",
|
60
|
-
"styled-system": "5.1.5"
|
61
|
-
"tinycolor2": "1.4.2"
|
60
|
+
"styled-system": "5.1.5"
|
62
61
|
},
|
63
62
|
"devDependencies": {
|
64
63
|
"@babel/cli": "7.14.5",
|
@@ -90,7 +89,6 @@
|
|
90
89
|
"@types/jest-axe": "3.5.1",
|
91
90
|
"@types/lodash.isempty": "4.4.6",
|
92
91
|
"@types/lodash.isobject": "3.0.6",
|
93
|
-
"@types/tinycolor2": "1.4.3",
|
94
92
|
"@typescript-eslint/eslint-plugin": "4.26.1",
|
95
93
|
"@typescript-eslint/parser": "4.26.1",
|
96
94
|
"@wojtekmaj/enzyme-adapter-react-17": "0.6.3",
|
@@ -124,7 +122,7 @@
|
|
124
122
|
"react": "17.0.2",
|
125
123
|
"react-dom": "17.0.2",
|
126
124
|
"react-test-renderer": "17.0.2",
|
127
|
-
"rollup": "2.
|
125
|
+
"rollup": "2.56.3",
|
128
126
|
"rollup-plugin-babel": "4.4.0",
|
129
127
|
"rollup-plugin-terser": "7.0.2",
|
130
128
|
"rollup-plugin-visualizer": "5.5.0",
|
@@ -1,49 +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 _AutocompleteContext = require("./AutocompleteContext");
|
11
|
-
|
12
|
-
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); }
|
13
|
-
|
14
|
-
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; }
|
15
|
-
|
16
|
-
const defaultItemFilter = filterValue => (item, _i) => {
|
17
|
-
var _item$text;
|
18
|
-
|
19
|
-
return Boolean(item === null || item === void 0 ? void 0 : (_item$text = item.text) === null || _item$text === void 0 ? void 0 : _item$text.toLowerCase().startsWith(filterValue.toLowerCase()));
|
20
|
-
};
|
21
|
-
|
22
|
-
const Autocomplete = ({
|
23
|
-
children,
|
24
|
-
filterValue = '',
|
25
|
-
filterFn: externalFilterFn
|
26
|
-
}) => {
|
27
|
-
const activeDescendantRef = (0, _react.useRef)(null);
|
28
|
-
const inputRef = (0, _react.useRef)(null);
|
29
|
-
const [inputValue, setInputValue] = (0, _react.useState)(filterValue);
|
30
|
-
const [showMenu, setShowMenu] = (0, _react.useState)(false);
|
31
|
-
const [autocompleteSuggestion, setAutocompleteSuggestion] = (0, _react.useState)('');
|
32
|
-
return /*#__PURE__*/_react.default.createElement(_AutocompleteContext.AutocompleteContext.Provider, {
|
33
|
-
value: {
|
34
|
-
activeDescendantRef,
|
35
|
-
autocompleteSuggestion,
|
36
|
-
filterFn: externalFilterFn ? externalFilterFn : defaultItemFilter(inputValue),
|
37
|
-
inputRef,
|
38
|
-
inputValue,
|
39
|
-
showMenu,
|
40
|
-
setAutocompleteSuggestion,
|
41
|
-
setInputValue,
|
42
|
-
setShowMenu
|
43
|
-
}
|
44
|
-
}, children);
|
45
|
-
};
|
46
|
-
|
47
|
-
Autocomplete.displayName = "Autocomplete";
|
48
|
-
var _default = Autocomplete;
|
49
|
-
exports.default = _default;
|
@@ -1,13 +0,0 @@
|
|
1
|
-
/// <reference types="react" />
|
2
|
-
import { ItemInput } from '../ActionList/List';
|
3
|
-
export declare const AutocompleteContext: import("react").Context<{
|
4
|
-
activeDescendantRef?: import("react").MutableRefObject<HTMLElement | null> | undefined;
|
5
|
-
autocompleteSuggestion?: string | undefined;
|
6
|
-
filterFn?: ((item: ItemInput, i: number) => boolean) | undefined;
|
7
|
-
inputRef?: import("react").MutableRefObject<HTMLInputElement | null> | undefined;
|
8
|
-
inputValue?: string | undefined;
|
9
|
-
showMenu?: boolean | undefined;
|
10
|
-
setAutocompleteSuggestion?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
|
11
|
-
setShowMenu?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
|
12
|
-
setInputValue?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
|
13
|
-
}>;
|
@@ -1,11 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.AutocompleteContext = void 0;
|
7
|
-
|
8
|
-
var _react = require("react");
|
9
|
-
|
10
|
-
const AutocompleteContext = /*#__PURE__*/(0, _react.createContext)({});
|
11
|
-
exports.AutocompleteContext = AutocompleteContext;
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import type * as Polymorphic from "@radix-ui/react-polymorphic";
|
3
|
-
interface Props {
|
4
|
-
as?: React.ComponentType<any>;
|
5
|
-
}
|
6
|
-
declare const AutocompleteInput: Polymorphic.ForwardRefComponent<"input", Props>;
|
7
|
-
export default AutocompleteInput;
|
@@ -1,78 +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 _AutocompleteContext = require("./AutocompleteContext");
|
11
|
-
|
12
|
-
var _TextInput = _interopRequireDefault(require("../TextInput"));
|
13
|
-
|
14
|
-
var _useCombinedRefs = require("../hooks/useCombinedRefs");
|
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
|
-
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); }
|
23
|
-
|
24
|
-
const AutocompleteInput = /*#__PURE__*/_react.default.forwardRef(({
|
25
|
-
as: Component = _TextInput.default,
|
26
|
-
onFocus,
|
27
|
-
onChange,
|
28
|
-
onKeyDown,
|
29
|
-
onKeyPress,
|
30
|
-
...props
|
31
|
-
}, forwardedRef) => {
|
32
|
-
const {
|
33
|
-
activeDescendantRef,
|
34
|
-
autocompleteSuggestion,
|
35
|
-
inputRef,
|
36
|
-
setInputValue,
|
37
|
-
setShowMenu
|
38
|
-
} = (0, _react.useContext)(_AutocompleteContext.AutocompleteContext);
|
39
|
-
const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(inputRef, forwardedRef);
|
40
|
-
|
41
|
-
const handleInputFocus = () => {
|
42
|
-
if (setShowMenu) {
|
43
|
-
setShowMenu(true);
|
44
|
-
}
|
45
|
-
};
|
46
|
-
|
47
|
-
const handleInputChange = e => {
|
48
|
-
if (setInputValue) {
|
49
|
-
setInputValue(e.currentTarget.value);
|
50
|
-
}
|
51
|
-
};
|
52
|
-
|
53
|
-
const handleInputKeyDown = e => {
|
54
|
-
if (setInputValue && e.key === 'ArrowRight' && autocompleteSuggestion) {
|
55
|
-
setInputValue(autocompleteSuggestion);
|
56
|
-
}
|
57
|
-
};
|
58
|
-
|
59
|
-
const onInputKeyPress = (0, _react.useCallback)(event => {
|
60
|
-
if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
|
61
|
-
event.preventDefault();
|
62
|
-
event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
|
63
|
-
|
64
|
-
const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
|
65
|
-
activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
|
66
|
-
}
|
67
|
-
}, [activeDescendantRef]);
|
68
|
-
return /*#__PURE__*/_react.default.createElement(Component, _extends({
|
69
|
-
onFocus: handleInputFocus,
|
70
|
-
onChange: handleInputChange,
|
71
|
-
onKeyDown: handleInputKeyDown,
|
72
|
-
onKeyPress: onInputKeyPress,
|
73
|
-
ref: combinedInputRef
|
74
|
-
}, props));
|
75
|
-
});
|
76
|
-
|
77
|
-
var _default = AutocompleteInput;
|
78
|
-
exports.default = _default;
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { ItemProps } from '../ActionList';
|
3
|
-
import { ItemInput } from '../ActionList/List';
|
4
|
-
import { ComponentProps } from '../utils/types';
|
5
|
-
declare type AutocompleteMenuInternalProps = {
|
6
|
-
selectableItems: ItemInput[];
|
7
|
-
selectedItemIds: Array<string | number>;
|
8
|
-
selectedSortFn?: (itemIdA: string | number, itemIdB: string | number) => number;
|
9
|
-
onItemSelect: NonNullable<ItemProps['onAction']>;
|
10
|
-
onItemDeselect: NonNullable<ItemProps['onAction']>;
|
11
|
-
emptyStateText?: React.ReactNode | false;
|
12
|
-
addNewItem?: Omit<ItemInput, 'onAction'>;
|
13
|
-
onCloseOptionsList?: () => void;
|
14
|
-
maxHeight?: React.CSSProperties['maxHeight'];
|
15
|
-
loading?: boolean;
|
16
|
-
};
|
17
|
-
declare const AutocompleteMenu: React.ForwardRefExoticComponent<AutocompleteMenuInternalProps & React.RefAttributes<HTMLInputElement>>;
|
18
|
-
export declare type AutocompleteMenuProps = ComponentProps<typeof AutocompleteMenu>;
|
19
|
-
export default AutocompleteMenu;
|
@@ -1,226 +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 _ActionList = require("../ActionList");
|
11
|
-
|
12
|
-
var _hooks = require("../hooks");
|
13
|
-
|
14
|
-
var _useFocusZone = require("../hooks/useFocusZone");
|
15
|
-
|
16
|
-
var _Overlay = _interopRequireDefault(require("../Overlay"));
|
17
|
-
|
18
|
-
var _ = require("../");
|
19
|
-
|
20
|
-
var _Portal = require("../Portal");
|
21
|
-
|
22
|
-
var _AutocompleteContext = require("./AutocompleteContext");
|
23
|
-
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25
|
-
|
26
|
-
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); }
|
27
|
-
|
28
|
-
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; }
|
29
|
-
|
30
|
-
const DROPDOWN_PORTAL_CONTAINER_NAME = '__listcontainerportal__';
|
31
|
-
|
32
|
-
const getDefaultSortFn = isItemSelectedFn => (itemIdA, itemIdB) => isItemSelectedFn(itemIdA) === isItemSelectedFn(itemIdB) ? 0 : isItemSelectedFn(itemIdA) ? -1 : 1;
|
33
|
-
|
34
|
-
function scrollIntoViewingArea(child, container, margin = 8, behavior = 'smooth') {
|
35
|
-
const {
|
36
|
-
top: childTop,
|
37
|
-
bottom: childBottom
|
38
|
-
} = child.getBoundingClientRect();
|
39
|
-
const {
|
40
|
-
top: containerTop,
|
41
|
-
bottom: containerBottom
|
42
|
-
} = container.getBoundingClientRect();
|
43
|
-
const isChildTopAboveViewingArea = childTop < containerTop + margin;
|
44
|
-
const isChildBottomBelowViewingArea = childBottom > containerBottom - margin;
|
45
|
-
|
46
|
-
if (isChildTopAboveViewingArea) {
|
47
|
-
const scrollHeightToChildTop = childTop - containerTop + container.scrollTop;
|
48
|
-
container.scrollTo({
|
49
|
-
behavior,
|
50
|
-
top: scrollHeightToChildTop - margin
|
51
|
-
});
|
52
|
-
} else if (isChildBottomBelowViewingArea) {
|
53
|
-
const scrollHeightToChildBottom = childBottom - containerBottom + container.scrollTop;
|
54
|
-
container.scrollTo({
|
55
|
-
behavior,
|
56
|
-
top: scrollHeightToChildBottom + margin
|
57
|
-
});
|
58
|
-
} // either completely in view or outside viewing area on both ends, don't scroll
|
59
|
-
|
60
|
-
}
|
61
|
-
|
62
|
-
// TODO:
|
63
|
-
// insteaad of using `forwardRef`, just use a regular Functional Component
|
64
|
-
// get rid of unused props
|
65
|
-
const AutocompleteMenu = /*#__PURE__*/_react.default.forwardRef(({
|
66
|
-
selectableItems,
|
67
|
-
selectedItemIds,
|
68
|
-
selectedSortFn,
|
69
|
-
onItemSelect,
|
70
|
-
onItemDeselect,
|
71
|
-
emptyStateText,
|
72
|
-
addNewItem,
|
73
|
-
onCloseOptionsList,
|
74
|
-
loading
|
75
|
-
}, ref) => {
|
76
|
-
const {
|
77
|
-
activeDescendantRef,
|
78
|
-
filterFn,
|
79
|
-
inputRef,
|
80
|
-
inputValue,
|
81
|
-
showMenu,
|
82
|
-
setAutocompleteSuggestion,
|
83
|
-
setShowMenu,
|
84
|
-
setInputValue
|
85
|
-
} = (0, _react.useContext)(_AutocompleteContext.AutocompleteContext);
|
86
|
-
const listContainerRef = (0, _react.useRef)(null);
|
87
|
-
const scrollContainerRef = (0, _react.useRef)(null);
|
88
|
-
const [highlightedItem, setHighlightedItem] = (0, _react.useState)(); // TODO: clean up this mess by making id required on ItemProps
|
89
|
-
|
90
|
-
const [sortedItemIds, setSortedItemIds] = (0, _react.useState)(selectableItems.map(({
|
91
|
-
id
|
92
|
-
}) => id || id === 0 ? id : ''));
|
93
|
-
const {
|
94
|
-
floatingElementRef,
|
95
|
-
position
|
96
|
-
} = (0, _hooks.useAnchoredPosition)({
|
97
|
-
side: 'outside-bottom',
|
98
|
-
align: 'start',
|
99
|
-
anchorElementRef: inputRef
|
100
|
-
}, [showMenu, selectedItemIds]); // TODO: replace this with the fn from the AutocompleteContext
|
101
|
-
|
102
|
-
const closeOptionList = () => {
|
103
|
-
if (setShowMenu) {
|
104
|
-
setShowMenu(false);
|
105
|
-
}
|
106
|
-
|
107
|
-
if (onCloseOptionsList) {
|
108
|
-
onCloseOptionsList();
|
109
|
-
}
|
110
|
-
};
|
111
|
-
|
112
|
-
const isItemSelected = itemId => {
|
113
|
-
var _selectableItems$find;
|
114
|
-
|
115
|
-
return ((_selectableItems$find = selectableItems.find(selectableItem => selectableItem.id === itemId)) === null || _selectableItems$find === void 0 ? void 0 : _selectableItems$find.selected) || selectedItemIds.includes(itemId);
|
116
|
-
};
|
117
|
-
|
118
|
-
const itemsToRender = [// selectable tokens
|
119
|
-
...selectableItems.map(selectableItem => {
|
120
|
-
return { ...selectableItem,
|
121
|
-
//TODO: just make `id` required
|
122
|
-
selected: isItemSelected(selectableItem.id),
|
123
|
-
onAction: (item, e) => {
|
124
|
-
if (!item.selected) {
|
125
|
-
onItemSelect(item, e);
|
126
|
-
|
127
|
-
if (setInputValue) {
|
128
|
-
setInputValue('');
|
129
|
-
}
|
130
|
-
|
131
|
-
if (setAutocompleteSuggestion) {
|
132
|
-
setAutocompleteSuggestion('');
|
133
|
-
}
|
134
|
-
} else {
|
135
|
-
onItemDeselect(item, e);
|
136
|
-
}
|
137
|
-
}
|
138
|
-
};
|
139
|
-
}), // menu item used for creating a token from whatever is in the text input
|
140
|
-
...(addNewItem ? [{ ...addNewItem,
|
141
|
-
onAction: (_item, e) => {
|
142
|
-
onItemSelect({
|
143
|
-
text: inputValue,
|
144
|
-
id: `randomlyGeneratedId-${inputValue}`
|
145
|
-
}, e);
|
146
|
-
}
|
147
|
-
}] : [])];
|
148
|
-
(0, _useFocusZone.useFocusZone)({
|
149
|
-
containerRef: listContainerRef,
|
150
|
-
focusOutBehavior: 'wrap',
|
151
|
-
focusableElementFilter: element => {
|
152
|
-
return !(element instanceof HTMLInputElement);
|
153
|
-
},
|
154
|
-
activeDescendantFocus: inputRef,
|
155
|
-
onActiveDescendantChanged: (current, _previous, directlyActivated) => {
|
156
|
-
if (activeDescendantRef && current) {
|
157
|
-
activeDescendantRef.current = current;
|
158
|
-
}
|
159
|
-
|
160
|
-
const selectedItem = itemsToRender.find(item => {
|
161
|
-
var _item$id;
|
162
|
-
|
163
|
-
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);
|
164
|
-
});
|
165
|
-
setHighlightedItem(selectedItem);
|
166
|
-
|
167
|
-
if (current && scrollContainerRef.current && directlyActivated) {
|
168
|
-
scrollIntoViewingArea(current, scrollContainerRef.current);
|
169
|
-
}
|
170
|
-
}
|
171
|
-
});
|
172
|
-
(0, _react.useEffect)(() => {
|
173
|
-
var _highlightedItem$text;
|
174
|
-
|
175
|
-
if (!setAutocompleteSuggestion) {
|
176
|
-
return;
|
177
|
-
}
|
178
|
-
|
179
|
-
if (inputValue && highlightedItem !== null && highlightedItem !== void 0 && (_highlightedItem$text = highlightedItem.text) !== null && _highlightedItem$text !== void 0 && _highlightedItem$text.startsWith(inputValue)) {
|
180
|
-
setAutocompleteSuggestion(highlightedItem.text);
|
181
|
-
} else {
|
182
|
-
setAutocompleteSuggestion('');
|
183
|
-
}
|
184
|
-
}, [highlightedItem, inputValue]);
|
185
|
-
(0, _react.useEffect)(() => {
|
186
|
-
setSortedItemIds([...sortedItemIds].sort(selectedSortFn ? selectedSortFn : getDefaultSortFn(isItemSelected)));
|
187
|
-
}, [showMenu]);
|
188
|
-
|
189
|
-
if (listContainerRef.current) {
|
190
|
-
(0, _Portal.registerPortalRoot)(listContainerRef.current, DROPDOWN_PORTAL_CONTAINER_NAME);
|
191
|
-
}
|
192
|
-
|
193
|
-
const itemSortOrderData = sortedItemIds.reduce((acc, curr, i) => {
|
194
|
-
acc[curr] = i;
|
195
|
-
return acc;
|
196
|
-
}, {});
|
197
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
198
|
-
ref: listContainerRef
|
199
|
-
}, showMenu && emptyStateText ? /*#__PURE__*/_react.default.createElement(_Overlay.default, {
|
200
|
-
returnFocusRef: inputRef,
|
201
|
-
portalContainerName: DROPDOWN_PORTAL_CONTAINER_NAME,
|
202
|
-
preventFocusOnOpen: true,
|
203
|
-
onClickOutside: closeOptionList,
|
204
|
-
onEscape: closeOptionList,
|
205
|
-
ref: floatingElementRef,
|
206
|
-
top: position === null || position === void 0 ? void 0 : position.top,
|
207
|
-
left: position === null || position === void 0 ? void 0 : position.left
|
208
|
-
}, loading ? /*#__PURE__*/_react.default.createElement(_.Box, {
|
209
|
-
p: 3,
|
210
|
-
display: "flex",
|
211
|
-
justifyContent: "center"
|
212
|
-
}, /*#__PURE__*/_react.default.createElement(_.Spinner, null)) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, itemsToRender.length ? /*#__PURE__*/_react.default.createElement(_ActionList.ActionList, {
|
213
|
-
selectionVariant: "multiple",
|
214
|
-
items: [...(filterFn ? itemsToRender.filter(filterFn) : itemsToRender)].sort((a, b) => itemSortOrderData[a.id] - itemSortOrderData[b.id]),
|
215
|
-
role: "listbox"
|
216
|
-
}) : /*#__PURE__*/_react.default.createElement(_.Box, {
|
217
|
-
p: 3
|
218
|
-
}, emptyStateText))) : null);
|
219
|
-
});
|
220
|
-
|
221
|
-
AutocompleteMenu.defaultProps = {
|
222
|
-
emptyStateText: 'No selectable options'
|
223
|
-
};
|
224
|
-
AutocompleteMenu.displayName = 'AutocompleteMenu';
|
225
|
-
var _default = AutocompleteMenu;
|
226
|
-
exports.default = _default;
|