@primer/components 0.0.0-202192719508 → 0.0.0-2021927202224
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 +23 -1
- package/dist/browser.esm.js +54 -53
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +51 -50
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.d.ts +6 -0
- package/lib/ActionList/Item.js +5 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
- package/lib/Autocomplete/Autocomplete.d.ts +2 -4
- package/lib/Autocomplete/AutocompleteInput.d.ts +2 -4
- package/lib/Breadcrumbs.d.ts +8 -7
- package/lib/Breadcrumbs.js +7 -12
- package/lib/SelectMenu/SelectMenu.d.ts +2 -4
- package/lib/TextInputWithTokens.d.ts +6 -4
- package/lib/TextInputWithTokens.js +102 -29
- package/lib/Token/Token.js +13 -2
- package/lib/Token/TokenBase.js +0 -4
- package/lib/Token/_RemoveTokenButton.js +15 -2
- package/lib/_TextInputWrapper.js +1 -1
- package/lib/theme-preval.js +2 -2
- package/lib/utils/testing.d.ts +1 -1
- package/lib-esm/ActionList/Item.d.ts +6 -0
- package/lib-esm/ActionList/Item.js +5 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -4
- package/lib-esm/Autocomplete/Autocomplete.d.ts +2 -4
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +2 -4
- package/lib-esm/Breadcrumbs.d.ts +8 -7
- package/lib-esm/Breadcrumbs.js +8 -13
- package/lib-esm/SelectMenu/SelectMenu.d.ts +2 -4
- package/lib-esm/TextInputWithTokens.d.ts +6 -4
- package/lib-esm/TextInputWithTokens.js +101 -30
- package/lib-esm/Token/Token.js +13 -2
- package/lib-esm/Token/TokenBase.js +0 -4
- package/lib-esm/Token/_RemoveTokenButton.js +11 -2
- package/lib-esm/_TextInputWrapper.js +1 -1
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/utils/testing.d.ts +1 -1
- package/package.json +13 -14
- package/lib/DatePicker/DatePicker.d.ts +0 -48
- package/lib/DatePicker/DatePicker.js +0 -104
- package/lib/DatePicker/DatePickerAnchor.d.ts +0 -5
- package/lib/DatePicker/DatePickerAnchor.js +0 -182
- package/lib/DatePicker/DatePickerOverlay.d.ts +0 -3
- package/lib/DatePicker/DatePickerOverlay.js +0 -48
- package/lib/DatePicker/DatePickerPanel.d.ts +0 -2
- package/lib/DatePicker/DatePickerPanel.js +0 -126
- package/lib/DatePicker/Day.d.ts +0 -14
- package/lib/DatePicker/Day.js +0 -190
- package/lib/DatePicker/Month.d.ts +0 -9
- package/lib/DatePicker/Month.js +0 -120
- package/lib/DatePicker/index.d.ts +0 -2
- package/lib/DatePicker/index.js +0 -13
- package/lib/DatePicker/useDatePicker.d.ts +0 -88
- package/lib/DatePicker/useDatePicker.js +0 -421
- package/lib/hooks/useDebounce.d.ts +0 -2
- package/lib/hooks/useDebounce.js +0 -24
- package/lib-esm/DatePicker/DatePicker.d.ts +0 -48
- package/lib-esm/DatePicker/DatePicker.js +0 -87
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +0 -5
- package/lib-esm/DatePicker/DatePickerAnchor.js +0 -155
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +0 -3
- package/lib-esm/DatePicker/DatePickerOverlay.js +0 -29
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +0 -2
- package/lib-esm/DatePicker/DatePickerPanel.js +0 -100
- package/lib-esm/DatePicker/Day.d.ts +0 -14
- package/lib-esm/DatePicker/Day.js +0 -167
- package/lib-esm/DatePicker/Month.d.ts +0 -9
- package/lib-esm/DatePicker/Month.js +0 -96
- package/lib-esm/DatePicker/index.d.ts +0 -2
- package/lib-esm/DatePicker/index.js +0 -1
- package/lib-esm/DatePicker/useDatePicker.d.ts +0 -88
- package/lib-esm/DatePicker/useDatePicker.js +0 -391
- package/lib-esm/hooks/useDebounce.d.ts +0 -2
- package/lib-esm/hooks/useDebounce.js +0 -16
@@ -154,6 +154,7 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
|
|
154
154
|
selectionVariant,
|
155
155
|
leadingVisual: LeadingVisual,
|
156
156
|
trailingIcon: TrailingIcon,
|
157
|
+
trailingVisual: TrailingVisual,
|
157
158
|
trailingText,
|
158
159
|
variant = 'default',
|
159
160
|
showDivider,
|
@@ -245,7 +246,10 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
|
|
245
246
|
title: description,
|
246
247
|
inline: true,
|
247
248
|
maxWidth: "100%"
|
248
|
-
}, description)) : null),
|
249
|
+
}, description)) : null), TrailingVisual ? /*#__PURE__*/React.createElement(TrailingContent, {
|
250
|
+
variant: variant,
|
251
|
+
disabled: disabled
|
252
|
+
}, typeof TrailingVisual === 'function' ? /*#__PURE__*/React.createElement(TrailingVisual, null) : TrailingVisual) : TrailingIcon || trailingText ? /*#__PURE__*/React.createElement(TrailingContent, {
|
249
253
|
variant: variant,
|
250
254
|
disabled: disabled
|
251
255
|
}, trailingText, TrailingIcon && /*#__PURE__*/React.createElement(TrailingIcon, null)) : null));
|
@@ -26,8 +26,6 @@ interface AnchoredOverlayPropsWithoutAnchor {
|
|
26
26
|
*/
|
27
27
|
anchorRef: React.RefObject<HTMLElement>;
|
28
28
|
}
|
29
|
-
export declare type OverlayOpenGesture = 'anchor-click' | 'anchor-key-press';
|
30
|
-
export declare type OverlayCloseGesture = 'anchor-click' | 'click-outside' | 'escape';
|
31
29
|
export declare type AnchoredOverlayWrapperAnchorProps = Partial<AnchoredOverlayPropsWithAnchor> | AnchoredOverlayPropsWithoutAnchor;
|
32
30
|
interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width'> {
|
33
31
|
/**
|
@@ -37,11 +35,11 @@ interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width'
|
|
37
35
|
/**
|
38
36
|
* A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.
|
39
37
|
*/
|
40
|
-
onOpen?: (gesture:
|
38
|
+
onOpen?: (gesture: 'anchor-click' | 'anchor-key-press') => unknown;
|
41
39
|
/**
|
42
40
|
* A callback which is called whenever the overlay is currently open and a "close gesture" is detected.
|
43
41
|
*/
|
44
|
-
onClose?: (gesture:
|
42
|
+
onClose?: (gesture: 'anchor-click' | 'click-outside' | 'escape') => unknown;
|
45
43
|
/**
|
46
44
|
* Props to be spread on the internal `Overlay` component.
|
47
45
|
*/
|
@@ -12,14 +12,12 @@ export type { AutocompleteOverlayProps } from './AutocompleteOverlay';
|
|
12
12
|
declare const _default: React.FC<{
|
13
13
|
id?: string | undefined;
|
14
14
|
}> & {
|
15
|
-
Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<
|
15
|
+
Input: import("@radix-ui/react-polymorphic").ForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<{
|
16
16
|
[x: string]: any;
|
17
17
|
[x: number]: any;
|
18
18
|
} & {
|
19
19
|
theme?: any;
|
20
|
-
} &
|
21
|
-
children?: React.ReactNode;
|
22
|
-
})) & {
|
20
|
+
} & {
|
23
21
|
as?: string | React.ComponentType<any> | undefined;
|
24
22
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
25
23
|
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
|
@@ -4,14 +4,12 @@ import { ComponentProps } from '../utils/types';
|
|
4
4
|
declare type InternalAutocompleteInputProps = {
|
5
5
|
as?: React.ComponentType<any>;
|
6
6
|
};
|
7
|
-
declare const AutocompleteInput: PolymorphicForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<
|
7
|
+
declare const AutocompleteInput: PolymorphicForwardRefComponent<React.ForwardRefExoticComponent<Pick<Omit<Pick<{
|
8
8
|
[x: string]: any;
|
9
9
|
[x: number]: any;
|
10
10
|
} & {
|
11
11
|
theme?: any;
|
12
|
-
} &
|
13
|
-
children?: React.ReactNode;
|
14
|
-
})) & {
|
12
|
+
} & {
|
15
13
|
as?: string | React.ComponentType<any> | undefined;
|
16
14
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
17
15
|
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
|
package/lib-esm/Breadcrumbs.d.ts
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
import * as History from 'history';
|
2
2
|
import React from 'react';
|
3
|
-
import { SystemCommonProps, SystemFlexProps } from './constants';
|
4
3
|
import { SxProp } from './sx';
|
5
4
|
import { ComponentProps } from './utils/types';
|
6
|
-
declare const BreadcrumbsBase: import("styled-components").StyledComponent<"nav", any,
|
7
|
-
export declare type BreadcrumbsProps =
|
8
|
-
|
5
|
+
declare const BreadcrumbsBase: import("styled-components").StyledComponent<"nav", any, SxProp, never>;
|
6
|
+
export declare type BreadcrumbsProps = React.PropsWithChildren<{
|
7
|
+
className?: string;
|
8
|
+
} & SxProp>;
|
9
|
+
declare function Breadcrumbs({ className, children, sx: sxProp }: React.PropsWithChildren<BreadcrumbsProps>): JSX.Element;
|
9
10
|
declare namespace Breadcrumbs {
|
10
11
|
var displayName: string;
|
11
12
|
}
|
12
13
|
declare const BreadcrumbsItem: import("styled-components").StyledComponent<"a", any, {
|
13
14
|
to?: History.LocationDescriptor<unknown> | undefined;
|
14
15
|
selected?: boolean | undefined;
|
15
|
-
} &
|
16
|
+
} & SxProp, never>;
|
16
17
|
export declare type BreadcrumbsItemProps = ComponentProps<typeof BreadcrumbsItem>;
|
17
18
|
declare const _default: typeof Breadcrumbs & {
|
18
19
|
Item: import("styled-components").StyledComponent<"a", any, {
|
19
20
|
to?: History.LocationDescriptor<unknown> | undefined;
|
20
21
|
selected?: boolean | undefined;
|
21
|
-
} &
|
22
|
+
} & SxProp, never>;
|
22
23
|
};
|
23
24
|
export default _default;
|
24
25
|
/**
|
@@ -28,7 +29,7 @@ export declare const Breadcrumb: typeof Breadcrumbs & {
|
|
28
29
|
Item: import("styled-components").StyledComponent<"a", any, {
|
29
30
|
to?: History.LocationDescriptor<unknown> | undefined;
|
30
31
|
selected?: boolean | undefined;
|
31
|
-
} &
|
32
|
+
} & SxProp, never>;
|
32
33
|
};
|
33
34
|
/**
|
34
35
|
* @deprecated Use the `BreadcrumbsProps` type instead
|
package/lib-esm/Breadcrumbs.js
CHANGED
@@ -1,11 +1,9 @@
|
|
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
1
|
import classnames from 'classnames'; // eslint-disable-next-line import/no-namespace
|
4
2
|
|
5
3
|
import React from 'react';
|
6
4
|
import styled from 'styled-components';
|
7
5
|
import Box from './Box';
|
8
|
-
import {
|
6
|
+
import { get } from './constants';
|
9
7
|
import sx from './sx';
|
10
8
|
const SELECTED_CLASS = 'selected';
|
11
9
|
const Wrapper = styled.li.withConfig({
|
@@ -15,22 +13,19 @@ const Wrapper = styled.li.withConfig({
|
|
15
13
|
const BreadcrumbsBase = styled.nav.withConfig({
|
16
14
|
displayName: "Breadcrumbs__BreadcrumbsBase",
|
17
15
|
componentId: "hwwoo0-1"
|
18
|
-
})(["display:flex;justify-content:space-between;", ";"
|
16
|
+
})(["display:flex;justify-content:space-between;", ";"], sx);
|
19
17
|
|
20
18
|
function Breadcrumbs({
|
21
19
|
className,
|
22
20
|
children,
|
23
|
-
|
24
|
-
...rest
|
21
|
+
sx: sxProp
|
25
22
|
}) {
|
26
|
-
const wrappedChildren = React.Children.map(children, child => /*#__PURE__*/React.createElement(Wrapper,
|
27
|
-
|
28
|
-
}, child));
|
29
|
-
return /*#__PURE__*/React.createElement(BreadcrumbsBase, _extends({
|
23
|
+
const wrappedChildren = React.Children.map(children, child => /*#__PURE__*/React.createElement(Wrapper, null, child));
|
24
|
+
return /*#__PURE__*/React.createElement(BreadcrumbsBase, {
|
30
25
|
className: className,
|
31
26
|
"aria-label": "Breadcrumbs",
|
32
|
-
|
33
|
-
},
|
27
|
+
sx: sxProp
|
28
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
34
29
|
as: "ol",
|
35
30
|
my: 0,
|
36
31
|
pl: 0
|
@@ -45,7 +40,7 @@ const BreadcrumbsItem = styled.a.attrs(props => ({
|
|
45
40
|
})).withConfig({
|
46
41
|
displayName: "Breadcrumbs__BreadcrumbsItem",
|
47
42
|
componentId: "hwwoo0-2"
|
48
|
-
})(["color:", ";display:inline-block;font-size:", ";text-decoration:none;&:hover{text-decoration:underline;}&.selected{color:", ";pointer-events:none;}", "
|
43
|
+
})(["color:", ";display:inline-block;font-size:", ";text-decoration:none;&:hover{text-decoration:underline;}&.selected{color:", ";pointer-events:none;}", ";"], get('colors.accent.fg'), get('fontSizes.1'), get('colors.fg.default'), sx);
|
49
44
|
Breadcrumbs.displayName = 'Breadcrumbs';
|
50
45
|
BreadcrumbsItem.displayName = 'Breadcrumbs.Item';
|
51
46
|
export default Object.assign(Breadcrumbs, {
|
@@ -32,14 +32,12 @@ 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
|
-
} & Pick<Omit<Pick<
|
35
|
+
} & Pick<Omit<Pick<{
|
36
36
|
[x: string]: any;
|
37
37
|
[x: number]: any;
|
38
38
|
} & {
|
39
39
|
theme?: any;
|
40
|
-
} &
|
41
|
-
children?: React.ReactNode;
|
42
|
-
})) & {
|
40
|
+
} & {
|
43
41
|
as?: string | React.ComponentType<any> | undefined;
|
44
42
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
45
43
|
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
|
@@ -32,14 +32,16 @@ declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<{
|
|
32
32
|
* Whether the remove buttons should be rendered in the tokens
|
33
33
|
*/
|
34
34
|
hideTokenRemoveButtons?: boolean | undefined;
|
35
|
-
|
35
|
+
/**
|
36
|
+
* The number of tokens to display before truncating
|
37
|
+
*/
|
38
|
+
visibleTokenCount?: number | undefined;
|
39
|
+
} & Pick<Omit<Pick<{
|
36
40
|
[x: string]: any;
|
37
41
|
[x: number]: any;
|
38
42
|
} & {
|
39
43
|
theme?: any;
|
40
|
-
} &
|
41
|
-
children?: React.ReactNode;
|
42
|
-
})) & {
|
44
|
+
} & {
|
43
45
|
as?: string | React.ComponentType<any> | undefined;
|
44
46
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
45
47
|
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"> & {
|
@@ -9,9 +9,17 @@ import Token from './Token/Token';
|
|
9
9
|
import { useProvidedRefOrCreate } from './hooks';
|
10
10
|
import UnstyledTextInput from './_UnstyledTextInput';
|
11
11
|
import TextInputWrapper from './_TextInputWrapper';
|
12
|
-
import Box from './Box';
|
12
|
+
import Box from './Box';
|
13
|
+
import Text from './Text';
|
14
|
+
import { isFocusable } from './utils/iterateFocusableElements'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
15
|
+
|
16
|
+
const overflowCountFontSizeMap = {
|
17
|
+
small: 0,
|
18
|
+
medium: 1,
|
19
|
+
large: 1,
|
20
|
+
extralarge: 2
|
21
|
+
}; // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
13
22
|
|
14
|
-
// using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
15
23
|
function TextInputWithTokensInnerComponent({
|
16
24
|
icon: IconComponent,
|
17
25
|
contrast,
|
@@ -31,9 +39,11 @@ function TextInputWithTokensInnerComponent({
|
|
31
39
|
minWidth: minWidthProp,
|
32
40
|
maxWidth: maxWidthProp,
|
33
41
|
variant: variantProp,
|
42
|
+
visibleTokenCount,
|
34
43
|
...rest
|
35
44
|
}, externalRef) {
|
36
45
|
const {
|
46
|
+
onBlur,
|
37
47
|
onFocus,
|
38
48
|
onKeyDown,
|
39
49
|
...inputPropsRest
|
@@ -42,6 +52,7 @@ function TextInputWithTokensInnerComponent({
|
|
42
52
|
const localInputRef = useRef(null);
|
43
53
|
const combinedInputRef = useCombinedRefs(localInputRef, ref);
|
44
54
|
const [selectedTokenIndex, setSelectedTokenIndex] = useState();
|
55
|
+
const [tokensAreTruncated, setTokensAreTruncated] = useState(Boolean(visibleTokenCount));
|
45
56
|
const {
|
46
57
|
containerRef
|
47
58
|
} = useFocusZone({
|
@@ -76,14 +87,25 @@ function TextInputWithTokensInnerComponent({
|
|
76
87
|
}, [selectedTokenIndex]);
|
77
88
|
|
78
89
|
const handleTokenRemove = tokenId => {
|
79
|
-
onTokenRemove(tokenId);
|
90
|
+
onTokenRemove(tokenId); // HACK: wait a tick for the the token node to be removed from the DOM
|
80
91
|
|
81
|
-
|
82
|
-
var _containerRef$current2;
|
92
|
+
setTimeout(() => {
|
93
|
+
var _containerRef$current2, _containerRef$current3;
|
83
94
|
|
84
|
-
const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
|
85
|
-
|
86
|
-
|
95
|
+
const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex || 0]; // when removing the first token by keying "Backspace" or "Delete",
|
96
|
+
// `nextFocusableElement` is the div that wraps the input
|
97
|
+
|
98
|
+
const firstFocusable = nextElementToFocus && isFocusable(nextElementToFocus) ? nextElementToFocus : Array.from(((_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.children) || []).find(el => isFocusable(el));
|
99
|
+
|
100
|
+
if (firstFocusable) {
|
101
|
+
firstFocusable.focus();
|
102
|
+
} else {
|
103
|
+
var _ref$current;
|
104
|
+
|
105
|
+
// if there are no tokens left, focus the input
|
106
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
107
|
+
}
|
108
|
+
}, 0);
|
87
109
|
};
|
88
110
|
|
89
111
|
const handleTokenFocus = tokenIndex => () => {
|
@@ -91,30 +113,55 @@ function TextInputWithTokensInnerComponent({
|
|
91
113
|
};
|
92
114
|
|
93
115
|
const handleTokenBlur = () => {
|
94
|
-
setSelectedTokenIndex(undefined);
|
116
|
+
setSelectedTokenIndex(undefined); // HACK: wait a tick and check the focused element before hiding truncated tokens
|
117
|
+
// this prevents the tokens from hiding when the user is moving focus between tokens,
|
118
|
+
// but still hides the tokens when the user blurs the token by tabbing out or clicking somewhere else on the page
|
119
|
+
|
120
|
+
setTimeout(() => {
|
121
|
+
var _containerRef$current4;
|
122
|
+
|
123
|
+
if (!((_containerRef$current4 = containerRef.current) !== null && _containerRef$current4 !== void 0 && _containerRef$current4.contains(document.activeElement)) && visibleTokenCount) {
|
124
|
+
setTokensAreTruncated(true);
|
125
|
+
}
|
126
|
+
}, 0);
|
95
127
|
};
|
96
128
|
|
97
|
-
const handleTokenKeyUp =
|
98
|
-
if (
|
99
|
-
var _ref$
|
129
|
+
const handleTokenKeyUp = event => {
|
130
|
+
if (event.key === 'Escape') {
|
131
|
+
var _ref$current2;
|
100
132
|
|
101
|
-
(_ref$
|
133
|
+
(_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focus();
|
102
134
|
}
|
103
135
|
};
|
104
136
|
|
105
|
-
const handleInputFocus =
|
106
|
-
onFocus && onFocus(
|
137
|
+
const handleInputFocus = event => {
|
138
|
+
onFocus && onFocus(event);
|
107
139
|
setSelectedTokenIndex(undefined);
|
140
|
+
visibleTokenCount && setTokensAreTruncated(false);
|
141
|
+
};
|
142
|
+
|
143
|
+
const handleInputBlur = event => {
|
144
|
+
onBlur && onBlur(event); // HACK: wait a tick and check the focused element before hiding truncated tokens
|
145
|
+
// this prevents the tokens from hiding when the user is moving focus from the input to a token,
|
146
|
+
// but still hides the tokens when the user blurs the input by tabbing out or clicking somewhere else on the page
|
147
|
+
|
148
|
+
setTimeout(() => {
|
149
|
+
var _containerRef$current5;
|
150
|
+
|
151
|
+
if (!((_containerRef$current5 = containerRef.current) !== null && _containerRef$current5 !== void 0 && _containerRef$current5.contains(document.activeElement)) && visibleTokenCount) {
|
152
|
+
setTokensAreTruncated(true);
|
153
|
+
}
|
154
|
+
}, 0);
|
108
155
|
};
|
109
156
|
|
110
157
|
const handleInputKeyDown = e => {
|
111
|
-
var _ref$
|
158
|
+
var _ref$current3;
|
112
159
|
|
113
160
|
if (onKeyDown) {
|
114
161
|
onKeyDown(e);
|
115
162
|
}
|
116
163
|
|
117
|
-
if ((_ref$
|
164
|
+
if ((_ref$current3 = ref.current) !== null && _ref$current3 !== void 0 && _ref$current3.value) {
|
118
165
|
return;
|
119
166
|
}
|
120
167
|
|
@@ -135,13 +182,24 @@ function TextInputWithTokensInnerComponent({
|
|
135
182
|
|
136
183
|
|
137
184
|
setTimeout(() => {
|
138
|
-
var _ref$
|
185
|
+
var _ref$current4;
|
139
186
|
|
140
|
-
(_ref$
|
187
|
+
(_ref$current4 = ref.current) === null || _ref$current4 === void 0 ? void 0 : _ref$current4.select();
|
141
188
|
}, 0);
|
142
189
|
}
|
143
190
|
};
|
144
191
|
|
192
|
+
const focusInput = () => {
|
193
|
+
var _combinedInputRef$cur;
|
194
|
+
|
195
|
+
(_combinedInputRef$cur = combinedInputRef.current) === null || _combinedInputRef$cur === void 0 ? void 0 : _combinedInputRef$cur.focus();
|
196
|
+
};
|
197
|
+
|
198
|
+
const preventTokenClickPropagation = event => {
|
199
|
+
event.stopPropagation();
|
200
|
+
};
|
201
|
+
|
202
|
+
const visibleTokens = tokensAreTruncated ? tokens.slice(0, visibleTokenCount) : tokens;
|
145
203
|
return /*#__PURE__*/React.createElement(TextInputWrapper, {
|
146
204
|
block: block,
|
147
205
|
className: className,
|
@@ -153,15 +211,8 @@ function TextInputWithTokensInnerComponent({
|
|
153
211
|
minWidth: minWidthProp,
|
154
212
|
maxWidth: maxWidthProp,
|
155
213
|
variant: variantProp,
|
156
|
-
|
157
|
-
sx: {
|
158
|
-
alignItems: 'center',
|
159
|
-
flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
|
160
|
-
gap: '0.25rem',
|
161
|
-
'> *': {
|
162
|
-
flexShrink: 0
|
163
|
-
},
|
164
|
-
...(block ? {
|
214
|
+
onClick: focusInput,
|
215
|
+
sx: { ...(block ? {
|
165
216
|
display: 'flex',
|
166
217
|
width: '100%'
|
167
218
|
} : {}),
|
@@ -174,6 +225,21 @@ function TextInputWithTokensInnerComponent({
|
|
174
225
|
} : {}),
|
175
226
|
...sxProp
|
176
227
|
}
|
228
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
229
|
+
ref: containerRef,
|
230
|
+
display: "flex",
|
231
|
+
sx: {
|
232
|
+
alignItems: 'center',
|
233
|
+
flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
|
234
|
+
marginLeft: '-0.25rem',
|
235
|
+
marginBottom: '-0.25rem',
|
236
|
+
flexGrow: 1,
|
237
|
+
'> *': {
|
238
|
+
flexShrink: 0,
|
239
|
+
marginLeft: '0.25rem',
|
240
|
+
marginBottom: '0.25rem'
|
241
|
+
}
|
242
|
+
}
|
177
243
|
}, /*#__PURE__*/React.createElement(Box, {
|
178
244
|
sx: {
|
179
245
|
order: 1,
|
@@ -185,12 +251,13 @@ function TextInputWithTokensInnerComponent({
|
|
185
251
|
ref: combinedInputRef,
|
186
252
|
disabled: disabled,
|
187
253
|
onFocus: handleInputFocus,
|
254
|
+
onBlur: handleInputBlur,
|
188
255
|
onKeyDown: handleInputKeyDown,
|
189
256
|
type: "text",
|
190
257
|
sx: {
|
191
258
|
height: '100%'
|
192
259
|
}
|
193
|
-
}, inputPropsRest))),
|
260
|
+
}, inputPropsRest))), TokenComponent ? visibleTokens.map(({
|
194
261
|
id,
|
195
262
|
...tokenRest
|
196
263
|
}, i) => /*#__PURE__*/React.createElement(TokenComponent, _extends({
|
@@ -198,6 +265,7 @@ function TextInputWithTokensInnerComponent({
|
|
198
265
|
onFocus: handleTokenFocus(i),
|
199
266
|
onBlur: handleTokenBlur,
|
200
267
|
onKeyUp: handleTokenKeyUp,
|
268
|
+
onClick: preventTokenClickPropagation,
|
201
269
|
isSelected: selectedTokenIndex === i,
|
202
270
|
onRemove: () => {
|
203
271
|
handleTokenRemove(id);
|
@@ -205,7 +273,10 @@ function TextInputWithTokensInnerComponent({
|
|
205
273
|
hideRemoveButton: hideTokenRemoveButtons,
|
206
274
|
size: size,
|
207
275
|
tabIndex: 0
|
208
|
-
}, tokenRest))) : null
|
276
|
+
}, tokenRest))) : null, tokensAreTruncated ? /*#__PURE__*/React.createElement(Text, {
|
277
|
+
color: "fg.muted",
|
278
|
+
fontSize: size && overflowCountFontSizeMap[size]
|
279
|
+
}, "+", tokens.length - visibleTokens.length) : null));
|
209
280
|
}
|
210
281
|
|
211
282
|
TextInputWithTokensInnerComponent.displayName = "TextInputWithTokensInnerComponent";
|
package/lib-esm/Token/Token.js
CHANGED
@@ -19,7 +19,16 @@ const DefaultTokenStyled = styled(TokenBase).withConfig({
|
|
19
19
|
const LeadingVisualContainer = styled('span').withConfig({
|
20
20
|
displayName: "Token__LeadingVisualContainer",
|
21
21
|
componentId: "sc-1dg52pw-1"
|
22
|
-
})(["flex-shrink:0;line-height:0;"]
|
22
|
+
})(["flex-shrink:0;line-height:0;", ""], props => {
|
23
|
+
switch (props.size) {
|
24
|
+
case 'large':
|
25
|
+
case 'extralarge':
|
26
|
+
return css(["margin-right:", ";"], get('space.2'));
|
27
|
+
|
28
|
+
default:
|
29
|
+
return css(["margin-right:", ";"], get('space.1'));
|
30
|
+
}
|
31
|
+
});
|
23
32
|
const Token = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
24
33
|
const {
|
25
34
|
as,
|
@@ -54,7 +63,9 @@ const Token = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
54
63
|
isTokenInteractive: isTokenInteractive(props)
|
55
64
|
}, !hasMultipleActionTargets ? interactiveTokenProps : {}, rest, {
|
56
65
|
ref: forwardedRef
|
57
|
-
}), LeadingVisual ? /*#__PURE__*/React.createElement(LeadingVisualContainer,
|
66
|
+
}), LeadingVisual ? /*#__PURE__*/React.createElement(LeadingVisualContainer, {
|
67
|
+
size: size
|
68
|
+
}, /*#__PURE__*/React.createElement(LeadingVisual, null)) : null, /*#__PURE__*/React.createElement(TokenTextContainer, hasMultipleActionTargets ? interactiveTokenProps : {}, text), !hideRemoveButton && onRemove ? /*#__PURE__*/React.createElement(RemoveTokenButton, {
|
58
69
|
borderOffset: tokenBorderWidthPx,
|
59
70
|
onClick: onRemoveClick,
|
60
71
|
size: size,
|
@@ -20,7 +20,6 @@ const variants = variant({
|
|
20
20
|
variants: {
|
21
21
|
small: {
|
22
22
|
fontSize: 0,
|
23
|
-
gap: 1,
|
24
23
|
height: tokenSizes.small,
|
25
24
|
// without setting lineHeight to match height, the "x" appears vertically mis-aligned
|
26
25
|
lineHeight: tokenSizes.small,
|
@@ -33,7 +32,6 @@ const variants = variant({
|
|
33
32
|
},
|
34
33
|
medium: {
|
35
34
|
fontSize: 0,
|
36
|
-
gap: 1,
|
37
35
|
height: tokenSizes.medium,
|
38
36
|
lineHeight: tokenSizes.medium,
|
39
37
|
paddingLeft: 2,
|
@@ -43,7 +41,6 @@ const variants = variant({
|
|
43
41
|
},
|
44
42
|
large: {
|
45
43
|
fontSize: 0,
|
46
|
-
gap: 2,
|
47
44
|
height: tokenSizes.large,
|
48
45
|
lineHeight: tokenSizes.large,
|
49
46
|
paddingLeft: 2,
|
@@ -53,7 +50,6 @@ const variants = variant({
|
|
53
50
|
},
|
54
51
|
extralarge: {
|
55
52
|
fontSize: 1,
|
56
|
-
gap: 2,
|
57
53
|
height: tokenSizes.extralarge,
|
58
54
|
lineHeight: tokenSizes.extralarge,
|
59
55
|
paddingLeft: 3,
|
@@ -2,7 +2,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
2
2
|
|
3
3
|
import React from 'react';
|
4
4
|
import { XIcon } from '@primer/octicons-react';
|
5
|
-
import styled from 'styled-components';
|
5
|
+
import styled, { css } from 'styled-components';
|
6
6
|
import { variant } from 'styled-system';
|
7
7
|
import { get } from '../constants';
|
8
8
|
import sx from '../sx';
|
@@ -34,7 +34,16 @@ const getTokenButtonIconSize = size => parseInt(tokenSizes[size || defaultTokenS
|
|
34
34
|
const StyledTokenButton = styled.span.withConfig({
|
35
35
|
displayName: "_RemoveTokenButton__StyledTokenButton",
|
36
36
|
componentId: "sc-14lvcw1-0"
|
37
|
-
})(["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;transform:", ";align-self:baseline;border:0;border-radius:999px
|
37
|
+
})(["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;transform:", ";align-self:baseline;border:0;border-radius:999px;", " &:hover,&:focus{background-color:", ";}&:active{background-color:", ";}", " ", ""], props => `translate(${props.borderOffset}px, -${props.borderOffset}px)`, props => {
|
38
|
+
switch (props.size) {
|
39
|
+
case 'large':
|
40
|
+
case 'extralarge':
|
41
|
+
return css(["margin-left:", ";"], get('space.2'));
|
42
|
+
|
43
|
+
default:
|
44
|
+
return css(["margin-left:", ";"], get('space.1'));
|
45
|
+
}
|
46
|
+
}, get('colors.neutral.muted'), get('colors.neutral.subtle'), variants, sx);
|
38
47
|
|
39
48
|
const RemoveTokenButton = ({
|
40
49
|
'aria-label': ariaLabel,
|
@@ -21,7 +21,7 @@ const sizeVariants = variant({
|
|
21
21
|
const TextInputWrapper = styled.span.withConfig({
|
22
22
|
displayName: "_TextInputWrapper__TextInputWrapper",
|
23
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 => {
|
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:", ";cursor:text;", " .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
25
|
if (props.hasIcon) {
|
26
26
|
return css(["padding:0;"]);
|
27
27
|
} else {
|
package/lib-esm/theme-preval.js
CHANGED
@@ -515,7 +515,7 @@ module.exports = {
|
|
515
515
|
}
|
516
516
|
}
|
517
517
|
},
|
518
|
-
"
|
518
|
+
"light_protanopia": {
|
519
519
|
"colors": {
|
520
520
|
"canvasDefaultTransparent": "rgba(255,255,255,0)",
|
521
521
|
"marketingIcon": {
|
@@ -2456,7 +2456,7 @@ module.exports = {
|
|
2456
2456
|
}
|
2457
2457
|
}
|
2458
2458
|
},
|
2459
|
-
"
|
2459
|
+
"dark_protanopia": {
|
2460
2460
|
"colors": {
|
2461
2461
|
"canvasDefaultTransparent": "rgba(13,17,23,0)",
|
2462
2462
|
"marketingIcon": {
|
@@ -53,7 +53,7 @@ export declare function render(component: React.ReactElement, theme?: {
|
|
53
53
|
xlarge: string;
|
54
54
|
};
|
55
55
|
space: string[];
|
56
|
-
colorSchemes: Record<"light" | "
|
56
|
+
colorSchemes: Record<"light" | "light_protanopia" | "dark" | "dark_dimmed" | "dark_high_contrast" | "dark_protanopia", Record<"colors" | "shadows", Partial<{
|
57
57
|
canvasDefaultTransparent: string;
|
58
58
|
marketingIcon: {
|
59
59
|
primary: string;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@primer/components",
|
3
|
-
"version": "0.0.0-
|
3
|
+
"version": "0.0.0-2021927202224",
|
4
4
|
"description": "Primer react components",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"module": "lib-esm/index.js",
|
@@ -43,16 +43,20 @@
|
|
43
43
|
"author": "GitHub, Inc.",
|
44
44
|
"license": "MIT",
|
45
45
|
"dependencies": {
|
46
|
-
"@primer/octicons-react": "^
|
47
|
-
"@primer/primitives": "
|
46
|
+
"@primer/octicons-react": "^13.0.0",
|
47
|
+
"@primer/primitives": "5.1.0",
|
48
48
|
"@radix-ui/react-polymorphic": "0.0.14",
|
49
49
|
"@react-aria/ssr": "3.1.0",
|
50
50
|
"@styled-system/css": "5.1.5",
|
51
51
|
"@styled-system/props": "5.1.5",
|
52
52
|
"@styled-system/theme-get": "5.1.2",
|
53
|
+
"@types/history": "4.7.8",
|
54
|
+
"@types/styled-components": "5.1.11",
|
55
|
+
"@types/styled-system": "5.1.12",
|
56
|
+
"@types/styled-system__css": "5.0.16",
|
57
|
+
"@types/styled-system__theme-get": "5.0.1",
|
53
58
|
"classnames": "2.3.1",
|
54
59
|
"color2k": "1.2.4",
|
55
|
-
"date-fns": "2.25.0",
|
56
60
|
"deepmerge": "4.2.2",
|
57
61
|
"focus-visible": "5.2.0",
|
58
62
|
"styled-system": "5.1.5"
|
@@ -72,20 +76,15 @@
|
|
72
76
|
"@rollup/plugin-commonjs": "19.0.2",
|
73
77
|
"@rollup/plugin-node-resolve": "13.0.5",
|
74
78
|
"@size-limit/preset-big-lib": "5.0.2",
|
75
|
-
"@storybook/addon-a11y": "6.3.
|
76
|
-
"@storybook/addon-actions": "^6.
|
77
|
-
"@storybook/addon-essentials": "6.
|
78
|
-
"@storybook/addon-links": "^6.
|
79
|
-
"@storybook/react": "6.3.
|
79
|
+
"@storybook/addon-a11y": "6.3.12",
|
80
|
+
"@storybook/addon-actions": "^6.3.12",
|
81
|
+
"@storybook/addon-essentials": "6.3.12",
|
82
|
+
"@storybook/addon-links": "^6.3.12",
|
83
|
+
"@storybook/react": "6.3.12",
|
80
84
|
"@testing-library/dom": "7.31.2",
|
81
85
|
"@testing-library/react": "11.2.7",
|
82
86
|
"@testing-library/react-hooks": "7.0.2",
|
83
87
|
"@testing-library/user-event": "13.1.9",
|
84
|
-
"@types/history": "4.7.9",
|
85
|
-
"@types/styled-components": "5.1.15",
|
86
|
-
"@types/styled-system": "5.1.13",
|
87
|
-
"@types/styled-system__css": "5.0.16",
|
88
|
-
"@types/styled-system__theme-get": "5.0.1",
|
89
88
|
"@types/chroma-js": "2.1.3",
|
90
89
|
"@types/enzyme": "3.10.9",
|
91
90
|
"@types/jest": "26.0.23",
|