@primer/components 0.0.0-20219815255 → 0.0.0-20219835928
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 +252 -256
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +331 -335
- package/dist/browser.umd.js.map +1 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.js +11 -3
- package/lib/Autocomplete/Autocomplete.d.ts +40 -0
- package/lib/Autocomplete/Autocomplete.js +68 -0
- package/lib/Autocomplete/AutocompleteContext.d.ts +17 -0
- package/lib/Autocomplete/AutocompleteContext.js +11 -0
- package/lib/Autocomplete/AutocompleteInput.d.ts +9 -0
- package/lib/Autocomplete/AutocompleteInput.js +150 -0
- package/lib/Autocomplete/AutocompleteMenu.d.ts +71 -0
- package/lib/Autocomplete/AutocompleteMenu.js +223 -0
- package/lib/Autocomplete/AutocompleteOverlay.d.ts +17 -0
- package/lib/Autocomplete/AutocompleteOverlay.js +69 -0
- package/lib/Autocomplete/index.d.ts +2 -0
- package/lib/Autocomplete/index.js +15 -0
- package/lib/FilteredActionList/FilteredActionList.js +5 -31
- package/lib/Overlay.d.ts +2 -1
- package/lib/Overlay.js +10 -5
- package/lib/SelectMenu/SelectMenu.d.ts +3 -8
- package/lib/TextInput.d.ts +3 -13
- package/lib/TextInput.js +3 -43
- package/lib/TextInputWithTokens.d.ts +11 -14
- package/lib/TextInputWithTokens.js +119 -119
- package/lib/_TextInputWrapper.d.ts +10 -0
- package/lib/_TextInputWrapper.js +51 -0
- package/lib/hooks/useOpenAndCloseFocus.d.ts +2 -1
- package/lib/hooks/useOpenAndCloseFocus.js +7 -2
- package/lib/hooks/useOverlay.d.ts +2 -1
- package/lib/hooks/useOverlay.js +4 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -0
- package/lib/utils/scrollIntoViewingArea.d.ts +1 -0
- package/lib/utils/scrollIntoViewingArea.js +39 -0
- package/lib/utils/types/MandateProps.d.ts +3 -0
- package/lib/utils/types/MandateProps.js +1 -0
- package/lib/utils/types/index.d.ts +1 -0
- package/lib/utils/types/index.js +13 -0
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +11 -3
- package/lib-esm/Autocomplete/Autocomplete.d.ts +40 -0
- package/lib-esm/Autocomplete/Autocomplete.js +47 -0
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +17 -0
- package/lib-esm/Autocomplete/AutocompleteContext.js +2 -0
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +9 -0
- package/lib-esm/Autocomplete/AutocompleteInput.js +131 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +71 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.js +204 -0
- package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +17 -0
- package/lib-esm/Autocomplete/AutocompleteOverlay.js +51 -0
- package/lib-esm/Autocomplete/index.d.ts +2 -0
- package/lib-esm/Autocomplete/index.js +1 -0
- package/lib-esm/FilteredActionList/FilteredActionList.js +3 -31
- package/lib-esm/Overlay.d.ts +2 -1
- package/lib-esm/Overlay.js +8 -5
- package/lib-esm/SelectMenu/SelectMenu.d.ts +3 -8
- package/lib-esm/TextInput.d.ts +3 -13
- package/lib-esm/TextInput.js +3 -34
- package/lib-esm/TextInputWithTokens.d.ts +11 -14
- package/lib-esm/TextInputWithTokens.js +117 -115
- package/lib-esm/_TextInputWrapper.d.ts +10 -0
- package/lib-esm/_TextInputWrapper.js +31 -0
- package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +2 -1
- package/lib-esm/hooks/useOpenAndCloseFocus.js +7 -2
- package/lib-esm/hooks/useOverlay.d.ts +2 -1
- package/lib-esm/hooks/useOverlay.js +4 -2
- package/lib-esm/index.d.ts +1 -0
- package/lib-esm/index.js +1 -0
- package/lib-esm/utils/scrollIntoViewingArea.d.ts +1 -0
- package/lib-esm/utils/scrollIntoViewingArea.js +30 -0
- package/lib-esm/utils/types/MandateProps.d.ts +3 -0
- package/lib-esm/utils/types/MandateProps.js +1 -0
- package/lib-esm/utils/types/index.d.ts +1 -0
- package/lib-esm/utils/types/index.js +2 -1
- package/package.json +1 -1
package/lib-esm/Overlay.js
CHANGED
@@ -92,6 +92,7 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
|
|
92
92
|
left,
|
93
93
|
anchorSide,
|
94
94
|
portalContainerName,
|
95
|
+
preventFocusOnOpen,
|
95
96
|
...rest
|
96
97
|
}, forwardedRef) => {
|
97
98
|
const overlayRef = useRef(null);
|
@@ -107,7 +108,8 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
|
|
107
108
|
onEscape,
|
108
109
|
ignoreClickRefs,
|
109
110
|
onClickOutside,
|
110
|
-
initialFocusRef
|
111
|
+
initialFocusRef,
|
112
|
+
preventFocusOnOpen
|
111
113
|
});
|
112
114
|
useEffect(() => {
|
113
115
|
var _combinedRef$current;
|
@@ -136,9 +138,7 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
|
|
136
138
|
easing: slideAnimationEasing
|
137
139
|
});
|
138
140
|
}, [anchorSide, slideAnimationDistance, slideAnimationEasing, visibility]);
|
139
|
-
|
140
|
-
containerName: portalContainerName
|
141
|
-
}, /*#__PURE__*/React.createElement(StyledOverlay, _extends({
|
141
|
+
const styledOverlay = /*#__PURE__*/React.createElement(StyledOverlay, _extends({
|
142
142
|
height: height,
|
143
143
|
role: role
|
144
144
|
}, rest, {
|
@@ -149,7 +149,10 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
|
|
149
149
|
...rest.style,
|
150
150
|
'--styled-overlay-visibility': visibility
|
151
151
|
}
|
152
|
-
}))
|
152
|
+
}));
|
153
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
154
|
+
containerName: portalContainerName
|
155
|
+
}, styledOverlay);
|
153
156
|
});
|
154
157
|
Overlay.defaultProps = {
|
155
158
|
height: 'auto',
|
@@ -32,9 +32,7 @@ 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
|
-
} & Omit<Pick<
|
36
|
-
ref?: ((instance: HTMLInputElement | null) => void) | React.RefObject<HTMLInputElement> | null | undefined;
|
37
|
-
}, string | number | symbol> & Omit<Pick<{
|
35
|
+
} & Pick<Omit<Pick<{
|
38
36
|
[x: string]: any;
|
39
37
|
[x: number]: any;
|
40
38
|
} & {
|
@@ -42,12 +40,11 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
|
|
42
40
|
} & {
|
43
41
|
as?: string | React.ComponentType<any> | undefined;
|
44
42
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
45
|
-
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"
|
43
|
+
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
|
46
44
|
className?: string | undefined;
|
47
45
|
icon?: React.ComponentType<{
|
48
46
|
className?: string | undefined;
|
49
47
|
}> | undefined;
|
50
|
-
wrapperRef?: React.RefObject<HTMLSpanElement> | undefined;
|
51
48
|
} & Pick<{
|
52
49
|
color?: string | undefined;
|
53
50
|
maxWidth?: import("styled-system").ResponsiveValue<import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
@@ -318,9 +315,7 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
|
|
318
315
|
contrast?: boolean | undefined;
|
319
316
|
} & {
|
320
317
|
theme?: any;
|
321
|
-
}, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "sx" | "disabled" | "variant" | "contrast"> &
|
322
|
-
as?: "input" | undefined;
|
323
|
-
}, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
318
|
+
}, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "sx" | "disabled" | "variant" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
324
319
|
Footer: import("styled-components").StyledComponent<"footer", any, SystemCommonProps & SxProp, never>;
|
325
320
|
Item: React.ForwardRefExoticComponent<Pick<{
|
326
321
|
as?: React.ElementType<any> | undefined;
|
package/lib-esm/TextInput.d.ts
CHANGED
@@ -1,24 +1,14 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
|
3
|
-
import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
|
4
|
-
import { SxProp } from './sx';
|
5
2
|
import { ComponentProps, Merge } from './utils/types';
|
6
3
|
import UnstyledTextInput from './_UnstyledTextInput';
|
7
|
-
|
8
|
-
disabled?: boolean | undefined;
|
9
|
-
hasIcon?: boolean | undefined;
|
10
|
-
block?: boolean | undefined;
|
11
|
-
contrast?: boolean | undefined;
|
12
|
-
variant?: "large" | "small" | undefined;
|
13
|
-
} & WidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Width<import("styled-system").TLengthStyledSystem>> & MinWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MinWidth<import("styled-system").TLengthStyledSystem>> & MaxWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>> & SxProp, never>;
|
4
|
+
import TextInputWrapper from './_TextInputWrapper';
|
14
5
|
declare type NonPassthroughProps = {
|
15
6
|
className?: string;
|
16
7
|
icon?: React.ComponentType<{
|
17
8
|
className?: string;
|
18
9
|
}>;
|
19
|
-
|
20
|
-
} & Pick<ComponentProps<typeof Wrapper>, 'block' | 'contrast' | 'disabled' | 'sx' | 'theme' | 'width' | 'maxWidth' | 'minWidth' | 'variant'>;
|
10
|
+
} & Pick<ComponentProps<typeof TextInputWrapper>, 'block' | 'contrast' | 'disabled' | 'sx' | 'theme' | 'width' | 'maxWidth' | 'minWidth' | 'variant'>;
|
21
11
|
declare type TextInputInternalProps = Merge<React.ComponentPropsWithoutRef<typeof UnstyledTextInput>, NonPassthroughProps>;
|
22
|
-
declare const TextInput:
|
12
|
+
declare const TextInput: React.ForwardRefExoticComponent<Pick<TextInputInternalProps, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
23
13
|
export declare type TextInputProps = ComponentProps<typeof TextInput>;
|
24
14
|
export default TextInput;
|
package/lib-esm/TextInput.js
CHANGED
@@ -2,37 +2,8 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
2
2
|
|
3
3
|
import classnames from 'classnames';
|
4
4
|
import React from 'react';
|
5
|
-
import styled, { css } from 'styled-components';
|
6
|
-
import { maxWidth, minWidth, variant, width } from 'styled-system';
|
7
|
-
import { get } from './constants';
|
8
|
-
import sx from './sx';
|
9
5
|
import UnstyledTextInput from './_UnstyledTextInput';
|
10
|
-
|
11
|
-
variants: {
|
12
|
-
small: {
|
13
|
-
minHeight: '28px',
|
14
|
-
px: 2,
|
15
|
-
py: '3px',
|
16
|
-
fontSize: 0,
|
17
|
-
lineHeight: '20px'
|
18
|
-
},
|
19
|
-
large: {
|
20
|
-
px: 2,
|
21
|
-
py: '10px',
|
22
|
-
fontSize: 3
|
23
|
-
}
|
24
|
-
}
|
25
|
-
});
|
26
|
-
const Wrapper = styled.span.withConfig({
|
27
|
-
displayName: "TextInput__Wrapper",
|
28
|
-
componentId: "sc-1apmpmt-0"
|
29
|
-
})(["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
|
-
if (props.hasIcon) {
|
31
|
-
return css(["padding:0;"]);
|
32
|
-
} else {
|
33
|
-
return css(["padding:6px 12px;"]);
|
34
|
-
}
|
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);
|
6
|
+
import TextInputWrapper from './_TextInputWrapper';
|
36
7
|
// using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input
|
37
8
|
const TextInput = /*#__PURE__*/React.forwardRef(({
|
38
9
|
icon: IconComponent,
|
@@ -46,12 +17,11 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
46
17
|
minWidth: minWidthProp,
|
47
18
|
maxWidth: maxWidthProp,
|
48
19
|
variant: variantProp,
|
49
|
-
wrapperRef,
|
50
20
|
...inputProps
|
51
21
|
}, ref) => {
|
52
22
|
// this class is necessary to style FilterSearch, plz no touchy!
|
53
23
|
const wrapperClasses = classnames(className, 'TextInput-wrapper');
|
54
|
-
return /*#__PURE__*/React.createElement(
|
24
|
+
return /*#__PURE__*/React.createElement(TextInputWrapper, {
|
55
25
|
block: block,
|
56
26
|
className: wrapperClasses,
|
57
27
|
contrast: contrast,
|
@@ -62,8 +32,7 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
62
32
|
width: widthProp,
|
63
33
|
minWidth: minWidthProp,
|
64
34
|
maxWidth: maxWidthProp,
|
65
|
-
variant: variantProp
|
66
|
-
ref: wrapperRef
|
35
|
+
variant: variantProp
|
67
36
|
}, IconComponent && /*#__PURE__*/React.createElement(IconComponent, {
|
68
37
|
className: "TextInput-icon"
|
69
38
|
}), /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
|
@@ -2,11 +2,11 @@ import React from 'react';
|
|
2
2
|
import { ComponentProps } from './utils/types';
|
3
3
|
import { TokenSizeKeys } from './Token/TokenBase';
|
4
4
|
declare type AnyReactComponent = React.ComponentType<any>;
|
5
|
-
declare
|
5
|
+
declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<{
|
6
6
|
/**
|
7
7
|
* The array of tokens to render
|
8
8
|
*/
|
9
|
-
tokens:
|
9
|
+
tokens: any[];
|
10
10
|
/**
|
11
11
|
* The function that gets called when a token is removed
|
12
12
|
*/
|
@@ -14,7 +14,7 @@ declare type TextInputWithTokensInternalProps<TokenComponentType extends AnyReac
|
|
14
14
|
/**
|
15
15
|
* The component used to render each token
|
16
16
|
*/
|
17
|
-
tokenComponent?:
|
17
|
+
tokenComponent?: AnyReactComponent | undefined;
|
18
18
|
/**
|
19
19
|
* The maximum height of the component. If the content in the input exceeds this height,
|
20
20
|
* it will scroll vertically
|
@@ -23,19 +23,16 @@ declare type TextInputWithTokensInternalProps<TokenComponentType extends AnyReac
|
|
23
23
|
/**
|
24
24
|
* Whether tokens should render inline horizontally. By default, tokens wrap to new lines.
|
25
25
|
*/
|
26
|
-
preventTokenWrapping?: boolean;
|
26
|
+
preventTokenWrapping?: boolean | undefined;
|
27
27
|
/**
|
28
28
|
* The size of the tokens
|
29
29
|
*/
|
30
|
-
size?: TokenSizeKeys;
|
30
|
+
size?: TokenSizeKeys | undefined;
|
31
31
|
/**
|
32
32
|
* Whether the remove buttons should be rendered in the tokens
|
33
33
|
*/
|
34
|
-
hideTokenRemoveButtons?: boolean;
|
35
|
-
}
|
36
|
-
declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<TextInputWithTokensInternalProps<AnyReactComponent> & Omit<Pick<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "key" | keyof React.InputHTMLAttributes<HTMLInputElement>> & {
|
37
|
-
ref?: ((instance: HTMLInputElement | null) => void) | React.RefObject<HTMLInputElement> | null | undefined;
|
38
|
-
}, string | number | symbol> & Omit<Pick<{
|
34
|
+
hideTokenRemoveButtons?: boolean | undefined;
|
35
|
+
} & Pick<Omit<Pick<{
|
39
36
|
[x: string]: any;
|
40
37
|
[x: number]: any;
|
41
38
|
} & {
|
@@ -43,12 +40,11 @@ declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<TextInpu
|
|
43
40
|
} & {
|
44
41
|
as?: string | React.ComponentType<any> | undefined;
|
45
42
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
46
|
-
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"
|
43
|
+
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
|
47
44
|
className?: string | undefined;
|
48
45
|
icon?: React.ComponentType<{
|
49
46
|
className?: string | undefined;
|
50
47
|
}> | undefined;
|
51
|
-
wrapperRef?: React.RefObject<HTMLSpanElement> | undefined;
|
52
48
|
} & Pick<{
|
53
49
|
color?: string | undefined;
|
54
50
|
maxWidth?: import("styled-system").ResponsiveValue<import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
@@ -319,8 +315,9 @@ declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<TextInpu
|
|
319
315
|
contrast?: boolean | undefined;
|
320
316
|
} & {
|
321
317
|
theme?: any;
|
322
|
-
}, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "sx" | "disabled" | "variant" | "contrast"> & {
|
323
|
-
|
318
|
+
}, "maxWidth" | "minWidth" | "width" | "theme" | "block" | "sx" | "disabled" | "variant" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement> & {
|
319
|
+
selectedTokenIndex: number | undefined;
|
320
|
+
setSelectedTokenIndex: React.Dispatch<React.SetStateAction<number | undefined>>;
|
324
321
|
}, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
325
322
|
export declare type TextInputWithTokensProps = ComponentProps<typeof TextInputWithTokens>;
|
326
323
|
export default TextInputWithTokens;
|
@@ -2,37 +2,89 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
2
2
|
|
3
3
|
import React, { useRef, useState } from 'react';
|
4
4
|
import { omit } from '@styled-system/props';
|
5
|
-
import styled from 'styled-components';
|
6
5
|
import { FocusKeys } from './behaviors/focusZone';
|
7
6
|
import { useCombinedRefs } from './hooks/useCombinedRefs';
|
8
7
|
import { useFocusZone } from './hooks/useFocusZone';
|
9
8
|
import Token from './Token/Token';
|
10
|
-
import TextInput from './TextInput';
|
11
9
|
import { useProvidedRefOrCreate } from './hooks';
|
12
10
|
import UnstyledTextInput from './_UnstyledTextInput';
|
13
|
-
|
14
|
-
|
15
|
-
componentId: "sc-8z94t5-0"
|
16
|
-
})(["order:1;flex-grow:1;"]); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
11
|
+
import TextInputWrapper from './_TextInputWrapper';
|
12
|
+
import Box from './Box'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
17
13
|
|
18
|
-
//
|
19
|
-
// prop of the `TextInput` component
|
14
|
+
// using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
20
15
|
function TextInputWithTokensInnerComponent({
|
16
|
+
icon: IconComponent,
|
17
|
+
contrast,
|
18
|
+
className,
|
19
|
+
block,
|
20
|
+
disabled,
|
21
|
+
theme,
|
22
|
+
sx: sxProp,
|
21
23
|
tokens,
|
22
24
|
onTokenRemove,
|
23
25
|
tokenComponent: TokenComponent,
|
26
|
+
preventTokenWrapping,
|
24
27
|
size,
|
25
28
|
hideTokenRemoveButtons,
|
26
|
-
|
27
|
-
|
29
|
+
maxHeight,
|
30
|
+
width: widthProp,
|
31
|
+
minWidth: minWidthProp,
|
32
|
+
maxWidth: maxWidthProp,
|
33
|
+
variant: variantProp,
|
28
34
|
...rest
|
29
35
|
}, externalRef) {
|
30
|
-
const ref = useProvidedRefOrCreate(externalRef);
|
31
36
|
const {
|
32
37
|
onFocus,
|
33
38
|
onKeyDown,
|
34
39
|
...inputPropsRest
|
35
40
|
} = omit(rest);
|
41
|
+
const ref = useProvidedRefOrCreate(externalRef);
|
42
|
+
const localInputRef = useRef(null);
|
43
|
+
const combinedInputRef = useCombinedRefs(localInputRef, ref);
|
44
|
+
const [selectedTokenIndex, setSelectedTokenIndex] = useState();
|
45
|
+
const {
|
46
|
+
containerRef
|
47
|
+
} = useFocusZone({
|
48
|
+
focusOutBehavior: 'wrap',
|
49
|
+
bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
|
50
|
+
focusableElementFilter: element => {
|
51
|
+
return !element.getAttributeNames().includes('aria-hidden');
|
52
|
+
},
|
53
|
+
getNextFocusable: direction => {
|
54
|
+
var _containerRef$current;
|
55
|
+
|
56
|
+
if (!selectedTokenIndex && selectedTokenIndex !== 0) {
|
57
|
+
return undefined;
|
58
|
+
}
|
59
|
+
|
60
|
+
let nextIndex = selectedTokenIndex + 1; // "+ 1" accounts for the first element: the text input
|
61
|
+
|
62
|
+
if (direction === 'next') {
|
63
|
+
nextIndex += 1;
|
64
|
+
}
|
65
|
+
|
66
|
+
if (direction === 'previous') {
|
67
|
+
nextIndex -= 1;
|
68
|
+
}
|
69
|
+
|
70
|
+
if (nextIndex > tokens.length || nextIndex < 1) {
|
71
|
+
return combinedInputRef.current || undefined;
|
72
|
+
}
|
73
|
+
|
74
|
+
return (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
|
75
|
+
}
|
76
|
+
}, [selectedTokenIndex]);
|
77
|
+
|
78
|
+
const handleTokenRemove = tokenId => {
|
79
|
+
onTokenRemove(tokenId);
|
80
|
+
|
81
|
+
if (selectedTokenIndex) {
|
82
|
+
var _containerRef$current2;
|
83
|
+
|
84
|
+
const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
|
85
|
+
nextElementToFocus.focus();
|
86
|
+
}
|
87
|
+
};
|
36
88
|
|
37
89
|
const handleTokenFocus = tokenIndex => () => {
|
38
90
|
setSelectedTokenIndex(tokenIndex);
|
@@ -42,24 +94,24 @@ function TextInputWithTokensInnerComponent({
|
|
42
94
|
setSelectedTokenIndex(undefined);
|
43
95
|
};
|
44
96
|
|
45
|
-
const handleTokenKeyUp =
|
46
|
-
if (
|
97
|
+
const handleTokenKeyUp = e => {
|
98
|
+
if (e.key === 'Escape') {
|
47
99
|
var _ref$current;
|
48
100
|
|
49
101
|
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
50
102
|
}
|
51
103
|
};
|
52
104
|
|
53
|
-
const handleInputFocus =
|
54
|
-
onFocus && onFocus(
|
105
|
+
const handleInputFocus = e => {
|
106
|
+
onFocus && onFocus(e);
|
55
107
|
setSelectedTokenIndex(undefined);
|
56
108
|
};
|
57
109
|
|
58
|
-
const handleInputKeyDown =
|
110
|
+
const handleInputKeyDown = e => {
|
59
111
|
var _ref$current2;
|
60
112
|
|
61
113
|
if (onKeyDown) {
|
62
|
-
onKeyDown(
|
114
|
+
onKeyDown(e);
|
63
115
|
}
|
64
116
|
|
65
117
|
if ((_ref$current2 = ref.current) !== null && _ref$current2 !== void 0 && _ref$current2.value) {
|
@@ -68,8 +120,8 @@ function TextInputWithTokensInnerComponent({
|
|
68
120
|
|
69
121
|
const lastToken = tokens[tokens.length - 1];
|
70
122
|
|
71
|
-
if (
|
72
|
-
|
123
|
+
if (e.key === 'Backspace' && lastToken) {
|
124
|
+
handleTokenRemove(lastToken.id);
|
73
125
|
|
74
126
|
if (ref.current) {
|
75
127
|
// TODO: eliminate the first hack by making changes to the Autocomplete component
|
@@ -90,10 +142,48 @@ function TextInputWithTokensInnerComponent({
|
|
90
142
|
}
|
91
143
|
};
|
92
144
|
|
93
|
-
return /*#__PURE__*/React.createElement(
|
94
|
-
|
95
|
-
|
96
|
-
|
145
|
+
return /*#__PURE__*/React.createElement(TextInputWrapper, {
|
146
|
+
block: block,
|
147
|
+
className: className,
|
148
|
+
contrast: contrast,
|
149
|
+
disabled: disabled,
|
150
|
+
hasIcon: !!IconComponent,
|
151
|
+
theme: theme,
|
152
|
+
width: widthProp,
|
153
|
+
minWidth: minWidthProp,
|
154
|
+
maxWidth: maxWidthProp,
|
155
|
+
variant: variantProp,
|
156
|
+
ref: containerRef,
|
157
|
+
sx: {
|
158
|
+
alignItems: 'center',
|
159
|
+
flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
|
160
|
+
gap: '0.25rem',
|
161
|
+
'> *': {
|
162
|
+
flexShrink: 0
|
163
|
+
},
|
164
|
+
...(block ? {
|
165
|
+
display: 'flex',
|
166
|
+
width: '100%'
|
167
|
+
} : {}),
|
168
|
+
...(maxHeight ? {
|
169
|
+
maxHeight,
|
170
|
+
overflow: 'auto'
|
171
|
+
} : {}),
|
172
|
+
...(preventTokenWrapping ? {
|
173
|
+
overflow: 'auto'
|
174
|
+
} : {}),
|
175
|
+
...sxProp
|
176
|
+
}
|
177
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
178
|
+
sx: {
|
179
|
+
order: 1,
|
180
|
+
flexGrow: 1
|
181
|
+
}
|
182
|
+
}, IconComponent && /*#__PURE__*/React.createElement(IconComponent, {
|
183
|
+
className: "TextInput-icon"
|
184
|
+
}), /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
|
185
|
+
ref: combinedInputRef,
|
186
|
+
disabled: disabled,
|
97
187
|
onFocus: handleInputFocus,
|
98
188
|
onKeyDown: handleInputKeyDown,
|
99
189
|
type: "text",
|
@@ -110,107 +200,19 @@ function TextInputWithTokensInnerComponent({
|
|
110
200
|
onKeyUp: handleTokenKeyUp,
|
111
201
|
isSelected: selectedTokenIndex === i,
|
112
202
|
onRemove: () => {
|
113
|
-
|
203
|
+
handleTokenRemove(id);
|
114
204
|
},
|
115
205
|
hideRemoveButton: hideTokenRemoveButtons,
|
116
206
|
size: size,
|
117
207
|
tabIndex: 0
|
118
208
|
}, tokenRest))) : null);
|
119
|
-
} // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
120
|
-
|
121
|
-
|
122
|
-
const TextInputWithTokensInnerComponentWithRef = /*#__PURE__*/React.forwardRef(TextInputWithTokensInnerComponent);
|
123
|
-
|
124
|
-
function TextInputWithTokensComponent({
|
125
|
-
tokens,
|
126
|
-
onTokenRemove,
|
127
|
-
sx: sxProp,
|
128
|
-
...props
|
129
|
-
}, ref) {
|
130
|
-
const localInputRef = useRef(null);
|
131
|
-
const combinedInputRef = useCombinedRefs(localInputRef, ref);
|
132
|
-
const [selectedTokenIndex, setSelectedTokenIndex] = useState();
|
133
|
-
const {
|
134
|
-
containerRef
|
135
|
-
} = useFocusZone({
|
136
|
-
focusOutBehavior: 'wrap',
|
137
|
-
bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
|
138
|
-
focusableElementFilter: element => {
|
139
|
-
return !element.getAttributeNames().includes('aria-hidden');
|
140
|
-
},
|
141
|
-
getNextFocusable: direction => {
|
142
|
-
var _containerRef$current;
|
143
|
-
|
144
|
-
if (!selectedTokenIndex && selectedTokenIndex !== 0) {
|
145
|
-
return undefined;
|
146
|
-
}
|
147
|
-
|
148
|
-
let nextIndex = selectedTokenIndex + 1; // "+ 1" accounts for the first element: the text input
|
149
|
-
|
150
|
-
if (direction === 'next') {
|
151
|
-
nextIndex += 1;
|
152
|
-
}
|
153
|
-
|
154
|
-
if (direction === 'previous') {
|
155
|
-
nextIndex -= 1;
|
156
|
-
}
|
157
|
-
|
158
|
-
if (nextIndex > tokens.length || nextIndex < 1) {
|
159
|
-
return combinedInputRef.current || undefined;
|
160
|
-
}
|
161
|
-
|
162
|
-
return (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
|
163
|
-
}
|
164
|
-
}, [selectedTokenIndex]);
|
165
|
-
|
166
|
-
const handleTokenRemove = tokenId => {
|
167
|
-
onTokenRemove(tokenId);
|
168
|
-
|
169
|
-
if (selectedTokenIndex) {
|
170
|
-
var _containerRef$current2;
|
171
|
-
|
172
|
-
const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
|
173
|
-
nextElementToFocus.focus();
|
174
|
-
}
|
175
|
-
};
|
176
|
-
|
177
|
-
return /*#__PURE__*/React.createElement(TextInput, _extends({
|
178
|
-
ref: combinedInputRef,
|
179
|
-
wrapperRef: containerRef,
|
180
|
-
as: TextInputWithTokensInnerComponentWithRef,
|
181
|
-
selectedTokenIndex: selectedTokenIndex,
|
182
|
-
setSelectedTokenIndex: setSelectedTokenIndex,
|
183
|
-
tokens: tokens,
|
184
|
-
onTokenRemove: handleTokenRemove,
|
185
|
-
sx: {
|
186
|
-
alignItems: 'center',
|
187
|
-
flexWrap: props.preventTokenWrapping ? 'nowrap' : 'wrap',
|
188
|
-
gap: '0.25rem',
|
189
|
-
'> *': {
|
190
|
-
flexShrink: 0
|
191
|
-
},
|
192
|
-
...(props.block ? {
|
193
|
-
display: 'flex',
|
194
|
-
width: '100%'
|
195
|
-
} : {}),
|
196
|
-
...(props.maxHeight ? {
|
197
|
-
maxHeight: props.maxHeight,
|
198
|
-
overflow: 'auto'
|
199
|
-
} : {}),
|
200
|
-
...(props.preventTokenWrapping ? {
|
201
|
-
overflow: 'auto'
|
202
|
-
} : {}),
|
203
|
-
...sxProp
|
204
|
-
}
|
205
|
-
}, props));
|
206
209
|
}
|
207
210
|
|
208
|
-
|
209
|
-
|
210
|
-
const TextInputWithTokens = /*#__PURE__*/React.forwardRef(TextInputWithTokensComponent);
|
211
|
+
TextInputWithTokensInnerComponent.displayName = "TextInputWithTokensInnerComponent";
|
212
|
+
const TextInputWithTokens = /*#__PURE__*/React.forwardRef(TextInputWithTokensInnerComponent);
|
211
213
|
TextInputWithTokens.defaultProps = {
|
212
214
|
tokenComponent: Token,
|
213
|
-
size: '
|
215
|
+
size: 'extralarge',
|
214
216
|
hideTokenRemoveButtons: false
|
215
217
|
};
|
216
218
|
TextInputWithTokens.displayName = 'TextInputWithTokens';
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
|
2
|
+
import { SxProp } from './sx';
|
3
|
+
declare const TextInputWrapper: import("styled-components").StyledComponent<"span", any, {
|
4
|
+
disabled?: boolean | undefined;
|
5
|
+
hasIcon?: boolean | undefined;
|
6
|
+
block?: boolean | undefined;
|
7
|
+
contrast?: boolean | undefined;
|
8
|
+
variant?: "large" | "small" | undefined;
|
9
|
+
} & WidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Width<import("styled-system").TLengthStyledSystem>> & MinWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MinWidth<import("styled-system").TLengthStyledSystem>> & MaxWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>> & SxProp, never>;
|
10
|
+
export default TextInputWrapper;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import styled, { css } from 'styled-components';
|
2
|
+
import { maxWidth, minWidth, variant, width } from 'styled-system';
|
3
|
+
import { get } from './constants';
|
4
|
+
import sx from './sx';
|
5
|
+
const sizeVariants = variant({
|
6
|
+
variants: {
|
7
|
+
small: {
|
8
|
+
minHeight: '28px',
|
9
|
+
px: 2,
|
10
|
+
py: '3px',
|
11
|
+
fontSize: 0,
|
12
|
+
lineHeight: '20px'
|
13
|
+
},
|
14
|
+
large: {
|
15
|
+
px: 2,
|
16
|
+
py: '10px',
|
17
|
+
fontSize: 3
|
18
|
+
}
|
19
|
+
}
|
20
|
+
});
|
21
|
+
const TextInputWrapper = styled.span.withConfig({
|
22
|
+
displayName: "_TextInputWrapper__TextInputWrapper",
|
23
|
+
componentId: "sc-5vfcis-0"
|
24
|
+
})(["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 => {
|
25
|
+
if (props.hasIcon) {
|
26
|
+
return css(["padding:0;"]);
|
27
|
+
} else {
|
28
|
+
return css(["padding:6px 12px;"]);
|
29
|
+
}
|
30
|
+
}, 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);
|
31
|
+
export default TextInputWrapper;
|
@@ -3,5 +3,6 @@ export declare type UseOpenAndCloseFocusSettings = {
|
|
3
3
|
initialFocusRef?: React.RefObject<HTMLElement>;
|
4
4
|
containerRef: React.RefObject<HTMLElement>;
|
5
5
|
returnFocusRef: React.RefObject<HTMLElement>;
|
6
|
+
preventFocusOnOpen?: boolean;
|
6
7
|
};
|
7
|
-
export declare function useOpenAndCloseFocus({ initialFocusRef, returnFocusRef, containerRef }: UseOpenAndCloseFocusSettings): void;
|
8
|
+
export declare function useOpenAndCloseFocus({ initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen }: UseOpenAndCloseFocusSettings): void;
|
@@ -3,9 +3,14 @@ import { iterateFocusableElements } from '../utils/iterateFocusableElements';
|
|
3
3
|
export function useOpenAndCloseFocus({
|
4
4
|
initialFocusRef,
|
5
5
|
returnFocusRef,
|
6
|
-
containerRef
|
6
|
+
containerRef,
|
7
|
+
preventFocusOnOpen
|
7
8
|
}) {
|
8
9
|
useEffect(() => {
|
10
|
+
if (preventFocusOnOpen) {
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
|
9
14
|
const returnRef = returnFocusRef.current;
|
10
15
|
|
11
16
|
if (initialFocusRef && initialFocusRef.current) {
|
@@ -18,5 +23,5 @@ export function useOpenAndCloseFocus({
|
|
18
23
|
return function () {
|
19
24
|
returnRef === null || returnRef === void 0 ? void 0 : returnRef.focus();
|
20
25
|
};
|
21
|
-
}, [initialFocusRef, returnFocusRef, containerRef]);
|
26
|
+
}, [initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen]);
|
22
27
|
}
|
@@ -7,8 +7,9 @@ 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;
|
10
11
|
};
|
11
12
|
export declare type OverlayReturnProps = {
|
12
13
|
ref: React.RefObject<HTMLDivElement>;
|
13
14
|
};
|
14
|
-
export declare const useOverlay: ({ overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside }: UseOverlaySettings) => OverlayReturnProps;
|
15
|
+
export declare const useOverlay: ({ overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside, preventFocusOnOpen }: UseOverlaySettings) => OverlayReturnProps;
|
@@ -8,13 +8,15 @@ export const useOverlay = ({
|
|
8
8
|
initialFocusRef,
|
9
9
|
onEscape,
|
10
10
|
ignoreClickRefs,
|
11
|
-
onClickOutside
|
11
|
+
onClickOutside,
|
12
|
+
preventFocusOnOpen
|
12
13
|
}) => {
|
13
14
|
const overlayRef = useProvidedRefOrCreate(_overlayRef);
|
14
15
|
useOpenAndCloseFocus({
|
15
16
|
containerRef: overlayRef,
|
16
17
|
returnFocusRef,
|
17
|
-
initialFocusRef
|
18
|
+
initialFocusRef,
|
19
|
+
preventFocusOnOpen
|
18
20
|
});
|
19
21
|
useOnOutsideClick({
|
20
22
|
containerRef: overlayRef,
|