@primer/components 0.0.0-202194183411 → 0.0.0-202194215436
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/browser.esm.js +295 -299
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +358 -362
- 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-esm/Token/TokenLabel.d.ts → lib/Token/LabelToken.d.ts} +3 -3
- package/lib/Token/{TokenLabel.js → LabelToken.js} +23 -23
- package/lib/Token/Token.d.ts +2 -2
- package/lib/Token/Token.js +13 -13
- package/lib/Token/TokenBase.d.ts +3 -3
- package/lib/Token/TokenBase.js +17 -16
- package/lib/Token/TokenProfile.d.ts +1 -1
- package/lib/Token/TokenProfile.js +3 -3
- package/lib/Token/_RemoveTokenButton.d.ts +7 -1
- package/lib/Token/_RemoveTokenButton.js +40 -11
- package/lib/Token/index.d.ts +1 -1
- package/lib/Token/index.js +3 -3
- package/lib/hooks/useOverlay.d.ts +1 -2
- package/lib/hooks/useOverlay.js +6 -11
- package/lib/index.d.ts +1 -3
- package/lib/index.js +2 -18
- 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/Token/TokenLabel.d.ts → lib-esm/Token/LabelToken.d.ts} +3 -3
- package/lib-esm/Token/{TokenLabel.js → LabelToken.js} +23 -23
- package/lib-esm/Token/Token.d.ts +2 -2
- package/lib-esm/Token/Token.js +13 -13
- package/lib-esm/Token/TokenBase.d.ts +3 -3
- package/lib-esm/Token/TokenBase.js +17 -16
- package/lib-esm/Token/TokenProfile.d.ts +1 -1
- package/lib-esm/Token/TokenProfile.js +3 -3
- package/lib-esm/Token/_RemoveTokenButton.d.ts +7 -1
- package/lib-esm/Token/_RemoveTokenButton.js +36 -10
- package/lib-esm/Token/index.d.ts +1 -1
- package/lib-esm/Token/index.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 +1 -3
- package/lib-esm/index.js +1 -3
- 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 -146
- 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 -71
- 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/Token/_tokenButtonUtils.d.ts +0 -10
- package/lib/Token/_tokenButtonUtils.js +0 -42
- package/lib/_UnstyledTextInput.d.ts +0 -2
- package/lib/_UnstyledTextInput.js +0 -20
- package/lib/utils/scrollIntoViewingArea.d.ts +0 -1
- package/lib/utils/scrollIntoViewingArea.js +0 -39
- package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -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 -127
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -71
- package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -202
- package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +0 -17
- package/lib-esm/Autocomplete/AutocompleteOverlay.js +0 -53
- 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/Token/_tokenButtonUtils.d.ts +0 -10
- package/lib-esm/Token/_tokenButtonUtils.js +0 -26
- package/lib-esm/_UnstyledTextInput.d.ts +0 -2
- package/lib-esm/_UnstyledTextInput.js +0 -7
- package/lib-esm/utils/scrollIntoViewingArea.d.ts +0 -1
- package/lib-esm/utils/scrollIntoViewingArea.js +0 -30
@@ -1,209 +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, { useRef, useState } from 'react';
|
4
|
-
import { omit } from '@styled-system/props';
|
5
|
-
import styled from 'styled-components';
|
6
|
-
import { FocusKeys } from './behaviors/focusZone';
|
7
|
-
import { useCombinedRefs } from './hooks/useCombinedRefs';
|
8
|
-
import { useFocusZone } from './hooks/useFocusZone';
|
9
|
-
import Token from './Token/Token';
|
10
|
-
import TextInput from './TextInput';
|
11
|
-
import { useProvidedRefOrCreate } from './hooks';
|
12
|
-
import UnstyledTextInput from './_UnstyledTextInput';
|
13
|
-
const InputWrapper = styled.div.withConfig({
|
14
|
-
displayName: "TextInputWithTokens__InputWrapper",
|
15
|
-
componentId: "sc-8z94t5-0"
|
16
|
-
})(["order:1;flex-grow:1;"]);
|
17
|
-
// using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
18
|
-
const TextInputWithTokensComponent = /*#__PURE__*/React.forwardRef(({
|
19
|
-
icon: IconComponent,
|
20
|
-
contrast,
|
21
|
-
className,
|
22
|
-
block,
|
23
|
-
disabled,
|
24
|
-
theme,
|
25
|
-
sx: sxProp,
|
26
|
-
tokens,
|
27
|
-
onTokenRemove,
|
28
|
-
tokenComponent: TokenComponent,
|
29
|
-
preventTokenWrapping,
|
30
|
-
tokenSizeVariant,
|
31
|
-
hideTokenRemoveButtons,
|
32
|
-
selectedTokenIdx,
|
33
|
-
setSelectedTokenIdx,
|
34
|
-
...rest
|
35
|
-
}, externalRef) => {
|
36
|
-
const ref = useProvidedRefOrCreate(externalRef);
|
37
|
-
const {
|
38
|
-
onFocus,
|
39
|
-
onKeyDown,
|
40
|
-
...inputPropsRest
|
41
|
-
} = omit(rest);
|
42
|
-
|
43
|
-
const handleTokenFocus = tokenIdx => () => {
|
44
|
-
setSelectedTokenIdx(tokenIdx);
|
45
|
-
};
|
46
|
-
|
47
|
-
const handleTokenBlur = () => {
|
48
|
-
setSelectedTokenIdx(undefined);
|
49
|
-
};
|
50
|
-
|
51
|
-
const handleTokenKeyUp = e => {
|
52
|
-
if (e.key === 'Escape') {
|
53
|
-
var _ref$current;
|
54
|
-
|
55
|
-
ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
56
|
-
}
|
57
|
-
};
|
58
|
-
|
59
|
-
const handleInputFocus = e => {
|
60
|
-
onFocus && onFocus(e);
|
61
|
-
setSelectedTokenIdx(undefined);
|
62
|
-
};
|
63
|
-
|
64
|
-
const handleInputKeyDown = e => {
|
65
|
-
var _ref$current2;
|
66
|
-
|
67
|
-
if (onKeyDown) {
|
68
|
-
onKeyDown(e);
|
69
|
-
}
|
70
|
-
|
71
|
-
if (ref !== null && ref !== void 0 && (_ref$current2 = ref.current) !== null && _ref$current2 !== void 0 && _ref$current2.value) {
|
72
|
-
return;
|
73
|
-
}
|
74
|
-
|
75
|
-
const lastToken = tokens[tokens.length - 1];
|
76
|
-
|
77
|
-
if (e.key === 'Backspace' && lastToken) {
|
78
|
-
onTokenRemove(lastToken.id);
|
79
|
-
|
80
|
-
if (ref !== null && ref !== void 0 && ref.current) {
|
81
|
-
// TODO: eliminate the first hack by making changes to the Autocomplete component
|
82
|
-
//
|
83
|
-
// HACKS:
|
84
|
-
// 1. Directly setting `ref.current.value` instead of updating state because the autocomplete
|
85
|
-
// highlight behavior doesn't work correctly if we update the value with a setState action in onChange
|
86
|
-
// 2. Adding an extra space so that when I backspace, it doesn't delete the last letter
|
87
|
-
ref.current.value = `${lastToken.text} `;
|
88
|
-
} // HACK: for some reason we need to wait a tick for `.select()` to work
|
89
|
-
|
90
|
-
|
91
|
-
setTimeout(() => {
|
92
|
-
var _ref$current3;
|
93
|
-
|
94
|
-
ref === null || ref === void 0 ? void 0 : (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.select();
|
95
|
-
}, 1);
|
96
|
-
}
|
97
|
-
};
|
98
|
-
|
99
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(InputWrapper, {
|
100
|
-
key: "inputWrapper"
|
101
|
-
}, /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
|
102
|
-
ref: ref,
|
103
|
-
disabled: disabled,
|
104
|
-
onFocus: handleInputFocus,
|
105
|
-
onKeyDown: handleInputKeyDown,
|
106
|
-
type: "text",
|
107
|
-
sx: {
|
108
|
-
height: '100%'
|
109
|
-
}
|
110
|
-
}, inputPropsRest))), tokens !== null && tokens !== void 0 && tokens.length && TokenComponent ? tokens.map(({
|
111
|
-
id,
|
112
|
-
...tokenRest
|
113
|
-
}, i) => /*#__PURE__*/React.createElement(TokenComponent, _extends({
|
114
|
-
key: id,
|
115
|
-
onFocus: handleTokenFocus(i),
|
116
|
-
onBlur: handleTokenBlur,
|
117
|
-
onKeyUp: handleTokenKeyUp,
|
118
|
-
isSelected: selectedTokenIdx === i,
|
119
|
-
handleRemove: () => {
|
120
|
-
onTokenRemove(id);
|
121
|
-
},
|
122
|
-
hideRemoveButton: hideTokenRemoveButtons,
|
123
|
-
variant: tokenSizeVariant,
|
124
|
-
tabIndex: 0
|
125
|
-
}, tokenRest))) : null);
|
126
|
-
});
|
127
|
-
const TextInputWithTokens = /*#__PURE__*/React.forwardRef(({
|
128
|
-
tokens,
|
129
|
-
onTokenRemove,
|
130
|
-
sx: sxProp,
|
131
|
-
...props
|
132
|
-
}, ref) => {
|
133
|
-
const localInputRef = useRef(null);
|
134
|
-
const combinedInputRef = useCombinedRefs(localInputRef, ref);
|
135
|
-
const [selectedTokenIdx, setSelectedTokenIdx] = useState();
|
136
|
-
const {
|
137
|
-
containerRef
|
138
|
-
} = useFocusZone({
|
139
|
-
focusOutBehavior: 'wrap',
|
140
|
-
bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
|
141
|
-
focusableElementFilter: element => {
|
142
|
-
return !element.getAttributeNames().includes('aria-hidden');
|
143
|
-
},
|
144
|
-
getNextFocusable: direction => {
|
145
|
-
var _containerRef$current;
|
146
|
-
|
147
|
-
if (!selectedTokenIdx && selectedTokenIdx !== 0) {
|
148
|
-
return undefined;
|
149
|
-
}
|
150
|
-
|
151
|
-
let nextIndex = selectedTokenIdx + 1; // "+ 1" accounts for the first element: the text input
|
152
|
-
|
153
|
-
if (direction === 'next') {
|
154
|
-
nextIndex += 1;
|
155
|
-
}
|
156
|
-
|
157
|
-
if (direction === 'previous') {
|
158
|
-
nextIndex -= 1;
|
159
|
-
}
|
160
|
-
|
161
|
-
if (nextIndex > tokens.length || nextIndex < 1) {
|
162
|
-
return combinedInputRef.current || undefined;
|
163
|
-
}
|
164
|
-
|
165
|
-
return containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
|
166
|
-
}
|
167
|
-
}, [selectedTokenIdx]);
|
168
|
-
|
169
|
-
const handleTokenRemove = tokenId => {
|
170
|
-
onTokenRemove(tokenId);
|
171
|
-
|
172
|
-
if (selectedTokenIdx) {
|
173
|
-
var _containerRef$current2;
|
174
|
-
|
175
|
-
const nextElementToFocus = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIdx];
|
176
|
-
nextElementToFocus.focus();
|
177
|
-
}
|
178
|
-
};
|
179
|
-
|
180
|
-
return /*#__PURE__*/React.createElement(TextInput, _extends({
|
181
|
-
ref: combinedInputRef,
|
182
|
-
wrapperRef: containerRef,
|
183
|
-
as: TextInputWithTokensComponent,
|
184
|
-
selectedTokenIdx: selectedTokenIdx,
|
185
|
-
setSelectedTokenIdx: setSelectedTokenIdx,
|
186
|
-
tokens: tokens,
|
187
|
-
onTokenRemove: handleTokenRemove,
|
188
|
-
sx: {
|
189
|
-
'alignItems': 'center',
|
190
|
-
'flexWrap': props.preventTokenWrapping ? 'nowrap' : 'wrap',
|
191
|
-
'gap': '0.25rem',
|
192
|
-
'> *': {
|
193
|
-
'flexShrink': 0
|
194
|
-
},
|
195
|
-
...(props.block ? {
|
196
|
-
display: 'flex',
|
197
|
-
width: '100%'
|
198
|
-
} : {}),
|
199
|
-
...sxProp
|
200
|
-
}
|
201
|
-
}, props));
|
202
|
-
});
|
203
|
-
TextInputWithTokens.defaultProps = {
|
204
|
-
tokenComponent: Token,
|
205
|
-
tokenSizeVariant: "xl",
|
206
|
-
hideTokenRemoveButtons: false
|
207
|
-
};
|
208
|
-
TextInputWithTokens.displayName = 'TextInputWithTokens';
|
209
|
-
export default TextInputWithTokens;
|
@@ -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,26 +0,0 @@
|
|
1
|
-
import { css } from 'styled-components';
|
2
|
-
import { variant } from 'styled-system';
|
3
|
-
import { get } from '../constants';
|
4
|
-
import { tokenSizes, defaultTokenSize } from "./TokenBase";
|
5
|
-
export const variants = variant({
|
6
|
-
variants: {
|
7
|
-
sm: {
|
8
|
-
height: `${tokenSizes.sm}px`,
|
9
|
-
width: `${tokenSizes.sm}px`
|
10
|
-
},
|
11
|
-
md: {
|
12
|
-
height: `${tokenSizes.md}px`,
|
13
|
-
width: `${tokenSizes.md}px`
|
14
|
-
},
|
15
|
-
lg: {
|
16
|
-
height: `${tokenSizes.lg}px`,
|
17
|
-
width: `${tokenSizes.lg}px`
|
18
|
-
},
|
19
|
-
xl: {
|
20
|
-
height: `${tokenSizes.xl}px`,
|
21
|
-
width: `${tokenSizes.xl}px`
|
22
|
-
}
|
23
|
-
}
|
24
|
-
});
|
25
|
-
export const tokenButtonStyles = 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:", ";}"], get('colors.fade.fg10'), get('colors.fade.fg15'));
|
26
|
-
export const getTokenButtonIconSize = variant => tokenSizes[variant || defaultTokenSize] * 0.75;
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import styled from "styled-components";
|
2
|
-
import sx from './sx';
|
3
|
-
const UnstyledTextInput = styled.input.withConfig({
|
4
|
-
displayName: "_UnstyledTextInput__UnstyledTextInput",
|
5
|
-
componentId: "sc-1jgl33s-0"
|
6
|
-
})(["border:0;font-size:inherit;font-family:inherit;background-color:transparent;-webkit-appearance:none;color:inherit;width:100%;&:focus{outline:0;}", ";"], sx);
|
7
|
-
export default UnstyledTextInput;
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare const scrollIntoViewingArea: (child: HTMLElement, container: HTMLElement, direction?: 'horizontal' | 'vertical', startMargin?: number, endMargin?: number, behavior?: ScrollBehavior) => void;
|
@@ -1,30 +0,0 @@
|
|
1
|
-
export const scrollIntoViewingArea = (child, container, direction = 'vertical', startMargin = 8, endMargin = 0, behavior = 'smooth') => {
|
2
|
-
const startSide = direction === 'vertical' ? 'top' : 'left';
|
3
|
-
const endSide = direction === 'vertical' ? 'bottom' : 'right';
|
4
|
-
const scrollSide = direction === 'vertical' ? 'scrollTop' : 'scrollLeft';
|
5
|
-
const {
|
6
|
-
[startSide]: childStart,
|
7
|
-
[endSide]: childEnd
|
8
|
-
} = child.getBoundingClientRect();
|
9
|
-
const {
|
10
|
-
[startSide]: containerStart,
|
11
|
-
[endSide]: containerEnd
|
12
|
-
} = container.getBoundingClientRect();
|
13
|
-
const isChildStartAboveViewingArea = childStart < containerStart + endMargin;
|
14
|
-
const isChildBottomBelowViewingArea = childEnd > containerEnd - startMargin;
|
15
|
-
|
16
|
-
if (isChildStartAboveViewingArea) {
|
17
|
-
const scrollHeightToChildStart = childStart - containerStart + container[scrollSide];
|
18
|
-
container.scrollTo({
|
19
|
-
behavior,
|
20
|
-
[startSide]: scrollHeightToChildStart - endMargin
|
21
|
-
});
|
22
|
-
} else if (isChildBottomBelowViewingArea) {
|
23
|
-
const scrollHeightToChildBottom = childEnd - containerEnd + container[scrollSide];
|
24
|
-
container.scrollTo({
|
25
|
-
behavior,
|
26
|
-
[startSide]: scrollHeightToChildBottom + startMargin
|
27
|
-
});
|
28
|
-
} // either completely in view or outside viewing area on both ends, don't scroll
|
29
|
-
|
30
|
-
};
|