@primer/components 0.0.0-2021927203020 → 0.0.0-2021927203131
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 +19 -1
- package/dist/browser.esm.js +54 -50
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +277 -273
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.d.ts +6 -0
- package/lib/ActionList/Item.js +11 -26
- 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/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 +12 -28
- 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/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 -433
- 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 -403
- package/lib-esm/hooks/useDebounce.d.ts +0 -2
- package/lib-esm/hooks/useDebounce.js +0 -16
@@ -8,37 +8,17 @@ import Truncate from '../Truncate';
|
|
8
8
|
import styled from 'styled-components';
|
9
9
|
import { StyledHeader } from './Header';
|
10
10
|
import { StyledDivider } from './Divider';
|
11
|
-
import {
|
11
|
+
import { useTheme } from '../ThemeProvider';
|
12
12
|
import { activeDescendantActivatedDirectly, activeDescendantActivatedIndirectly, isActiveDescendantAttribute } from '../behaviors/focusZone';
|
13
13
|
import { useSSRSafeId } from '@react-aria/ssr';
|
14
|
-
|
15
|
-
/**
|
16
|
-
* These colors are not yet in our default theme. Need to remove this once they are added.
|
17
|
-
*/
|
18
14
|
const customItemThemes = {
|
19
15
|
default: {
|
20
|
-
hover:
|
21
|
-
|
22
|
-
dark: 'rgba(201, 206, 212, 0.12)',
|
23
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.12)'
|
24
|
-
},
|
25
|
-
focus: {
|
26
|
-
light: 'rgba(54, 77, 100, 0.16)',
|
27
|
-
dark: 'rgba(201, 206, 212, 0.24)',
|
28
|
-
dark_dimmed: 'rgba(201, 206, 212, 0.24)'
|
29
|
-
}
|
16
|
+
hover: get('colors.neutral.subtle'),
|
17
|
+
focus: get('colors.neutral.muted')
|
30
18
|
},
|
31
19
|
danger: {
|
32
|
-
hover:
|
33
|
-
|
34
|
-
dark: 'rgba(248, 81, 73, 0.16)',
|
35
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.16)'
|
36
|
-
},
|
37
|
-
focus: {
|
38
|
-
light: 'rgba(234, 74, 90, 0.14)',
|
39
|
-
dark: 'rgba(248, 81, 73, 0.24)',
|
40
|
-
dark_dimmed: 'rgba(248, 81, 73, 0.24)'
|
41
|
-
}
|
20
|
+
hover: get('colors.danger.subtle'),
|
21
|
+
focus: get('colors.danger.muted')
|
42
22
|
}
|
43
23
|
};
|
44
24
|
/**
|
@@ -154,6 +134,7 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
|
|
154
134
|
selectionVariant,
|
155
135
|
leadingVisual: LeadingVisual,
|
156
136
|
trailingIcon: TrailingIcon,
|
137
|
+
trailingVisual: TrailingVisual,
|
157
138
|
trailingText,
|
158
139
|
variant = 'default',
|
159
140
|
showDivider,
|
@@ -196,8 +177,8 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
|
|
196
177
|
}
|
197
178
|
}, [onAction, disabled, itemProps, onClick]);
|
198
179
|
const customItemTheme = customItemThemes[variant];
|
199
|
-
const hoverBackground =
|
200
|
-
const focusBackground =
|
180
|
+
const hoverBackground = customItemTheme.hover;
|
181
|
+
const focusBackground = customItemTheme.focus;
|
201
182
|
const {
|
202
183
|
theme
|
203
184
|
} = useTheme();
|
@@ -245,7 +226,10 @@ export const Item = /*#__PURE__*/React.forwardRef((itemProps, ref) => {
|
|
245
226
|
title: description,
|
246
227
|
inline: true,
|
247
228
|
maxWidth: "100%"
|
248
|
-
}, description)) : null),
|
229
|
+
}, description)) : null), TrailingVisual ? /*#__PURE__*/React.createElement(TrailingContent, {
|
230
|
+
variant: variant,
|
231
|
+
disabled: disabled
|
232
|
+
}, typeof TrailingVisual === 'function' ? /*#__PURE__*/React.createElement(TrailingVisual, null) : TrailingVisual) : TrailingIcon || trailingText ? /*#__PURE__*/React.createElement(TrailingContent, {
|
249
233
|
variant: variant,
|
250
234
|
disabled: disabled
|
251
235
|
}, 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"> & {
|
@@ -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-2021927203131",
|
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",
|
@@ -1,48 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { OverlayProps } from '../Overlay';
|
3
|
-
import { FocusTrapHookSettings } from '../hooks/useFocusTrap';
|
4
|
-
import { FocusZoneHookSettings } from '../hooks/useFocusZone';
|
5
|
-
import { DatePickerConfiguration, Selection } from './useDatePicker';
|
6
|
-
declare type OpenGesture = 'anchor-click' | 'anchor-key-press';
|
7
|
-
declare type CloseGesture = 'anchor-click' | 'click-outside' | 'escape';
|
8
|
-
export interface DatePickerProps extends DatePickerConfiguration {
|
9
|
-
/**
|
10
|
-
* An override to the internal ref that will be spread on to the renderAnchor
|
11
|
-
*/
|
12
|
-
anchorRef?: React.RefObject<HTMLElement>;
|
13
|
-
/**
|
14
|
-
* Settings to apply to the Focus Zone on the internal `Overlay` component.
|
15
|
-
*/
|
16
|
-
focusTrapSettings?: Partial<FocusTrapHookSettings>;
|
17
|
-
/**
|
18
|
-
* Settings to apply to the Focus Zone on the internal `Overlay` component.
|
19
|
-
*/
|
20
|
-
focusZoneSettings?: Partial<FocusZoneHookSettings>;
|
21
|
-
initialValue?: 'today' | Date | string | null;
|
22
|
-
iconOnly?: boolean;
|
23
|
-
placeholder?: string;
|
24
|
-
/**
|
25
|
-
* Determines whether the overlay portion of the component should be shown or not
|
26
|
-
*/
|
27
|
-
open?: boolean;
|
28
|
-
/**
|
29
|
-
* A callback which is called whenever the overlay is currently closed and an "open gesture" is detected.
|
30
|
-
*/
|
31
|
-
onOpen?: (gesture: OpenGesture) => unknown;
|
32
|
-
/**
|
33
|
-
* A callback which is called whenever the overlay is currently open and a "close gesture" is detected.
|
34
|
-
*/
|
35
|
-
onClose?: (gesture: CloseGesture) => unknown;
|
36
|
-
/**
|
37
|
-
* Props to be spread on the internal `Overlay` component.
|
38
|
-
*/
|
39
|
-
overlayProps?: Partial<OverlayProps>;
|
40
|
-
/**
|
41
|
-
* A custom function component used to render the anchor element.
|
42
|
-
* Will receive the selected text as `children` prop when an item is activated.
|
43
|
-
*/
|
44
|
-
renderAnchor: <T extends React.HTMLAttributes<HTMLElement>>(props: T) => JSX.Element;
|
45
|
-
value?: Selection;
|
46
|
-
}
|
47
|
-
export declare const DatePicker: React.FC<DatePickerProps>;
|
48
|
-
export {};
|