@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.
Files changed (96) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/browser.esm.js +250 -290
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +318 -358
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/FilteredActionList/FilteredActionList.js +31 -6
  7. package/lib/Overlay.d.ts +1 -2
  8. package/lib/Overlay.js +5 -10
  9. package/lib/SelectMenu/SelectMenu.d.ts +2 -8
  10. package/lib/TextInput.d.ts +3 -6
  11. package/lib/TextInput.js +10 -9
  12. package/lib/hooks/useOverlay.d.ts +1 -2
  13. package/lib/hooks/useOverlay.js +6 -11
  14. package/lib/index.d.ts +0 -2
  15. package/lib/index.js +0 -16
  16. package/lib/utils/types.d.ts +0 -3
  17. package/lib-esm/FilteredActionList/FilteredActionList.js +31 -4
  18. package/lib-esm/Overlay.d.ts +1 -2
  19. package/lib-esm/Overlay.js +5 -8
  20. package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -8
  21. package/lib-esm/TextInput.d.ts +3 -6
  22. package/lib-esm/TextInput.js +9 -8
  23. package/lib-esm/hooks/useOverlay.d.ts +1 -2
  24. package/lib-esm/hooks/useOverlay.js +6 -11
  25. package/lib-esm/index.d.ts +0 -2
  26. package/lib-esm/index.js +0 -2
  27. package/lib-esm/utils/types.d.ts +0 -3
  28. package/package.json +4 -7
  29. package/lib/Autocomplete/Autocomplete.d.ts +0 -31
  30. package/lib/Autocomplete/Autocomplete.js +0 -60
  31. package/lib/Autocomplete/AutocompleteContext.d.ts +0 -14
  32. package/lib/Autocomplete/AutocompleteContext.js +0 -11
  33. package/lib/Autocomplete/AutocompleteInput.d.ts +0 -9
  34. package/lib/Autocomplete/AutocompleteInput.js +0 -148
  35. package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -70
  36. package/lib/Autocomplete/AutocompleteMenu.js +0 -252
  37. package/lib/Autocomplete/index.d.ts +0 -2
  38. package/lib/Autocomplete/index.js +0 -15
  39. package/lib/Badge/Badge.d.ts +0 -8
  40. package/lib/Badge/Badge.js +0 -59
  41. package/lib/Badge/BadgeState.d.ts +0 -13
  42. package/lib/Badge/BadgeState.js +0 -51
  43. package/lib/Badge/_badgeStyleUtils.d.ts +0 -3
  44. package/lib/Badge/_badgeStyleUtils.js +0 -39
  45. package/lib/TextInputTokens.d.ts +0 -43
  46. package/lib/TextInputTokens.js +0 -237
  47. package/lib/Token/Token.d.ts +0 -14
  48. package/lib/Token/Token.js +0 -75
  49. package/lib/Token/TokenBase.d.ts +0 -16
  50. package/lib/Token/TokenBase.js +0 -90
  51. package/lib/Token/TokenLabel.d.ts +0 -14
  52. package/lib/Token/TokenLabel.js +0 -135
  53. package/lib/Token/TokenProfile.d.ts +0 -7
  54. package/lib/Token/TokenProfile.js +0 -50
  55. package/lib/Token/_RemoveTokenButton.d.ts +0 -3
  56. package/lib/Token/_RemoveTokenButton.js +0 -45
  57. package/lib/Token/_tokenButtonUtils.d.ts +0 -10
  58. package/lib/Token/_tokenButtonUtils.js +0 -42
  59. package/lib/_UnstyledTextInput.d.ts +0 -2
  60. package/lib/_UnstyledTextInput.js +0 -20
  61. package/lib/utils/scrollIntoViewingArea.d.ts +0 -1
  62. package/lib/utils/scrollIntoViewingArea.js +0 -39
  63. package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -31
  64. package/lib-esm/Autocomplete/Autocomplete.js +0 -40
  65. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -14
  66. package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
  67. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -9
  68. package/lib-esm/Autocomplete/AutocompleteInput.js +0 -129
  69. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -70
  70. package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -226
  71. package/lib-esm/Autocomplete/index.d.ts +0 -2
  72. package/lib-esm/Autocomplete/index.js +0 -1
  73. package/lib-esm/Badge/Badge.d.ts +0 -8
  74. package/lib-esm/Badge/Badge.js +0 -44
  75. package/lib-esm/Badge/BadgeState.d.ts +0 -13
  76. package/lib-esm/Badge/BadgeState.js +0 -40
  77. package/lib-esm/Badge/_badgeStyleUtils.d.ts +0 -3
  78. package/lib-esm/Badge/_badgeStyleUtils.js +0 -29
  79. package/lib-esm/TextInputTokens.d.ts +0 -43
  80. package/lib-esm/TextInputTokens.js +0 -210
  81. package/lib-esm/Token/Token.d.ts +0 -14
  82. package/lib-esm/Token/Token.js +0 -56
  83. package/lib-esm/Token/TokenBase.d.ts +0 -16
  84. package/lib-esm/Token/TokenBase.js +0 -70
  85. package/lib-esm/Token/TokenLabel.d.ts +0 -14
  86. package/lib-esm/Token/TokenLabel.js +0 -115
  87. package/lib-esm/Token/TokenProfile.d.ts +0 -7
  88. package/lib-esm/Token/TokenProfile.js +0 -29
  89. package/lib-esm/Token/_RemoveTokenButton.d.ts +0 -3
  90. package/lib-esm/Token/_RemoveTokenButton.js +0 -30
  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
@@ -1,50 +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 _styledComponents = _interopRequireDefault(require("styled-components"));
11
-
12
- var _constants = require("../constants");
13
-
14
- var _primitives = _interopRequireDefault(require("@primer/primitives"));
15
-
16
- var _TokenBase = require("./TokenBase");
17
-
18
- var _Token = _interopRequireDefault(require("./Token"));
19
-
20
- var _ = require("..");
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- 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); }
25
-
26
- 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; }
27
-
28
- 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); }
29
-
30
- const StyledToken = (0, _styledComponents.default)(_Token.default).withConfig({
31
- displayName: "TokenProfile__StyledToken",
32
- componentId: "sc-1vf9jhf-0"
33
- })(["padding-left:", ";"], (0, _constants.get)('space.1'));
34
- const TokenProfile = /*#__PURE__*/(0, _react.forwardRef)(({
35
- avatarSrc,
36
- id,
37
- ref,
38
- variant,
39
- ...rest
40
- }, forwardedRef) => /*#__PURE__*/_react.default.createElement(StyledToken, _extends({
41
- leadingVisual: () => /*#__PURE__*/_react.default.createElement(_.Avatar, {
42
- src: avatarSrc,
43
- size: _TokenBase.tokenSizes[variant || _TokenBase.defaultTokenSize] - parseInt(_primitives.default.spacing.normal.spacer[1], 10) * 2
44
- }),
45
- variant: variant,
46
- id: id === null || id === void 0 ? void 0 : id.toString(),
47
- ref: forwardedRef
48
- }, rest)));
49
- var _default = TokenProfile;
50
- exports.default = _default;
@@ -1,3 +0,0 @@
1
- import { TokenButtonProps } from './_tokenButtonUtils';
2
- declare const RemoveTokenButton: import("styled-components").StyledComponent<"span", any, TokenButtonProps, never>;
3
- export default RemoveTokenButton;
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _octiconsReact = require("@primer/octicons-react");
9
-
10
- var _styledComponents = _interopRequireDefault(require("styled-components"));
11
-
12
- var _TokenBase = require("./TokenBase");
13
-
14
- var _tokenButtonUtils = require("./_tokenButtonUtils");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const RemoveTokenButton = _styledComponents.default.span.attrs(({
19
- borderOffset,
20
- parentTokenTag,
21
- variant,
22
- parentTokenIsInteractive,
23
- ...rest
24
- }) => {
25
- delete rest.children;
26
- return {
27
- borderOffset,
28
- as: parentTokenIsInteractive ? 'span' : 'button',
29
- tabIndex: parentTokenIsInteractive ? -1 : undefined,
30
- 'aria-label': !parentTokenIsInteractive ? 'Remove token' : undefined,
31
- children: /*#__PURE__*/React.createElement(_octiconsReact.XIcon, {
32
- size: (0, _tokenButtonUtils.getTokenButtonIconSize)(variant)
33
- }) // TODO: figure out how to set `size` using `fontSizes` from Primitives
34
-
35
- };
36
- }).withConfig({
37
- displayName: "_RemoveTokenButton__RemoveTokenButton",
38
- componentId: "sc-14lvcw1-0"
39
- })(["", " ", " transform:", ";"], _tokenButtonUtils.tokenButtonStyles, _tokenButtonUtils.variants, props => `translate(${props.borderOffset}px, -${props.borderOffset}px)`);
40
-
41
- RemoveTokenButton.defaultProps = {
42
- variant: _TokenBase.defaultTokenSize
43
- };
44
- var _default = RemoveTokenButton;
45
- exports.default = _default;
@@ -1,10 +0,0 @@
1
- import { TokenSizeKeys } from "./TokenBase";
2
- export interface TokenButtonProps {
3
- borderOffset?: number;
4
- parentTokenTag: 'span' | 'button' | 'a';
5
- variant?: TokenSizeKeys;
6
- parentTokenIsInteractive?: boolean;
7
- }
8
- export declare const variants: (...args: any[]) => any;
9
- export declare const tokenButtonStyles: import("styled-components").FlattenInterpolation<import("styled-components").ThemeProps<any>>;
10
- export declare const getTokenButtonIconSize: (variant?: TokenSizeKeys | undefined) => number;
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getTokenButtonIconSize = exports.tokenButtonStyles = exports.variants = void 0;
7
-
8
- var _styledComponents = require("styled-components");
9
-
10
- var _styledSystem = require("styled-system");
11
-
12
- var _constants = require("../constants");
13
-
14
- var _TokenBase = require("./TokenBase");
15
-
16
- const variants = (0, _styledSystem.variant)({
17
- variants: {
18
- sm: {
19
- height: `${_TokenBase.tokenSizes.sm}px`,
20
- width: `${_TokenBase.tokenSizes.sm}px`
21
- },
22
- md: {
23
- height: `${_TokenBase.tokenSizes.md}px`,
24
- width: `${_TokenBase.tokenSizes.md}px`
25
- },
26
- lg: {
27
- height: `${_TokenBase.tokenSizes.lg}px`,
28
- width: `${_TokenBase.tokenSizes.lg}px`
29
- },
30
- xl: {
31
- height: `${_TokenBase.tokenSizes.xl}px`,
32
- width: `${_TokenBase.tokenSizes.xl}px`
33
- }
34
- }
35
- });
36
- exports.variants = variants;
37
- const tokenButtonStyles = (0, _styledComponents.css)(["background-color:transparent;font-family:inherit;color:currentColor;cursor:pointer;display:inline-flex;justify-content:center;align-items:center;user-select:none;appearance:none;text-decoration:none;padding:0;align-self:baseline;border:0;border-radius:999px;&:hover,&:focus{background-color:", ";}&:active{background-color:", ";}"], (0, _constants.get)('colors.fade.fg10'), (0, _constants.get)('colors.fade.fg15'));
38
- exports.tokenButtonStyles = tokenButtonStyles;
39
-
40
- const getTokenButtonIconSize = variant => _TokenBase.tokenSizes[variant || _TokenBase.defaultTokenSize] * 0.75;
41
-
42
- exports.getTokenButtonIconSize = getTokenButtonIconSize;
@@ -1,2 +0,0 @@
1
- declare const UnstyledTextInput: import("styled-components").StyledComponent<"input", any, import("./sx").SxProp, never>;
2
- export default UnstyledTextInput;
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _styledComponents = _interopRequireDefault(require("styled-components"));
9
-
10
- var _sx = _interopRequireDefault(require("./sx"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- const UnstyledTextInput = _styledComponents.default.input.withConfig({
15
- displayName: "_UnstyledTextInput__UnstyledTextInput",
16
- componentId: "sc-1jgl33s-0"
17
- })(["border:0;font-size:inherit;font-family:inherit;background-color:transparent;-webkit-appearance:none;color:inherit;width:100%;&:focus{outline:0;}", ";"], _sx.default);
18
-
19
- var _default = UnstyledTextInput;
20
- exports.default = _default;
@@ -1 +0,0 @@
1
- export declare const scrollIntoViewingArea: (child: HTMLElement, container: HTMLElement, direction?: 'horizontal' | 'vertical', startMargin?: number, endMargin?: number, behavior?: ScrollBehavior) => void;
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.scrollIntoViewingArea = void 0;
7
-
8
- const scrollIntoViewingArea = (child, container, direction = 'vertical', startMargin = 8, endMargin = 0, behavior = 'smooth') => {
9
- const startSide = direction === 'vertical' ? 'top' : 'left';
10
- const endSide = direction === 'vertical' ? 'bottom' : 'right';
11
- const scrollSide = direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
12
- const {
13
- [startSide]: childStart,
14
- [endSide]: childEnd
15
- } = child.getBoundingClientRect();
16
- const {
17
- [startSide]: containerStart,
18
- [endSide]: containerEnd
19
- } = container.getBoundingClientRect();
20
- const isChildStartAboveViewingArea = childStart < containerStart + endMargin;
21
- const isChildBottomBelowViewingArea = childEnd > containerEnd - startMargin;
22
-
23
- if (isChildStartAboveViewingArea) {
24
- const scrollHeightToChildStart = childStart - containerStart + container[scrollSide];
25
- container.scrollTo({
26
- behavior,
27
- [startSide]: scrollHeightToChildStart - endMargin
28
- });
29
- } else if (isChildBottomBelowViewingArea) {
30
- const scrollHeightToChildBottom = childEnd - containerEnd + container[scrollSide];
31
- container.scrollTo({
32
- behavior,
33
- [startSide]: scrollHeightToChildBottom + startMargin
34
- });
35
- } // either completely in view or outside viewing area on both ends, don't scroll
36
-
37
- };
38
-
39
- exports.scrollIntoViewingArea = scrollIntoViewingArea;
@@ -1,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,40 +0,0 @@
1
- import React, { useRef, useState } from 'react';
2
- import { uniqueId } from '../utils/uniqueId';
3
- import { AutocompleteContext } from './AutocompleteContext';
4
- import AutocompleteInput from './AutocompleteInput';
5
- import AutocompleteMenu from './AutocompleteMenu';
6
-
7
- const Autocomplete = ({
8
- children,
9
- id: idProp
10
- }) => {
11
- const activeDescendantRef = useRef(null);
12
- const inputRef = useRef(null);
13
- const [inputValue, setInputValue] = useState('');
14
- const [showMenu, setShowMenu] = useState(false);
15
- const [autocompleteSuggestion, setAutocompleteSuggestion] = useState('');
16
- const [isMenuDirectlyActivated, setIsMenuDirectlyActivated] = useState(false);
17
- const id = idProp || uniqueId();
18
- return /*#__PURE__*/React.createElement(AutocompleteContext.Provider, {
19
- value: {
20
- activeDescendantRef,
21
- autocompleteSuggestion,
22
- id,
23
- inputRef,
24
- inputValue,
25
- isMenuDirectlyActivated,
26
- setAutocompleteSuggestion,
27
- setInputValue,
28
- setIsMenuDirectlyActivated,
29
- setShowMenu,
30
- showMenu
31
- }
32
- }, children);
33
- };
34
-
35
- Autocomplete.displayName = "Autocomplete";
36
- export default Object.assign(Autocomplete, {
37
- AutocompleteContext,
38
- Input: AutocompleteInput,
39
- Menu: AutocompleteMenu
40
- });
@@ -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,2 +0,0 @@
1
- import { createContext } from 'react';
2
- export const AutocompleteContext = /*#__PURE__*/createContext({});
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import 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,129 +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
- // COLEHELP
41
-
42
- setTimeout(() => {
43
- if (document.activeElement !== combinedInputRef.current) {
44
- setShowMenu && setShowMenu(false);
45
- }
46
- }, 0);
47
- };
48
-
49
- const handleInputChange = e => {
50
- onChange && onChange(e);
51
- setInputValue && setInputValue(e.currentTarget.value);
52
-
53
- if (!showMenu) {
54
- setShowMenu && setShowMenu(true);
55
- }
56
- };
57
-
58
- const handleInputKeyDown = e => {
59
- var _inputRef$current;
60
-
61
- if (e.key === 'Backspace') {
62
- setHighlightRemainingText(false);
63
- }
64
-
65
- if (e.key === 'Escape' && inputRef !== null && inputRef !== void 0 && (_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.value) {
66
- setInputValue && setInputValue('');
67
- inputRef.current.value = '';
68
- }
69
- };
70
-
71
- const handleInputKeyUp = e => {
72
- if (e.key === 'Backspace') {
73
- setHighlightRemainingText(true);
74
- }
75
- };
76
-
77
- const onInputKeyPress = useCallback(event => {
78
- if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
79
- event.preventDefault();
80
- event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
81
-
82
- const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
83
- activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
84
- }
85
- }, [activeDescendantRef]);
86
- useEffect(() => {
87
- if (!(inputRef !== null && inputRef !== void 0 && inputRef.current)) {
88
- return;
89
- } // resets input value to being empty after a selection has been made
90
-
91
-
92
- if (!autocompleteSuggestion) {
93
- inputRef.current.value = inputValue;
94
- } // TODO: fix bug where this function prevents `onChange` from being triggered if the highlighted item text
95
- // is the same as what I'm typing
96
- // e.g.: typing 'tw' highights 'two', but when I 'two', the text input change does not get triggered
97
- // COLEHELP
98
-
99
-
100
- if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
101
- inputRef.current.value = autocompleteSuggestion;
102
-
103
- if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
104
- inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
105
- }
106
- }
107
- }, [autocompleteSuggestion, inputValue]);
108
- useEffect(() => {
109
- if (value) {
110
- setInputValue && setInputValue(value.toString());
111
- }
112
- }, [value]);
113
- return /*#__PURE__*/React.createElement(Component, _extends({
114
- onFocus: handleInputFocus,
115
- onBlur: handleInputBlur,
116
- onChange: handleInputChange,
117
- onKeyDown: handleInputKeyDown,
118
- onKeyPress: onInputKeyPress,
119
- onKeyUp: handleInputKeyUp,
120
- ref: combinedInputRef,
121
- "aria-controls": `${id}-listbox`,
122
- "aria-autocomplete": "both",
123
- role: "combobox",
124
- "aria-expanded": showMenu,
125
- "aria-haspopup": "listbox",
126
- "aria-owns": `${id}-listbox`
127
- }, props));
128
- });
129
- export default AutocompleteInput;
@@ -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;