@primer/components 0.0.0-2021829202552 → 0.0.0-2021829233555
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 +250 -290
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +318 -358
- package/dist/browser.umd.js.map +1 -1
- package/lib/FilteredActionList/FilteredActionList.js +31 -6
- 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/hooks/useOverlay.d.ts +1 -2
- package/lib/hooks/useOverlay.js +6 -11
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -16
- package/lib/utils/types.d.ts +0 -3
- package/lib-esm/FilteredActionList/FilteredActionList.js +31 -4
- 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-esm/hooks/useOverlay.d.ts +1 -2
- package/lib-esm/hooks/useOverlay.js +6 -11
- package/lib-esm/index.d.ts +0 -2
- package/lib-esm/index.js +0 -2
- package/lib-esm/utils/types.d.ts +0 -3
- package/package.json +4 -7
- package/lib/Autocomplete/Autocomplete.d.ts +0 -31
- package/lib/Autocomplete/Autocomplete.js +0 -60
- package/lib/Autocomplete/AutocompleteContext.d.ts +0 -14
- package/lib/Autocomplete/AutocompleteContext.js +0 -11
- package/lib/Autocomplete/AutocompleteInput.d.ts +0 -9
- package/lib/Autocomplete/AutocompleteInput.js +0 -148
- package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -70
- package/lib/Autocomplete/AutocompleteMenu.js +0 -252
- package/lib/Autocomplete/index.d.ts +0 -2
- package/lib/Autocomplete/index.js +0 -15
- 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 -43
- package/lib/TextInputTokens.js +0 -237
- package/lib/Token/Token.d.ts +0 -14
- package/lib/Token/Token.js +0 -75
- package/lib/Token/TokenBase.d.ts +0 -16
- package/lib/Token/TokenBase.js +0 -90
- package/lib/Token/TokenLabel.d.ts +0 -14
- package/lib/Token/TokenLabel.js +0 -135
- package/lib/Token/TokenProfile.d.ts +0 -7
- package/lib/Token/TokenProfile.js +0 -50
- package/lib/Token/_RemoveTokenButton.d.ts +0 -3
- package/lib/Token/_RemoveTokenButton.js +0 -45
- 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 -31
- package/lib-esm/Autocomplete/Autocomplete.js +0 -40
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -14
- package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -9
- package/lib-esm/Autocomplete/AutocompleteInput.js +0 -129
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -70
- package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -226
- package/lib-esm/Autocomplete/index.d.ts +0 -2
- package/lib-esm/Autocomplete/index.js +0 -1
- 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 -43
- package/lib-esm/TextInputTokens.js +0 -210
- package/lib-esm/Token/Token.d.ts +0 -14
- package/lib-esm/Token/Token.js +0 -56
- package/lib-esm/Token/TokenBase.d.ts +0 -16
- package/lib-esm/Token/TokenBase.js +0 -70
- package/lib-esm/Token/TokenLabel.d.ts +0 -14
- package/lib-esm/Token/TokenLabel.js +0 -115
- package/lib-esm/Token/TokenProfile.d.ts +0 -7
- package/lib-esm/Token/TokenProfile.js +0 -29
- package/lib-esm/Token/_RemoveTokenButton.d.ts +0 -3
- package/lib-esm/Token/_RemoveTokenButton.js +0 -30
- 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
package/lib-esm/index.d.ts
CHANGED
@@ -24,7 +24,6 @@ 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';
|
28
27
|
export { default as Avatar } from './Avatar';
|
29
28
|
export type { AvatarProps } from './Avatar';
|
30
29
|
export { default as AvatarPair } from './AvatarPair';
|
@@ -99,7 +98,6 @@ export { default as TabNav } from './TabNav';
|
|
99
98
|
export type { TabNavProps, TabNavLinkProps } from './TabNav';
|
100
99
|
export { default as TextInput } from './TextInput';
|
101
100
|
export type { TextInputProps } from './TextInput';
|
102
|
-
export { default as TextInputWithTokens } from './TextInputTokens';
|
103
101
|
export { default as Text } from './Text';
|
104
102
|
export type { TextProps } from './Text';
|
105
103
|
export { default as Timeline } from './Timeline';
|
package/lib-esm/index.js
CHANGED
@@ -19,7 +19,6 @@ export { useConfirm } from './Dialog/ConfirmationDialog'; // Components
|
|
19
19
|
|
20
20
|
export { ActionList } from './ActionList';
|
21
21
|
export { ActionMenu } from './ActionMenu';
|
22
|
-
export { default as Autocomplete } from './Autocomplete';
|
23
22
|
export { default as Avatar } from './Avatar';
|
24
23
|
export { default as AvatarPair } from './AvatarPair';
|
25
24
|
export { default as AvatarStack } from './AvatarStack';
|
@@ -62,7 +61,6 @@ export { default as StyledOcticon } from './StyledOcticon';
|
|
62
61
|
export { default as SubNav } from './SubNav';
|
63
62
|
export { default as TabNav } from './TabNav';
|
64
63
|
export { default as TextInput } from './TextInput';
|
65
|
-
export { default as TextInputWithTokens } from './TextInputTokens';
|
66
64
|
export { default as Text } from './Text';
|
67
65
|
export { default as Timeline } from './Timeline';
|
68
66
|
export { default as Tooltip } from './Tooltip';
|
package/lib-esm/utils/types.d.ts
CHANGED
@@ -12,6 +12,3 @@ export declare type ComponentProps<T> = T extends React.ComponentType<infer Prop
|
|
12
12
|
*/
|
13
13
|
export declare type Flatten<T extends unknown> = T extends (infer U)[] ? U : never;
|
14
14
|
export declare type AriaRole = 'alert' | 'alertdialog' | 'application' | 'article' | 'banner' | 'button' | 'cell' | 'checkbox' | 'columnheader' | 'combobox' | 'complementary' | 'contentinfo' | 'definition' | 'dialog' | 'directory' | 'document' | 'feed' | 'figure' | 'form' | 'grid' | 'gridcell' | 'group' | 'heading' | 'img' | 'link' | 'list' | 'listbox' | 'listitem' | 'log' | 'main' | 'marquee' | 'math' | 'menu' | 'menubar' | 'menuitem' | 'menuitemcheckbox ' | 'menuitemradio' | 'navigation' | 'none' | 'note' | 'option' | 'presentation' | 'progressbar' | 'radio' | 'radiogroup' | 'region' | 'row' | 'rowgroup' | 'rowheader' | 'scrollbar' | 'search' | 'searchbox' | 'separator' | 'slider' | 'spinbutton' | 'status' | 'switch' | 'tab' | 'table' | 'tablist' | 'tabpanel' | 'term' | 'textbox' | 'timer' | 'toolbar' | 'tooltip' | 'tree' | 'treegrid' | 'treeitem';
|
15
|
-
export declare type MandateProps<T extends {}, K extends keyof T> = Omit<T, K> & {
|
16
|
-
[MK in K]-?: NonNullable<T[MK]>;
|
17
|
-
};
|
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-2021829233555",
|
4
4
|
"description": "Primer react components",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"module": "lib-esm/index.js",
|
@@ -45,7 +45,6 @@
|
|
45
45
|
"dependencies": {
|
46
46
|
"@primer/octicons-react": "^13.0.0",
|
47
47
|
"@primer/primitives": "4.8.1",
|
48
|
-
"@radix-ui/react-polymorphic": "0.0.14",
|
49
48
|
"@react-aria/ssr": "3.1.0",
|
50
49
|
"@styled-system/css": "5.1.5",
|
51
50
|
"@styled-system/props": "5.1.5",
|
@@ -58,8 +57,7 @@
|
|
58
57
|
"classnames": "2.3.1",
|
59
58
|
"deepmerge": "4.2.2",
|
60
59
|
"focus-visible": "5.2.0",
|
61
|
-
"styled-system": "5.1.5"
|
62
|
-
"tinycolor2": "1.4.2"
|
60
|
+
"styled-system": "5.1.5"
|
63
61
|
},
|
64
62
|
"devDependencies": {
|
65
63
|
"@babel/cli": "7.14.5",
|
@@ -69,7 +67,7 @@
|
|
69
67
|
"@babel/plugin-proposal-optional-chaining": "7.14.5",
|
70
68
|
"@babel/plugin-transform-modules-commonjs": "7.14.5",
|
71
69
|
"@babel/preset-react": "7.14.5",
|
72
|
-
"@babel/preset-typescript": "7.
|
70
|
+
"@babel/preset-typescript": "7.15.0",
|
73
71
|
"@changesets/changelog-github": "0.4.0",
|
74
72
|
"@changesets/cli": "2.17.0",
|
75
73
|
"@github/prettier-config": "0.0.4",
|
@@ -87,11 +85,10 @@
|
|
87
85
|
"@testing-library/user-event": "13.1.9",
|
88
86
|
"@types/chroma-js": "2.1.3",
|
89
87
|
"@types/enzyme": "3.10.9",
|
90
|
-
"@types/jest": "
|
88
|
+
"@types/jest": "27.0.2",
|
91
89
|
"@types/jest-axe": "3.5.3",
|
92
90
|
"@types/lodash.isempty": "4.4.6",
|
93
91
|
"@types/lodash.isobject": "3.0.6",
|
94
|
-
"@types/tinycolor2": "1.4.3",
|
95
92
|
"@typescript-eslint/eslint-plugin": "4.31.2",
|
96
93
|
"@typescript-eslint/parser": "4.26.1",
|
97
94
|
"@wojtekmaj/enzyme-adapter-react-17": "0.6.3",
|
@@ -1,31 +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
|
-
declare const _default: React.FC<{
|
11
|
-
id?: string | undefined;
|
12
|
-
}> & {
|
13
|
-
AutocompleteContext: React.Context<{
|
14
|
-
activeDescendantRef?: React.MutableRefObject<HTMLElement | null> | undefined;
|
15
|
-
autocompleteSuggestion?: string | undefined;
|
16
|
-
id?: string | undefined;
|
17
|
-
inputRef?: React.MutableRefObject<HTMLInputElement | null> | undefined;
|
18
|
-
inputValue?: string | undefined;
|
19
|
-
isMenuDirectlyActivated?: boolean | undefined;
|
20
|
-
setAutocompleteSuggestion?: React.Dispatch<React.SetStateAction<string>> | undefined;
|
21
|
-
setInputValue?: React.Dispatch<React.SetStateAction<string>> | undefined;
|
22
|
-
setIsMenuDirectlyActivated?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
|
23
|
-
setShowMenu?: React.Dispatch<React.SetStateAction<boolean>> | undefined;
|
24
|
-
showMenu?: boolean | undefined;
|
25
|
-
}>;
|
26
|
-
Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<"input", {
|
27
|
-
as?: React.ComponentType<any> | undefined;
|
28
|
-
}>;
|
29
|
-
Menu: typeof AutocompleteMenu;
|
30
|
-
};
|
31
|
-
export default _default;
|
@@ -1,60 +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 _uniqueId = require("../utils/uniqueId");
|
11
|
-
|
12
|
-
var _AutocompleteContext = require("./AutocompleteContext");
|
13
|
-
|
14
|
-
var _AutocompleteInput = _interopRequireDefault(require("./AutocompleteInput"));
|
15
|
-
|
16
|
-
var _AutocompleteMenu = _interopRequireDefault(require("./AutocompleteMenu"));
|
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
|
-
const Autocomplete = ({
|
25
|
-
children,
|
26
|
-
id: idProp
|
27
|
-
}) => {
|
28
|
-
const activeDescendantRef = (0, _react.useRef)(null);
|
29
|
-
const inputRef = (0, _react.useRef)(null);
|
30
|
-
const [inputValue, setInputValue] = (0, _react.useState)('');
|
31
|
-
const [showMenu, setShowMenu] = (0, _react.useState)(false);
|
32
|
-
const [autocompleteSuggestion, setAutocompleteSuggestion] = (0, _react.useState)('');
|
33
|
-
const [isMenuDirectlyActivated, setIsMenuDirectlyActivated] = (0, _react.useState)(false);
|
34
|
-
const id = idProp || (0, _uniqueId.uniqueId)();
|
35
|
-
return /*#__PURE__*/_react.default.createElement(_AutocompleteContext.AutocompleteContext.Provider, {
|
36
|
-
value: {
|
37
|
-
activeDescendantRef,
|
38
|
-
autocompleteSuggestion,
|
39
|
-
id,
|
40
|
-
inputRef,
|
41
|
-
inputValue,
|
42
|
-
isMenuDirectlyActivated,
|
43
|
-
setAutocompleteSuggestion,
|
44
|
-
setInputValue,
|
45
|
-
setIsMenuDirectlyActivated,
|
46
|
-
setShowMenu,
|
47
|
-
showMenu
|
48
|
-
}
|
49
|
-
}, children);
|
50
|
-
};
|
51
|
-
|
52
|
-
Autocomplete.displayName = "Autocomplete";
|
53
|
-
|
54
|
-
var _default = Object.assign(Autocomplete, {
|
55
|
-
AutocompleteContext: _AutocompleteContext.AutocompleteContext,
|
56
|
-
Input: _AutocompleteInput.default,
|
57
|
-
Menu: _AutocompleteMenu.default
|
58
|
-
});
|
59
|
-
|
60
|
-
exports.default = _default;
|
@@ -1,14 +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
|
-
setAutocompleteSuggestion?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
|
10
|
-
setInputValue?: import("react").Dispatch<import("react").SetStateAction<string>> | undefined;
|
11
|
-
setIsMenuDirectlyActivated?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
|
12
|
-
setShowMenu?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
|
13
|
-
showMenu?: boolean | undefined;
|
14
|
-
}>;
|
@@ -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,9 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import type * as Polymorphic 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: Polymorphic.ForwardRefComponent<"input", InternalAutocompleteInputProps>;
|
8
|
-
export declare type AutocompleteInputProps = ComponentProps<typeof AutocompleteInput>;
|
9
|
-
export default AutocompleteInput;
|
@@ -1,148 +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
|
-
onBlur,
|
28
|
-
onChange,
|
29
|
-
onKeyDown,
|
30
|
-
onKeyPress,
|
31
|
-
value,
|
32
|
-
...props
|
33
|
-
}, forwardedRef) => {
|
34
|
-
const {
|
35
|
-
activeDescendantRef,
|
36
|
-
autocompleteSuggestion = '',
|
37
|
-
id,
|
38
|
-
inputRef,
|
39
|
-
inputValue = '',
|
40
|
-
isMenuDirectlyActivated,
|
41
|
-
setInputValue,
|
42
|
-
setShowMenu,
|
43
|
-
showMenu
|
44
|
-
} = (0, _react.useContext)(_AutocompleteContext.AutocompleteContext);
|
45
|
-
const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(inputRef, forwardedRef);
|
46
|
-
const [highlightRemainingText, setHighlightRemainingText] = (0, _react.useState)(true);
|
47
|
-
|
48
|
-
const handleInputFocus = e => {
|
49
|
-
onFocus && onFocus(e);
|
50
|
-
setShowMenu && setShowMenu(true);
|
51
|
-
};
|
52
|
-
|
53
|
-
const handleInputBlur = e => {
|
54
|
-
onBlur && onBlur(e); // HACK: wait a tick and check the focused element before hiding the autocomplete menu
|
55
|
-
// this prevents the menu from hiding when the user is clicking an option in the Autoselect.Menu,
|
56
|
-
// but still hides the menu when the user blurs the input by tabbing out or clicking somewhere else on the page
|
57
|
-
// COLEHELP
|
58
|
-
|
59
|
-
setTimeout(() => {
|
60
|
-
if (document.activeElement !== combinedInputRef.current) {
|
61
|
-
setShowMenu && setShowMenu(false);
|
62
|
-
}
|
63
|
-
}, 0);
|
64
|
-
};
|
65
|
-
|
66
|
-
const handleInputChange = e => {
|
67
|
-
onChange && onChange(e);
|
68
|
-
setInputValue && setInputValue(e.currentTarget.value);
|
69
|
-
|
70
|
-
if (!showMenu) {
|
71
|
-
setShowMenu && setShowMenu(true);
|
72
|
-
}
|
73
|
-
};
|
74
|
-
|
75
|
-
const handleInputKeyDown = e => {
|
76
|
-
var _inputRef$current;
|
77
|
-
|
78
|
-
if (e.key === 'Backspace') {
|
79
|
-
setHighlightRemainingText(false);
|
80
|
-
}
|
81
|
-
|
82
|
-
if (e.key === 'Escape' && inputRef !== null && inputRef !== void 0 && (_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.value) {
|
83
|
-
setInputValue && setInputValue('');
|
84
|
-
inputRef.current.value = '';
|
85
|
-
}
|
86
|
-
};
|
87
|
-
|
88
|
-
const handleInputKeyUp = e => {
|
89
|
-
if (e.key === 'Backspace') {
|
90
|
-
setHighlightRemainingText(true);
|
91
|
-
}
|
92
|
-
};
|
93
|
-
|
94
|
-
const onInputKeyPress = (0, _react.useCallback)(event => {
|
95
|
-
if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
|
96
|
-
event.preventDefault();
|
97
|
-
event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
|
98
|
-
|
99
|
-
const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
|
100
|
-
activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
|
101
|
-
}
|
102
|
-
}, [activeDescendantRef]);
|
103
|
-
(0, _react.useEffect)(() => {
|
104
|
-
if (!(inputRef !== null && inputRef !== void 0 && inputRef.current)) {
|
105
|
-
return;
|
106
|
-
} // resets input value to being empty after a selection has been made
|
107
|
-
|
108
|
-
|
109
|
-
if (!autocompleteSuggestion) {
|
110
|
-
inputRef.current.value = inputValue;
|
111
|
-
} // TODO: fix bug where this function prevents `onChange` from being triggered if the highlighted item text
|
112
|
-
// is the same as what I'm typing
|
113
|
-
// e.g.: typing 'tw' highights 'two', but when I 'two', the text input change does not get triggered
|
114
|
-
// COLEHELP
|
115
|
-
|
116
|
-
|
117
|
-
if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
|
118
|
-
inputRef.current.value = autocompleteSuggestion;
|
119
|
-
|
120
|
-
if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
|
121
|
-
inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
|
122
|
-
}
|
123
|
-
}
|
124
|
-
}, [autocompleteSuggestion, inputValue]);
|
125
|
-
(0, _react.useEffect)(() => {
|
126
|
-
if (value) {
|
127
|
-
setInputValue && setInputValue(value.toString());
|
128
|
-
}
|
129
|
-
}, [value]);
|
130
|
-
return /*#__PURE__*/_react.default.createElement(Component, _extends({
|
131
|
-
onFocus: handleInputFocus,
|
132
|
-
onBlur: handleInputBlur,
|
133
|
-
onChange: handleInputChange,
|
134
|
-
onKeyDown: handleInputKeyDown,
|
135
|
-
onKeyPress: onInputKeyPress,
|
136
|
-
onKeyUp: handleInputKeyUp,
|
137
|
-
ref: combinedInputRef,
|
138
|
-
"aria-controls": `${id}-listbox`,
|
139
|
-
"aria-autocomplete": "both",
|
140
|
-
role: "combobox",
|
141
|
-
"aria-expanded": showMenu,
|
142
|
-
"aria-haspopup": "listbox",
|
143
|
-
"aria-owns": `${id}-listbox`
|
144
|
-
}, props));
|
145
|
-
});
|
146
|
-
|
147
|
-
var _default = AutocompleteInput;
|
148
|
-
exports.default = _default;
|
@@ -1,70 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { ItemProps } from '../ActionList';
|
3
|
-
import { OverlayProps } from '../Overlay';
|
4
|
-
import { ComponentProps, MandateProps } from '../utils/types';
|
5
|
-
declare type OnAction<T> = (item: T, event: React.MouseEvent<HTMLDivElement> | React.KeyboardEvent<HTMLDivElement>) => void;
|
6
|
-
declare type AutocompleteItemProps<T = Record<string, any>> = MandateProps<ItemProps, 'id'> & {
|
7
|
-
metadata?: T;
|
8
|
-
};
|
9
|
-
declare type AutocompleteMenuInternalProps<T extends AutocompleteItemProps> = {
|
10
|
-
/**
|
11
|
-
* A menu item that is used to allow users make a selection that is not available in the array passed to the `items` prop.
|
12
|
-
* This menu item gets appended to the end of the list of options.
|
13
|
-
*/
|
14
|
-
addNewItem?: Omit<T, 'onAction' | 'leadingVisual' | 'id'> & {
|
15
|
-
handleAddItem: (item: Omit<T, 'onAction' | 'leadingVisual'>) => void;
|
16
|
-
};
|
17
|
-
/**
|
18
|
-
* The text that appears in the menu when there are no options in the array passed to the `items` prop.
|
19
|
-
*/
|
20
|
-
emptyStateText?: React.ReactNode | false;
|
21
|
-
/**
|
22
|
-
* A custom function used to filter the options in the array passed to the `items` prop.
|
23
|
-
* By default, we filter out items that don't match the value of the autocomplete text input. The default filter is not case-sensitive.
|
24
|
-
*/
|
25
|
-
filterFn?: (item: T, i: number) => boolean;
|
26
|
-
/**
|
27
|
-
* The options for field values that are displayed in the dropdown menu.
|
28
|
-
* One or more may be selected depending on the value of the `selectionVariant` prop.
|
29
|
-
*/
|
30
|
-
items: T[];
|
31
|
-
/**
|
32
|
-
* The function that is called when an item in the list is de-selected
|
33
|
-
*/
|
34
|
-
onItemDeselect?: OnAction<T>;
|
35
|
-
/**
|
36
|
-
* The function that is called when an item in the list is selected
|
37
|
-
*/
|
38
|
-
onItemSelect?: OnAction<T>;
|
39
|
-
/**
|
40
|
-
* Whether the data is loaded for the menu items
|
41
|
-
*/
|
42
|
-
loading?: boolean;
|
43
|
-
/**
|
44
|
-
* The IDs of the selected items
|
45
|
-
*/
|
46
|
-
selectedItemIds: Array<string | number>;
|
47
|
-
/**
|
48
|
-
* The sort function that is applied to the options in the array passed to the `items` prop after the user closes the menu.
|
49
|
-
* By default, selected items are sorted to the top after the user closes the menu.
|
50
|
-
*/
|
51
|
-
sortOnCloseFn?: (itemIdA: string | number, itemIdB: string | number) => number;
|
52
|
-
/**
|
53
|
-
* Whether there can be one item selected from the menu or multiple items selected from the menu
|
54
|
-
*/
|
55
|
-
selectionVariant?: 'single' | 'multiple';
|
56
|
-
/**
|
57
|
-
* 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
|
58
|
-
*/
|
59
|
-
menuAnchorRef?: React.RefObject<Element>;
|
60
|
-
} & Pick<React.AriaAttributes, 'aria-labelledby'>;
|
61
|
-
declare function AutocompleteMenu<T extends AutocompleteItemProps>(props: AutocompleteMenuInternalProps<T> & Pick<OverlayProps, 'width' | 'height' | 'maxHeight'>): JSX.Element;
|
62
|
-
declare namespace AutocompleteMenu {
|
63
|
-
var defaultProps: {
|
64
|
-
emptyStateText: string;
|
65
|
-
selectionVariant: string;
|
66
|
-
};
|
67
|
-
var displayName: string;
|
68
|
-
}
|
69
|
-
export declare type AutocompleteMenuProps = ComponentProps<typeof AutocompleteMenu>;
|
70
|
-
export default AutocompleteMenu;
|