@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.
Files changed (96) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/browser.esm.js +295 -299
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +358 -362
  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/SelectMenu/SelectMenu.d.ts +2 -8
  12. package/lib/TextInput.d.ts +3 -6
  13. package/lib/TextInput.js +10 -9
  14. package/{lib-esm/Token/TokenLabel.d.ts → lib/Token/LabelToken.d.ts} +3 -3
  15. package/lib/Token/{TokenLabel.js → LabelToken.js} +23 -23
  16. package/lib/Token/Token.d.ts +2 -2
  17. package/lib/Token/Token.js +13 -13
  18. package/lib/Token/TokenBase.d.ts +3 -3
  19. package/lib/Token/TokenBase.js +17 -16
  20. package/lib/Token/TokenProfile.d.ts +1 -1
  21. package/lib/Token/TokenProfile.js +3 -3
  22. package/lib/Token/_RemoveTokenButton.d.ts +7 -1
  23. package/lib/Token/_RemoveTokenButton.js +40 -11
  24. package/lib/Token/index.d.ts +1 -1
  25. package/lib/Token/index.js +3 -3
  26. package/lib/hooks/useOverlay.d.ts +1 -2
  27. package/lib/hooks/useOverlay.js +6 -11
  28. package/lib/index.d.ts +1 -3
  29. package/lib/index.js +2 -18
  30. package/lib/utils/types.d.ts +0 -3
  31. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
  32. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -11
  33. package/lib-esm/FilteredActionList/FilteredActionList.js +31 -3
  34. package/lib-esm/Overlay.d.ts +1 -2
  35. package/lib-esm/Overlay.js +5 -8
  36. package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -8
  37. package/lib-esm/TextInput.d.ts +3 -6
  38. package/lib-esm/TextInput.js +9 -8
  39. package/{lib/Token/TokenLabel.d.ts → lib-esm/Token/LabelToken.d.ts} +3 -3
  40. package/lib-esm/Token/{TokenLabel.js → LabelToken.js} +23 -23
  41. package/lib-esm/Token/Token.d.ts +2 -2
  42. package/lib-esm/Token/Token.js +13 -13
  43. package/lib-esm/Token/TokenBase.d.ts +3 -3
  44. package/lib-esm/Token/TokenBase.js +17 -16
  45. package/lib-esm/Token/TokenProfile.d.ts +1 -1
  46. package/lib-esm/Token/TokenProfile.js +3 -3
  47. package/lib-esm/Token/_RemoveTokenButton.d.ts +7 -1
  48. package/lib-esm/Token/_RemoveTokenButton.js +36 -10
  49. package/lib-esm/Token/index.d.ts +1 -1
  50. package/lib-esm/Token/index.js +1 -1
  51. package/lib-esm/hooks/useOverlay.d.ts +1 -2
  52. package/lib-esm/hooks/useOverlay.js +6 -11
  53. package/lib-esm/index.d.ts +1 -3
  54. package/lib-esm/index.js +1 -3
  55. package/lib-esm/utils/types.d.ts +0 -3
  56. package/package.json +1 -1
  57. package/lib/Autocomplete/Autocomplete.d.ts +0 -40
  58. package/lib/Autocomplete/Autocomplete.js +0 -68
  59. package/lib/Autocomplete/AutocompleteContext.d.ts +0 -17
  60. package/lib/Autocomplete/AutocompleteContext.js +0 -11
  61. package/lib/Autocomplete/AutocompleteInput.d.ts +0 -9
  62. package/lib/Autocomplete/AutocompleteInput.js +0 -146
  63. package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -71
  64. package/lib/Autocomplete/AutocompleteMenu.js +0 -223
  65. package/lib/Autocomplete/AutocompleteOverlay.d.ts +0 -17
  66. package/lib/Autocomplete/AutocompleteOverlay.js +0 -71
  67. package/lib/Autocomplete/index.d.ts +0 -2
  68. package/lib/Autocomplete/index.js +0 -15
  69. package/lib/TextInputWithTokens.d.ts +0 -43
  70. package/lib/TextInputWithTokens.js +0 -236
  71. package/lib/Token/_tokenButtonUtils.d.ts +0 -10
  72. package/lib/Token/_tokenButtonUtils.js +0 -42
  73. package/lib/_UnstyledTextInput.d.ts +0 -2
  74. package/lib/_UnstyledTextInput.js +0 -20
  75. package/lib/utils/scrollIntoViewingArea.d.ts +0 -1
  76. package/lib/utils/scrollIntoViewingArea.js +0 -39
  77. package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -40
  78. package/lib-esm/Autocomplete/Autocomplete.js +0 -47
  79. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -17
  80. package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
  81. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -9
  82. package/lib-esm/Autocomplete/AutocompleteInput.js +0 -127
  83. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -71
  84. package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -202
  85. package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +0 -17
  86. package/lib-esm/Autocomplete/AutocompleteOverlay.js +0 -53
  87. package/lib-esm/Autocomplete/index.d.ts +0 -2
  88. package/lib-esm/Autocomplete/index.js +0 -1
  89. package/lib-esm/TextInputWithTokens.d.ts +0 -43
  90. package/lib-esm/TextInputWithTokens.js +0 -209
  91. package/lib-esm/Token/_tokenButtonUtils.d.ts +0 -10
  92. package/lib-esm/Token/_tokenButtonUtils.js +0 -26
  93. package/lib-esm/_UnstyledTextInput.d.ts +0 -2
  94. package/lib-esm/_UnstyledTextInput.js +0 -7
  95. package/lib-esm/utils/scrollIntoViewingArea.d.ts +0 -1
  96. package/lib-esm/utils/scrollIntoViewingArea.js +0 -30
@@ -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,12 +98,11 @@ 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 './TextInputWithTokens';
103
101
  export { default as Text } from './Text';
104
102
  export type { TextProps } from './Text';
105
103
  export { default as Timeline } from './Timeline';
106
104
  export type { TimelineProps, TimelineBadgeProps, TimelineBodyProps, TimelineBreakProps, TimelineItemsProps } from './Timeline';
107
- export { default as Token, TokenLabel, TokenProfile } from './Token';
105
+ export { default as Token, LabelToken, TokenProfile } from './Token';
108
106
  export { default as Tooltip } from './Tooltip';
109
107
  export type { TooltipProps } from './Tooltip';
110
108
  export { default as Truncate } from './Truncate';
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,10 +61,9 @@ 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 './TextInputWithTokens';
66
64
  export { default as Text } from './Text';
67
65
  export { default as Timeline } from './Timeline';
68
- export { default as Token, TokenLabel, TokenProfile } from './Token';
66
+ export { default as Token, LabelToken, TokenProfile } from './Token';
69
67
  export { default as Tooltip } from './Tooltip';
70
68
  export { default as Truncate } from './Truncate';
71
69
  export { default as UnderlineNav } from './UnderlineNav';
@@ -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-202194183411",
3
+ "version": "0.0.0-202194215436",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -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,68 +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
- var _AutocompleteOverlay = _interopRequireDefault(require("./AutocompleteOverlay"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- 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); }
23
-
24
- 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; }
25
-
26
- const Autocomplete = ({
27
- children,
28
- id: idProp
29
- }) => {
30
- const activeDescendantRef = (0, _react.useRef)(null);
31
- const scrollContainerRef = (0, _react.useRef)(null);
32
- const inputRef = (0, _react.useRef)(null);
33
- const [inputValue, setInputValue] = (0, _react.useState)('');
34
- const [showMenu, setShowMenu] = (0, _react.useState)(false);
35
- const [autocompleteSuggestion, setAutocompleteSuggestion] = (0, _react.useState)('');
36
- const [isMenuDirectlyActivated, setIsMenuDirectlyActivated] = (0, _react.useState)(false);
37
- const [selectedItemLength, setSelectedItemLength] = (0, _react.useState)();
38
- const id = idProp || (0, _uniqueId.uniqueId)();
39
- return /*#__PURE__*/_react.default.createElement(_AutocompleteContext.AutocompleteContext.Provider, {
40
- value: {
41
- activeDescendantRef,
42
- autocompleteSuggestion,
43
- id,
44
- inputRef,
45
- inputValue,
46
- isMenuDirectlyActivated,
47
- scrollContainerRef,
48
- selectedItemLength,
49
- setAutocompleteSuggestion,
50
- setInputValue,
51
- setIsMenuDirectlyActivated,
52
- setShowMenu,
53
- setSelectedItemLength,
54
- showMenu
55
- }
56
- }, children);
57
- };
58
-
59
- Autocomplete.displayName = "Autocomplete";
60
-
61
- var _default = Object.assign(Autocomplete, {
62
- AutocompleteContext: _AutocompleteContext.AutocompleteContext,
63
- Input: _AutocompleteInput.default,
64
- Menu: _AutocompleteMenu.default,
65
- Overlay: _AutocompleteOverlay.default
66
- });
67
-
68
- exports.default = _default;
@@ -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,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,146 +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
-
58
- setTimeout(() => {
59
- if (document.activeElement !== combinedInputRef.current) {
60
- setShowMenu && setShowMenu(false);
61
- }
62
- }, 0);
63
- };
64
-
65
- const handleInputChange = e => {
66
- onChange && onChange(e);
67
- setInputValue && setInputValue(e.currentTarget.value);
68
-
69
- if (!showMenu) {
70
- setShowMenu && setShowMenu(true);
71
- }
72
- };
73
-
74
- const handleInputKeyDown = e => {
75
- var _inputRef$current;
76
-
77
- if (e.key === 'Backspace') {
78
- setHighlightRemainingText(false);
79
- }
80
-
81
- if (e.key === 'Escape' && inputRef !== null && inputRef !== void 0 && (_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.value) {
82
- setInputValue && setInputValue('');
83
- inputRef.current.value = '';
84
- }
85
- };
86
-
87
- const handleInputKeyUp = e => {
88
- if (e.key === 'Backspace') {
89
- setHighlightRemainingText(true);
90
- }
91
- };
92
-
93
- const onInputKeyPress = (0, _react.useCallback)(event => {
94
- if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
95
- event.preventDefault();
96
- event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
97
-
98
- const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
99
- activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
100
- }
101
- }, [activeDescendantRef]);
102
- (0, _react.useEffect)(() => {
103
- if (!(inputRef !== null && inputRef !== void 0 && inputRef.current)) {
104
- return;
105
- } // resets input value to being empty after a selection has been made
106
-
107
-
108
- if (!autocompleteSuggestion) {
109
- inputRef.current.value = inputValue;
110
- } // TODO: fix bug where this function prevents `onChange` from being triggered if the highlighted item text
111
- // is the same as what I'm typing
112
- // e.g.: typing 'tw' highights 'two', but when I 'two', the text input change does not get triggered
113
-
114
-
115
- if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
116
- inputRef.current.value = autocompleteSuggestion;
117
-
118
- if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
119
- inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
120
- }
121
- }
122
- }, [autocompleteSuggestion, inputValue]);
123
- (0, _react.useEffect)(() => {
124
- if (value) {
125
- setInputValue && setInputValue(value.toString());
126
- }
127
- }, [value]);
128
- return /*#__PURE__*/_react.default.createElement(Component, _extends({
129
- onFocus: handleInputFocus,
130
- onBlur: handleInputBlur,
131
- onChange: handleInputChange,
132
- onKeyDown: handleInputKeyDown,
133
- onKeyPress: onInputKeyPress,
134
- onKeyUp: handleInputKeyUp,
135
- ref: combinedInputRef,
136
- "aria-controls": `${id}-listbox`,
137
- "aria-autocomplete": "both",
138
- role: "combobox",
139
- "aria-expanded": showMenu,
140
- "aria-haspopup": "listbox",
141
- "aria-owns": `${id}-listbox`
142
- }, props));
143
- });
144
-
145
- var _default = AutocompleteInput;
146
- exports.default = _default;
@@ -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,223 +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 _useFocusZone = require("../hooks/useFocusZone");
13
-
14
- var _ = require("../");
15
-
16
- var _Portal = require("../Portal");
17
-
18
- var _AutocompleteContext = require("./AutocompleteContext");
19
-
20
- var _octiconsReact = require("@primer/octicons-react");
21
-
22
- var _uniqueId = require("../utils/uniqueId");
23
-
24
- var _scrollIntoViewingArea = require("../utils/scrollIntoViewingArea");
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 getDefaultItemFilter(filterValue) {
35
- return function (item, _i) {
36
- var _item$text;
37
-
38
- return Boolean((_item$text = item.text) === null || _item$text === void 0 ? void 0 : _item$text.toLowerCase().startsWith(filterValue.toLowerCase()));
39
- };
40
- }
41
-
42
- const getDefaultOnSelectionChange = setInputValueFn => {
43
- return function (itemOrItems) {
44
- const {
45
- text = ''
46
- } = Array.isArray(itemOrItems) ? itemOrItems.slice(-1)[0] : itemOrItems;
47
- setInputValueFn && setInputValueFn(text);
48
- };
49
- };
50
-
51
- // TODO: consider making 'aria-labelledby' required
52
- function AutocompleteMenu(props) {
53
- const {
54
- activeDescendantRef,
55
- id,
56
- inputRef,
57
- inputValue = '',
58
- scrollContainerRef,
59
- setAutocompleteSuggestion,
60
- setShowMenu,
61
- setInputValue,
62
- setIsMenuDirectlyActivated,
63
- setSelectedItemLength,
64
- showMenu
65
- } = (0, _react.useContext)(_AutocompleteContext.AutocompleteContext);
66
- const {
67
- items,
68
- selectedItemIds,
69
- sortOnCloseFn,
70
- emptyStateText,
71
- addNewItem,
72
- loading,
73
- selectionVariant,
74
- filterFn = getDefaultItemFilter(inputValue),
75
- "aria-labelledby": ariaLabelledBy,
76
- onOpenChange,
77
- onSelectedChange = getDefaultOnSelectionChange(setInputValue),
78
- customScrollContainerRef
79
- } = props;
80
- const listContainerRef = (0, _react.useRef)(null);
81
- const [highlightedItem, setHighlightedItem] = (0, _react.useState)();
82
- const [sortedItemIds, setSortedItemIds] = (0, _react.useState)(items.map(({
83
- id
84
- }) => id));
85
-
86
- const isItemSelected = itemId => selectedItemIds.includes(itemId);
87
-
88
- const getItemById = itemId => items.find(item => item.id === itemId);
89
-
90
- const selectableItems = items.map(selectableItem => {
91
- return { ...selectableItem,
92
- role: "option",
93
- id: selectableItem.id,
94
- selected: selectionVariant === 'multiple' ? selectedItemIds.includes(selectableItem.id) : undefined,
95
- onAction: item => {
96
- const otherSelectedItemIds = selectedItemIds.filter(selectedItemId => selectedItemId !== item.id);
97
- const newSelectedItemIds = selectedItemIds.includes(item.id) ? otherSelectedItemIds : [...otherSelectedItemIds, item.id];
98
- onSelectedChange && onSelectedChange(newSelectedItemIds.map(getItemById));
99
-
100
- if (selectionVariant === 'multiple') {
101
- setInputValue && setInputValue('');
102
- setAutocompleteSuggestion && setAutocompleteSuggestion('');
103
- } else {
104
- var _inputRef$current;
105
-
106
- setShowMenu && setShowMenu(false);
107
- 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);
108
- }
109
- }
110
- };
111
- });
112
- const itemSortOrderData = sortedItemIds.reduce((acc, curr, i) => {
113
- acc[curr] = i;
114
- return acc;
115
- }, {});
116
- const sortedAndFilteredItemsToRender = selectableItems.filter((item, i) => filterFn(item, i)).sort((a, b) => itemSortOrderData[a.id] - itemSortOrderData[b.id]);
117
- const allItemsToRender = [// sorted and filtered selectable items
118
- ...sortedAndFilteredItemsToRender, // menu item used for creating a token from whatever is in the text input
119
- ...(addNewItem ? [{ ...addNewItem,
120
- leadingVisual: () => /*#__PURE__*/_react.default.createElement(_octiconsReact.PlusIcon, null),
121
- onAction: (item, e) => {
122
- // TODO: make it possible to pass a leadingVisual when using `addNewItem`
123
- addNewItem.handleAddItem({ ...item,
124
- id: item.id || (0, _uniqueId.uniqueId)(),
125
- leadingVisual: undefined
126
- });
127
-
128
- if (selectionVariant === 'multiple') {
129
- setInputValue && setInputValue('');
130
- setAutocompleteSuggestion && setAutocompleteSuggestion('');
131
- }
132
- }
133
- }] : [])];
134
- (0, _useFocusZone.useFocusZone)({
135
- containerRef: listContainerRef,
136
- focusOutBehavior: 'wrap',
137
- focusableElementFilter: element => {
138
- return !(element instanceof HTMLInputElement);
139
- },
140
- activeDescendantFocus: inputRef,
141
- onActiveDescendantChanged: (current, _previous, directlyActivated) => {
142
- if (activeDescendantRef) {
143
- activeDescendantRef.current = current || null;
144
- }
145
-
146
- if (current) {
147
- const selectedItem = selectableItems.find(item => item.id.toString() === (current === null || current === void 0 ? void 0 : current.dataset.id));
148
- setHighlightedItem(selectedItem);
149
- setIsMenuDirectlyActivated && setIsMenuDirectlyActivated(directlyActivated);
150
- }
151
-
152
- if (current && customScrollContainerRef && customScrollContainerRef.current && directlyActivated) {
153
- (0, _scrollIntoViewingArea.scrollIntoViewingArea)(current, customScrollContainerRef.current);
154
- } else if (current && scrollContainerRef && scrollContainerRef.current && directlyActivated) {
155
- (0, _scrollIntoViewingArea.scrollIntoViewingArea)(current, scrollContainerRef.current);
156
- }
157
- }
158
- }, [loading]);
159
- (0, _react.useEffect)(() => {
160
- var _highlightedItem$text;
161
-
162
- if (!setAutocompleteSuggestion) {
163
- return;
164
- }
165
-
166
- if (highlightedItem !== null && highlightedItem !== void 0 && (_highlightedItem$text = highlightedItem.text) !== null && _highlightedItem$text !== void 0 && _highlightedItem$text.startsWith(inputValue) && !selectedItemIds.includes(highlightedItem.id)) {
167
- setAutocompleteSuggestion(highlightedItem.text);
168
- } else {
169
- setAutocompleteSuggestion('');
170
- }
171
- }, [highlightedItem, inputValue]);
172
- (0, _react.useEffect)(() => {
173
- setSortedItemIds([...sortedItemIds].sort(sortOnCloseFn ? sortOnCloseFn : getDefaultSortFn(isItemSelected)));
174
- onOpenChange && onOpenChange(Boolean(showMenu));
175
- }, [showMenu]);
176
- (0, _react.useEffect)(() => {
177
- setSelectedItemLength && setSelectedItemLength(selectedItemIds.length);
178
- }, [selectedItemIds]);
179
-
180
- if (listContainerRef.current) {
181
- (0, _Portal.registerPortalRoot)(listContainerRef.current, DROPDOWN_PORTAL_CONTAINER_NAME);
182
- }
183
-
184
- return /*#__PURE__*/_react.default.createElement(_.Box, {
185
- sx: !showMenu ? {
186
- // visually hides this label for sighted users
187
- position: 'absolute',
188
- width: '1px',
189
- height: '1px',
190
- padding: '0',
191
- margin: '-1px',
192
- overflow: 'hidden',
193
- clip: 'rect(0, 0, 0, 0)',
194
- whiteSpace: 'nowrap',
195
- borderWidth: '0'
196
- } : {}
197
- }, loading ? /*#__PURE__*/_react.default.createElement(_.Box, {
198
- p: 3,
199
- display: "flex",
200
- justifyContent: "center"
201
- }, /*#__PURE__*/_react.default.createElement(_.Spinner, null)) : /*#__PURE__*/_react.default.createElement("div", {
202
- ref: listContainerRef
203
- }, allItemsToRender.length ? /*#__PURE__*/_react.default.createElement(_ActionList.ActionList, {
204
- selectionVariant: "multiple" // have to typecast to `ItemProps` because we have an extra property
205
- // on `items` for Autocomplete: `metadata`
206
- ,
207
- items: allItemsToRender,
208
- role: "listbox",
209
- id: `${id}-listbox`,
210
- "aria-labelledby": ariaLabelledBy
211
- }) : /*#__PURE__*/_react.default.createElement(_.Box, {
212
- p: 3
213
- }, emptyStateText)));
214
- }
215
-
216
- AutocompleteMenu.displayName = "AutocompleteMenu";
217
- AutocompleteMenu.defaultProps = {
218
- emptyStateText: 'No selectable options',
219
- selectionVariant: 'single'
220
- };
221
- AutocompleteMenu.displayName = 'AutocompleteMenu';
222
- var _default = AutocompleteMenu;
223
- exports.default = _default;