@primer/components 0.0.0-202194204247 → 0.0.0-20219421241
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 +294 -298
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +364 -368
- package/dist/browser.umd.js.map +1 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
- package/lib/AnchoredOverlay/AnchoredOverlay.js +3 -11
- package/lib/FilteredActionList/FilteredActionList.js +31 -5
- package/lib/Overlay.d.ts +1 -2
- package/lib/Overlay.js +5 -10
- package/lib/SelectMenu/SelectMenu.d.ts +2 -8
- package/lib/TextInput.d.ts +3 -6
- package/lib/TextInput.js +10 -9
- package/lib/Token/Token.js +1 -1
- package/lib/Token/TokenBase.js +3 -3
- package/lib/Token/TokenLabel.js +3 -3
- package/lib/Token/_tokenButtonUtils.d.ts +1 -1
- 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/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -11
- package/lib-esm/FilteredActionList/FilteredActionList.js +31 -3
- package/lib-esm/Overlay.d.ts +1 -2
- package/lib-esm/Overlay.js +5 -8
- package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -8
- package/lib-esm/TextInput.d.ts +3 -6
- package/lib-esm/TextInput.js +9 -8
- package/lib-esm/Token/Token.js +1 -1
- package/lib-esm/Token/TokenBase.js +3 -3
- package/lib-esm/Token/TokenLabel.js +3 -3
- package/lib-esm/Token/_RemoveTokenButton.js +1 -1
- package/lib-esm/Token/_tokenButtonUtils.d.ts +1 -1
- package/lib-esm/Token/_tokenButtonUtils.js +1 -1
- package/lib-esm/hooks/useOverlay.d.ts +1 -2
- package/lib-esm/hooks/useOverlay.js +6 -11
- package/lib-esm/index.d.ts +0 -2
- package/lib-esm/index.js +0 -2
- package/lib-esm/utils/types.d.ts +0 -3
- package/package.json +1 -1
- package/lib/Autocomplete/Autocomplete.d.ts +0 -40
- package/lib/Autocomplete/Autocomplete.js +0 -68
- package/lib/Autocomplete/AutocompleteContext.d.ts +0 -17
- package/lib/Autocomplete/AutocompleteContext.js +0 -11
- package/lib/Autocomplete/AutocompleteInput.d.ts +0 -9
- package/lib/Autocomplete/AutocompleteInput.js +0 -142
- package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -71
- package/lib/Autocomplete/AutocompleteMenu.js +0 -223
- package/lib/Autocomplete/AutocompleteOverlay.d.ts +0 -17
- package/lib/Autocomplete/AutocompleteOverlay.js +0 -69
- package/lib/Autocomplete/index.d.ts +0 -2
- package/lib/Autocomplete/index.js +0 -15
- package/lib/TextInputWithTokens.d.ts +0 -43
- package/lib/TextInputWithTokens.js +0 -236
- package/lib/_UnstyledTextInput.d.ts +0 -2
- package/lib/_UnstyledTextInput.js +0 -20
- package/lib/utils/scrollIntoViewingArea.d.ts +0 -1
- package/lib/utils/scrollIntoViewingArea.js +0 -39
- package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -40
- package/lib-esm/Autocomplete/Autocomplete.js +0 -47
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -17
- package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -9
- package/lib-esm/Autocomplete/AutocompleteInput.js +0 -123
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -71
- package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -204
- package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +0 -17
- package/lib-esm/Autocomplete/AutocompleteOverlay.js +0 -51
- package/lib-esm/Autocomplete/index.d.ts +0 -2
- package/lib-esm/Autocomplete/index.js +0 -1
- package/lib-esm/TextInputWithTokens.d.ts +0 -43
- package/lib-esm/TextInputWithTokens.js +0 -209
- package/lib-esm/_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
@@ -32,15 +32,11 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
|
|
32
32
|
Divider: import("styled-components").StyledComponent<"div", any, SystemCommonProps & SxProp, never>;
|
33
33
|
Filter: React.ForwardRefExoticComponent<Pick<{
|
34
34
|
value?: string | undefined;
|
35
|
-
} &
|
36
|
-
ref?: ((instance: HTMLInputElement | null) => void) | React.RefObject<HTMLInputElement> | null | undefined;
|
37
|
-
}, string | number | symbol> & {
|
35
|
+
} & Pick<{
|
38
36
|
className?: string | undefined;
|
39
37
|
icon?: React.ComponentType<{
|
40
38
|
className?: string | undefined;
|
41
39
|
}> | undefined;
|
42
|
-
inputComponent?: React.ComponentType<HTMLInputElement> | undefined;
|
43
|
-
wrapperRef?: React.RefObject<HTMLSpanElement> | undefined;
|
44
40
|
} & Pick<{
|
45
41
|
color?: string | undefined;
|
46
42
|
maxWidth?: import("styled-system").ResponsiveValue<import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
@@ -319,9 +315,7 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
|
|
319
315
|
} & {
|
320
316
|
as?: string | React.ComponentType<any> | undefined;
|
321
317
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
322
|
-
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast" |
|
323
|
-
as?: "input" | undefined;
|
324
|
-
}, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
318
|
+
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
325
319
|
Footer: import("styled-components").StyledComponent<"footer", any, SystemCommonProps & SxProp, never>;
|
326
320
|
Item: React.ForwardRefExoticComponent<Pick<{
|
327
321
|
as?: React.ElementType<any> | undefined;
|
package/lib-esm/TextInput.d.ts
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
|
3
|
-
import type * as Polymorphic from "@radix-ui/react-polymorphic";
|
4
3
|
import { SxProp } from './sx';
|
5
4
|
import { ComponentProps } from './utils/types';
|
6
|
-
import
|
5
|
+
declare const Input: import("styled-components").StyledComponent<"input", any, {}, never>;
|
7
6
|
declare const Wrapper: import("styled-components").StyledComponent<"span", any, {
|
8
7
|
disabled?: boolean | undefined;
|
9
8
|
hasIcon?: boolean | undefined;
|
@@ -16,10 +15,8 @@ declare type NonPassthroughProps = {
|
|
16
15
|
icon?: React.ComponentType<{
|
17
16
|
className?: string;
|
18
17
|
}>;
|
19
|
-
inputComponent?: React.ComponentType<HTMLInputElement>;
|
20
|
-
wrapperRef?: React.RefObject<HTMLSpanElement>;
|
21
18
|
} & Pick<ComponentProps<typeof Wrapper>, 'block' | 'contrast' | 'disabled' | 'sx' | 'theme' | 'width' | 'maxWidth' | 'minWidth' | 'variant'>;
|
22
|
-
declare type TextInputInternalProps = NonPassthroughProps & Omit<React.ComponentPropsWithoutRef<typeof
|
23
|
-
declare const TextInput:
|
19
|
+
declare type TextInputInternalProps = NonPassthroughProps & Omit<React.ComponentPropsWithoutRef<typeof Input>, keyof NonPassthroughProps>;
|
20
|
+
declare const TextInput: React.ForwardRefExoticComponent<Pick<TextInputInternalProps, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
24
21
|
export declare type TextInputProps = ComponentProps<typeof TextInput>;
|
25
22
|
export default TextInput;
|
package/lib-esm/TextInput.js
CHANGED
@@ -6,7 +6,6 @@ import styled, { css } from 'styled-components';
|
|
6
6
|
import { maxWidth, minWidth, variant, width } from 'styled-system';
|
7
7
|
import { get } from './constants';
|
8
8
|
import sx from './sx';
|
9
|
-
import UnstyledTextInput from './_UnstyledTextInput';
|
10
9
|
const sizeVariants = variant({
|
11
10
|
variants: {
|
12
11
|
small: {
|
@@ -23,19 +22,23 @@ const sizeVariants = variant({
|
|
23
22
|
}
|
24
23
|
}
|
25
24
|
});
|
25
|
+
const Input = styled.input.withConfig({
|
26
|
+
displayName: "TextInput__Input",
|
27
|
+
componentId: "sc-1apmpmt-0"
|
28
|
+
})(["border:0;font-size:inherit;font-family:inherit;background-color:transparent;-webkit-appearance:none;color:inherit;width:100%;&:focus{outline:0;}"]);
|
26
29
|
const Wrapper = styled.span.withConfig({
|
27
30
|
displayName: "TextInput__Wrapper",
|
28
|
-
componentId: "sc-1apmpmt-
|
31
|
+
componentId: "sc-1apmpmt-1"
|
29
32
|
})(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.fg.default'), get('colors.border.default'), get('radii.2'), get('shadows.primer.shadow.inset'), props => {
|
30
33
|
if (props.hasIcon) {
|
31
34
|
return css(["padding:0;"]);
|
32
35
|
} else {
|
33
36
|
return css(["padding:6px 12px;"]);
|
34
37
|
}
|
35
|
-
}, get('colors.fg.muted'), get('space.2'), get('colors.accent.emphasis'), get('shadows.primer.shadow.focus'), props => props.contrast && css(["background-color:", ";"], get('colors.canvas.inset')), props => props.disabled && css(["color:", ";background-color:", ";border-color:", ";"], get('colors.fg.muted'), get('colors.input.disabledBg'), get('colors.border.default')), props => props.block && css(["display:block;width:100%;"]), get('breakpoints.1'), get('fontSizes.1'), width, minWidth, maxWidth, sizeVariants, sx);
|
38
|
+
}, get('colors.fg.muted'), get('space.2'), get('colors.accent.emphasis'), get('shadows.primer.shadow.focus'), props => props.contrast && css(["background-color:", ";"], get('colors.canvas.inset')), props => props.disabled && css(["color:", ";background-color:", ";border-color:", ";"], get('colors.fg.muted'), get('colors.input.disabledBg'), get('colors.border.default')), props => props.block && css(["display:block;width:100%;"]), get('breakpoints.1'), get('fontSizes.1'), width, minWidth, maxWidth, sizeVariants, sx); // Props that are not passed through to Input:
|
39
|
+
|
36
40
|
// using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input
|
37
41
|
const TextInput = /*#__PURE__*/React.forwardRef(({
|
38
|
-
inputComponent: InputComponent,
|
39
42
|
icon: IconComponent,
|
40
43
|
block,
|
41
44
|
className,
|
@@ -47,7 +50,6 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
47
50
|
minWidth: minWidthProp,
|
48
51
|
maxWidth: maxWidthProp,
|
49
52
|
variant: variantProp,
|
50
|
-
wrapperRef,
|
51
53
|
...inputProps
|
52
54
|
}, ref) => {
|
53
55
|
// this class is necessary to style FilterSearch, plz no touchy!
|
@@ -63,11 +65,10 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
63
65
|
width: widthProp,
|
64
66
|
minWidth: minWidthProp,
|
65
67
|
maxWidth: maxWidthProp,
|
66
|
-
variant: variantProp
|
67
|
-
ref: wrapperRef
|
68
|
+
variant: variantProp
|
68
69
|
}, IconComponent && /*#__PURE__*/React.createElement(IconComponent, {
|
69
70
|
className: "TextInput-icon"
|
70
|
-
}), /*#__PURE__*/React.createElement(
|
71
|
+
}), /*#__PURE__*/React.createElement(Input, _extends({
|
71
72
|
ref: ref,
|
72
73
|
disabled: disabled
|
73
74
|
}, inputProps)));
|
package/lib-esm/Token/Token.js
CHANGED
@@ -51,7 +51,7 @@ const Token = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
51
51
|
onClick: handleRemoveClick,
|
52
52
|
variant: variant,
|
53
53
|
parentTokenIsInteractive: isTokenInteractive(props),
|
54
|
-
"aria-hidden": hasMultipleActionTargets ?
|
54
|
+
"aria-hidden": hasMultipleActionTargets ? 'true' : 'false'
|
55
55
|
}) : null);
|
56
56
|
});
|
57
57
|
export default Token;
|
@@ -51,10 +51,10 @@ const TokenBase = styled.span.attrs(({
|
|
51
51
|
handleRemove,
|
52
52
|
onKeyUp
|
53
53
|
}) => ({
|
54
|
-
onKeyUp:
|
55
|
-
onKeyUp && onKeyUp(
|
54
|
+
onKeyUp: event => {
|
55
|
+
onKeyUp && onKeyUp(event);
|
56
56
|
|
57
|
-
if ((
|
57
|
+
if ((event.key === 'Backspace' || event.key === 'Delete') && handleRemove) {
|
58
58
|
handleRemove();
|
59
59
|
}
|
60
60
|
},
|
@@ -75,12 +75,12 @@ const TokenLabel = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
75
75
|
}
|
76
76
|
|
77
77
|
if (isSelected) {
|
78
|
-
bgColor = isFillColorDark ? tinycolor(fillColor).lighten(10).toString() // TODO: darken more than 10 if the fillColor is really bright and doesn't darken well
|
78
|
+
bgColor = isFillColorDark ? tinycolor(fillColor).lighten(10).toString() : // TODO: darken more than 10 if the fillColor is really bright and doesn't darken well
|
79
79
|
// Examples of colors that don't darken well:
|
80
80
|
// - #a2eeef
|
81
81
|
// - #ffd78e
|
82
82
|
// - #a4f287
|
83
|
-
|
83
|
+
tinycolor(fillColor).darken(10).toString();
|
84
84
|
}
|
85
85
|
}
|
86
86
|
|
@@ -112,7 +112,7 @@ const TokenLabel = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
112
112
|
tabIndex: -1,
|
113
113
|
onClick: handleRemoveClick,
|
114
114
|
variant: variant,
|
115
|
-
"aria-hidden": hasMultipleActionTargets ?
|
115
|
+
"aria-hidden": hasMultipleActionTargets ? 'true' : 'false'
|
116
116
|
}) : null);
|
117
117
|
});
|
118
118
|
TokenLabel.defaultProps = {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { XIcon } from '@primer/octicons-react';
|
2
2
|
import styled from 'styled-components';
|
3
|
-
import { defaultTokenSize } from
|
3
|
+
import { defaultTokenSize } from './TokenBase';
|
4
4
|
import { tokenButtonStyles, variants, getTokenButtonIconSize } from './_tokenButtonUtils';
|
5
5
|
const RemoveTokenButton = styled.span.attrs(({
|
6
6
|
borderOffset,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { css } from 'styled-components';
|
2
2
|
import { variant } from 'styled-system';
|
3
3
|
import { get } from '../constants';
|
4
|
-
import { tokenSizes, defaultTokenSize } from
|
4
|
+
import { tokenSizes, defaultTokenSize } from './TokenBase';
|
5
5
|
export const variants = variant({
|
6
6
|
variants: {
|
7
7
|
sm: {
|
@@ -7,9 +7,8 @@ export declare type UseOverlaySettings = {
|
|
7
7
|
onEscape: (e: KeyboardEvent) => void;
|
8
8
|
onClickOutside: (e: TouchOrMouseEvent) => void;
|
9
9
|
overlayRef?: React.RefObject<HTMLDivElement>;
|
10
|
-
preventFocusOnOpen?: boolean;
|
11
10
|
};
|
12
11
|
export declare type OverlayReturnProps = {
|
13
12
|
ref: React.RefObject<HTMLDivElement>;
|
14
13
|
};
|
15
|
-
export declare const useOverlay: ({ overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside
|
14
|
+
export declare const useOverlay: ({ overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside }: UseOverlaySettings) => OverlayReturnProps;
|
@@ -8,19 +8,14 @@ export const useOverlay = ({
|
|
8
8
|
initialFocusRef,
|
9
9
|
onEscape,
|
10
10
|
ignoreClickRefs,
|
11
|
-
onClickOutside
|
12
|
-
preventFocusOnOpen
|
11
|
+
onClickOutside
|
13
12
|
}) => {
|
14
13
|
const overlayRef = useProvidedRefOrCreate(_overlayRef);
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
initialFocusRef
|
21
|
-
});
|
22
|
-
}
|
23
|
-
|
14
|
+
useOpenAndCloseFocus({
|
15
|
+
containerRef: overlayRef,
|
16
|
+
returnFocusRef,
|
17
|
+
initialFocusRef
|
18
|
+
});
|
24
19
|
useOnOutsideClick({
|
25
20
|
containerRef: overlayRef,
|
26
21
|
ignoreClickRefs,
|
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 './TextInputWithTokens';
|
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 './TextInputWithTokens';
|
66
64
|
export { default as Text } from './Text';
|
67
65
|
export { default as Timeline } from './Timeline';
|
68
66
|
export { default as Token, TokenLabel, TokenProfile } from './Token';
|
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,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,142 +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
|
-
const handleInputFocus = (0, _react.useCallback)(e => {
|
48
|
-
onFocus && onFocus(e);
|
49
|
-
setShowMenu && setShowMenu(true);
|
50
|
-
}, [onFocus, setShowMenu]);
|
51
|
-
const handleInputBlur = (0, _react.useCallback)(e => {
|
52
|
-
onBlur && onBlur(e); // HACK: wait a tick and check the focused element before hiding the autocomplete menu
|
53
|
-
// this prevents the menu from hiding when the user is clicking an option in the Autoselect.Menu,
|
54
|
-
// but still hides the menu when the user blurs the input by tabbing out or clicking somewhere else on the page
|
55
|
-
|
56
|
-
setTimeout(() => {
|
57
|
-
if (document.activeElement !== combinedInputRef.current) {
|
58
|
-
setShowMenu && setShowMenu(false);
|
59
|
-
}
|
60
|
-
}, 0);
|
61
|
-
}, [onBlur, setShowMenu]);
|
62
|
-
const handleInputChange = (0, _react.useCallback)(e => {
|
63
|
-
onChange && onChange(e);
|
64
|
-
setInputValue && setInputValue(e.currentTarget.value);
|
65
|
-
|
66
|
-
if (!showMenu) {
|
67
|
-
setShowMenu && setShowMenu(true);
|
68
|
-
}
|
69
|
-
}, [onChange, setInputValue, setShowMenu, showMenu]);
|
70
|
-
const handleInputKeyDown = (0, _react.useCallback)(e => () => {
|
71
|
-
var _inputRef$current;
|
72
|
-
|
73
|
-
if (e.key === 'Backspace') {
|
74
|
-
setHighlightRemainingText(false);
|
75
|
-
}
|
76
|
-
|
77
|
-
if (e.key === 'Escape' && inputRef !== null && inputRef !== void 0 && (_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.value) {
|
78
|
-
setInputValue && setInputValue('');
|
79
|
-
inputRef.current.value = '';
|
80
|
-
}
|
81
|
-
}, [setInputValue]);
|
82
|
-
|
83
|
-
const handleInputKeyUp = e => {
|
84
|
-
if (e.key === 'Backspace') {
|
85
|
-
setHighlightRemainingText(true);
|
86
|
-
}
|
87
|
-
};
|
88
|
-
|
89
|
-
const onInputKeyPress = (0, _react.useCallback)(event => {
|
90
|
-
if (activeDescendantRef && event.key === 'Enter' && activeDescendantRef.current) {
|
91
|
-
event.preventDefault();
|
92
|
-
event.nativeEvent.stopImmediatePropagation(); // Forward Enter key press to active descendant so that item gets activated
|
93
|
-
|
94
|
-
const activeDescendantEvent = new KeyboardEvent(event.type, event.nativeEvent);
|
95
|
-
activeDescendantRef.current.dispatchEvent(activeDescendantEvent);
|
96
|
-
}
|
97
|
-
}, [activeDescendantRef]);
|
98
|
-
(0, _react.useEffect)(() => {
|
99
|
-
if (!(inputRef !== null && inputRef !== void 0 && inputRef.current)) {
|
100
|
-
return;
|
101
|
-
} // resets input value to being empty after a selection has been made
|
102
|
-
|
103
|
-
|
104
|
-
if (!autocompleteSuggestion) {
|
105
|
-
inputRef.current.value = inputValue;
|
106
|
-
} // TODO: fix bug where this function prevents `onChange` from being triggered if the highlighted item text
|
107
|
-
// is the same as what I'm typing
|
108
|
-
// e.g.: typing 'tw' highights 'two', but when I 'two', the text input change does not get triggered
|
109
|
-
|
110
|
-
|
111
|
-
if (highlightRemainingText && autocompleteSuggestion && (inputValue || isMenuDirectlyActivated)) {
|
112
|
-
inputRef.current.value = autocompleteSuggestion;
|
113
|
-
|
114
|
-
if (autocompleteSuggestion.toLowerCase().indexOf(inputValue.toLowerCase()) === 0) {
|
115
|
-
inputRef.current.setSelectionRange(inputValue.length, autocompleteSuggestion.length);
|
116
|
-
}
|
117
|
-
}
|
118
|
-
}, [autocompleteSuggestion, inputValue]);
|
119
|
-
(0, _react.useEffect)(() => {
|
120
|
-
if (value) {
|
121
|
-
setInputValue && setInputValue(value.toString());
|
122
|
-
}
|
123
|
-
}, [value]);
|
124
|
-
return /*#__PURE__*/_react.default.createElement(Component, _extends({
|
125
|
-
onFocus: handleInputFocus,
|
126
|
-
onBlur: handleInputBlur,
|
127
|
-
onChange: handleInputChange,
|
128
|
-
onKeyDown: handleInputKeyDown,
|
129
|
-
onKeyPress: onInputKeyPress,
|
130
|
-
onKeyUp: handleInputKeyUp,
|
131
|
-
ref: combinedInputRef,
|
132
|
-
"aria-controls": `${id}-listbox`,
|
133
|
-
"aria-autocomplete": "both",
|
134
|
-
role: "combobox",
|
135
|
-
"aria-expanded": showMenu,
|
136
|
-
"aria-haspopup": "listbox",
|
137
|
-
"aria-owns": `${id}-listbox`
|
138
|
-
}, props));
|
139
|
-
});
|
140
|
-
|
141
|
-
var _default = AutocompleteInput;
|
142
|
-
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;
|