@primer/components 0.0.0-2021919202426 → 0.0.0-2021921114926

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.
@@ -32,10 +32,6 @@ 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
- /**
36
- * The number of tokens to display before truncating
37
- */
38
- visibleTokenCount?: number | undefined;
39
35
  } & Pick<Omit<Pick<{
40
36
  [x: string]: any;
41
37
  [x: number]: any;
@@ -25,8 +25,6 @@ var _TextInputWrapper = _interopRequireDefault(require("./_TextInputWrapper"));
25
25
 
26
26
  var _Box = _interopRequireDefault(require("./Box"));
27
27
 
28
- var _Text = _interopRequireDefault(require("./Text"));
29
-
30
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
29
 
32
30
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -35,13 +33,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
35
33
 
36
34
  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); }
37
35
 
38
- const overflowCountFontSizeMap = {
39
- small: 0,
40
- medium: 1,
41
- large: 1,
42
- extralarge: 2
43
- }; // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
44
-
36
+ // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
45
37
  function TextInputWithTokensInnerComponent({
46
38
  icon: IconComponent,
47
39
  contrast,
@@ -61,11 +53,9 @@ function TextInputWithTokensInnerComponent({
61
53
  minWidth: minWidthProp,
62
54
  maxWidth: maxWidthProp,
63
55
  variant: variantProp,
64
- visibleTokenCount,
65
56
  ...rest
66
57
  }, externalRef) {
67
58
  const {
68
- onBlur,
69
59
  onFocus,
70
60
  onKeyDown,
71
61
  ...inputPropsRest
@@ -74,7 +64,6 @@ function TextInputWithTokensInnerComponent({
74
64
  const localInputRef = (0, _react.useRef)(null);
75
65
  const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(localInputRef, ref);
76
66
  const [selectedTokenIndex, setSelectedTokenIndex] = (0, _react.useState)();
77
- const [tokensAreTruncated, setTokensAreTruncated] = (0, _react.useState)(Boolean(visibleTokenCount));
78
67
  const {
79
68
  containerRef
80
69
  } = (0, _useFocusZone.useFocusZone)({
@@ -124,45 +113,20 @@ function TextInputWithTokensInnerComponent({
124
113
  };
125
114
 
126
115
  const handleTokenBlur = () => {
127
- setSelectedTokenIndex(undefined); // HACK: wait a tick and check the focused element before hiding truncated tokens
128
- // this prevents the tokens from hiding when the user is moving focus between tokens,
129
- // but still hides the tokens when the user blurs the token by tabbing out or clicking somewhere else on the page
130
-
131
- setTimeout(() => {
132
- var _containerRef$current3;
133
-
134
- if (!((_containerRef$current3 = containerRef.current) !== null && _containerRef$current3 !== void 0 && _containerRef$current3.contains(document.activeElement)) && visibleTokenCount) {
135
- setTokensAreTruncated(true);
136
- }
137
- }, 0);
116
+ setSelectedTokenIndex(undefined);
138
117
  };
139
118
 
140
- const handleTokenKeyUp = event => {
141
- if (event.key === 'Escape') {
119
+ const handleTokenKeyUp = e => {
120
+ if (e.key === 'Escape') {
142
121
  var _ref$current;
143
122
 
144
123
  (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
145
124
  }
146
125
  };
147
126
 
148
- const handleInputFocus = event => {
149
- onFocus && onFocus(event);
127
+ const handleInputFocus = e => {
128
+ onFocus && onFocus(e);
150
129
  setSelectedTokenIndex(undefined);
151
- visibleTokenCount && setTokensAreTruncated(false);
152
- };
153
-
154
- const handleInputBlur = event => {
155
- onBlur && onBlur(event); // HACK: wait a tick and check the focused element before hiding truncated tokens
156
- // this prevents the tokens from hiding when the user is moving focus from the input to a token,
157
- // but still hides the tokens when the user blurs the input by tabbing out or clicking somewhere else on the page
158
-
159
- setTimeout(() => {
160
- var _containerRef$current4;
161
-
162
- if (!((_containerRef$current4 = containerRef.current) !== null && _containerRef$current4 !== void 0 && _containerRef$current4.contains(document.activeElement)) && visibleTokenCount) {
163
- setTokensAreTruncated(true);
164
- }
165
- }, 0);
166
130
  };
167
131
 
168
132
  const handleInputKeyDown = e => {
@@ -200,17 +164,6 @@ function TextInputWithTokensInnerComponent({
200
164
  }
201
165
  };
202
166
 
203
- const focusInput = () => {
204
- var _combinedInputRef$cur;
205
-
206
- (_combinedInputRef$cur = combinedInputRef.current) === null || _combinedInputRef$cur === void 0 ? void 0 : _combinedInputRef$cur.focus();
207
- };
208
-
209
- const preventTokenClickPropagation = event => {
210
- event.stopPropagation();
211
- };
212
-
213
- const visibleTokens = tokensAreTruncated ? tokens.slice(0, visibleTokenCount) : tokens;
214
167
  return /*#__PURE__*/_react.default.createElement(_TextInputWrapper.default, {
215
168
  block: block,
216
169
  className: className,
@@ -222,16 +175,7 @@ function TextInputWithTokensInnerComponent({
222
175
  minWidth: minWidthProp,
223
176
  maxWidth: maxWidthProp,
224
177
  variant: variantProp,
225
- ref: containerRef,
226
- onClick: focusInput,
227
- sx: {
228
- alignItems: 'center',
229
- flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
230
- gap: '0.25rem',
231
- '> *': {
232
- flexShrink: 0
233
- },
234
- ...(block ? {
178
+ sx: { ...(block ? {
235
179
  display: 'flex',
236
180
  width: '100%'
237
181
  } : {}),
@@ -244,6 +188,21 @@ function TextInputWithTokensInnerComponent({
244
188
  } : {}),
245
189
  ...sxProp
246
190
  }
191
+ }, /*#__PURE__*/_react.default.createElement(_Box.default, {
192
+ ref: containerRef,
193
+ display: "flex",
194
+ sx: {
195
+ alignItems: 'center',
196
+ flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
197
+ marginLeft: '-0.25rem',
198
+ marginBottom: '-0.25rem',
199
+ flexGrow: 1,
200
+ '> *': {
201
+ flexShrink: 0,
202
+ marginLeft: '0.25rem',
203
+ marginBottom: '0.25rem'
204
+ }
205
+ }
247
206
  }, /*#__PURE__*/_react.default.createElement(_Box.default, {
248
207
  sx: {
249
208
  order: 1,
@@ -255,13 +214,12 @@ function TextInputWithTokensInnerComponent({
255
214
  ref: combinedInputRef,
256
215
  disabled: disabled,
257
216
  onFocus: handleInputFocus,
258
- onBlur: handleInputBlur,
259
217
  onKeyDown: handleInputKeyDown,
260
218
  type: "text",
261
219
  sx: {
262
220
  height: '100%'
263
221
  }
264
- }, inputPropsRest))), TokenComponent ? visibleTokens.map(({
222
+ }, inputPropsRest))), tokens.length && TokenComponent ? tokens.map(({
265
223
  id,
266
224
  ...tokenRest
267
225
  }, i) => /*#__PURE__*/_react.default.createElement(TokenComponent, _extends({
@@ -269,7 +227,6 @@ function TextInputWithTokensInnerComponent({
269
227
  onFocus: handleTokenFocus(i),
270
228
  onBlur: handleTokenBlur,
271
229
  onKeyUp: handleTokenKeyUp,
272
- onClick: preventTokenClickPropagation,
273
230
  isSelected: selectedTokenIndex === i,
274
231
  onRemove: () => {
275
232
  handleTokenRemove(id);
@@ -277,10 +234,7 @@ function TextInputWithTokensInnerComponent({
277
234
  hideRemoveButton: hideTokenRemoveButtons,
278
235
  size: size,
279
236
  tabIndex: 0
280
- }, tokenRest))) : null, tokensAreTruncated ? /*#__PURE__*/_react.default.createElement(_Text.default, {
281
- color: "fg.muted",
282
- fontSize: size && overflowCountFontSizeMap[size]
283
- }, "+", tokens.length - visibleTokens.length) : null);
237
+ }, tokenRest))) : null));
284
238
  }
285
239
 
286
240
  TextInputWithTokensInnerComponent.displayName = "TextInputWithTokensInnerComponent";
@@ -39,7 +39,16 @@ const DefaultTokenStyled = (0, _styledComponents.default)(_TokenBase.default).wi
39
39
  const LeadingVisualContainer = (0, _styledComponents.default)('span').withConfig({
40
40
  displayName: "Token__LeadingVisualContainer",
41
41
  componentId: "sc-1dg52pw-1"
42
- })(["flex-shrink:0;line-height:0;"]);
42
+ })(["flex-shrink:0;line-height:0;", ""], props => {
43
+ switch (props.size) {
44
+ case 'large':
45
+ case 'extralarge':
46
+ return (0, _styledComponents.css)(["margin-right:", ";"], (0, _constants.get)('space.2'));
47
+
48
+ default:
49
+ return (0, _styledComponents.css)(["margin-right:", ";"], (0, _constants.get)('space.1'));
50
+ }
51
+ });
43
52
  const Token = /*#__PURE__*/(0, _react.forwardRef)((props, forwardedRef) => {
44
53
  const {
45
54
  as,
@@ -74,7 +83,9 @@ const Token = /*#__PURE__*/(0, _react.forwardRef)((props, forwardedRef) => {
74
83
  isTokenInteractive: (0, _TokenBase.isTokenInteractive)(props)
75
84
  }, !hasMultipleActionTargets ? interactiveTokenProps : {}, rest, {
76
85
  ref: forwardedRef
77
- }), LeadingVisual ? /*#__PURE__*/_react.default.createElement(LeadingVisualContainer, null, /*#__PURE__*/_react.default.createElement(LeadingVisual, null)) : null, /*#__PURE__*/_react.default.createElement(_TokenTextContainer.default, hasMultipleActionTargets ? interactiveTokenProps : {}, text), !hideRemoveButton && onRemove ? /*#__PURE__*/_react.default.createElement(_RemoveTokenButton.default, {
86
+ }), LeadingVisual ? /*#__PURE__*/_react.default.createElement(LeadingVisualContainer, {
87
+ size: size
88
+ }, /*#__PURE__*/_react.default.createElement(LeadingVisual, null)) : null, /*#__PURE__*/_react.default.createElement(_TokenTextContainer.default, hasMultipleActionTargets ? interactiveTokenProps : {}, text), !hideRemoveButton && onRemove ? /*#__PURE__*/_react.default.createElement(_RemoveTokenButton.default, {
78
89
  borderOffset: tokenBorderWidthPx,
79
90
  onClick: onRemoveClick,
80
91
  size: size,
@@ -38,7 +38,6 @@ const variants = (0, _styledSystem.variant)({
38
38
  variants: {
39
39
  small: {
40
40
  fontSize: 0,
41
- gap: 1,
42
41
  height: tokenSizes.small,
43
42
  // without setting lineHeight to match height, the "x" appears vertically mis-aligned
44
43
  lineHeight: tokenSizes.small,
@@ -51,7 +50,6 @@ const variants = (0, _styledSystem.variant)({
51
50
  },
52
51
  medium: {
53
52
  fontSize: 0,
54
- gap: 1,
55
53
  height: tokenSizes.medium,
56
54
  lineHeight: tokenSizes.medium,
57
55
  paddingLeft: 2,
@@ -61,7 +59,6 @@ const variants = (0, _styledSystem.variant)({
61
59
  },
62
60
  large: {
63
61
  fontSize: 0,
64
- gap: 2,
65
62
  height: tokenSizes.large,
66
63
  lineHeight: tokenSizes.large,
67
64
  paddingLeft: 2,
@@ -71,7 +68,6 @@ const variants = (0, _styledSystem.variant)({
71
68
  },
72
69
  extralarge: {
73
70
  fontSize: 1,
74
- gap: 2,
75
71
  height: tokenSizes.extralarge,
76
72
  lineHeight: tokenSizes.extralarge,
77
73
  paddingLeft: 3,
@@ -9,7 +9,7 @@ var _react = _interopRequireDefault(require("react"));
9
9
 
10
10
  var _octiconsReact = require("@primer/octicons-react");
11
11
 
12
- var _styledComponents = _interopRequireDefault(require("styled-components"));
12
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
13
13
 
14
14
  var _styledSystem = require("styled-system");
15
15
 
@@ -19,6 +19,10 @@ var _sx = _interopRequireDefault(require("../sx"));
19
19
 
20
20
  var _TokenBase = require("./TokenBase");
21
21
 
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+
24
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+
22
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
27
 
24
28
  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); }
@@ -50,7 +54,16 @@ const getTokenButtonIconSize = size => parseInt(_TokenBase.tokenSizes[size || _T
50
54
  const StyledTokenButton = _styledComponents.default.span.withConfig({
51
55
  displayName: "_RemoveTokenButton__StyledTokenButton",
52
56
  componentId: "sc-14lvcw1-0"
53
- })(["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)`, (0, _constants.get)('colors.neutral.muted'), (0, _constants.get)('colors.neutral.subtle'), variants, _sx.default);
57
+ })(["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 => {
58
+ switch (props.size) {
59
+ case 'large':
60
+ case 'extralarge':
61
+ return (0, _styledComponents.css)(["margin-left:", ";"], (0, _constants.get)('space.2'));
62
+
63
+ default:
64
+ return (0, _styledComponents.css)(["margin-left:", ";"], (0, _constants.get)('space.1'));
65
+ }
66
+ }, (0, _constants.get)('colors.neutral.muted'), (0, _constants.get)('colors.neutral.subtle'), variants, _sx.default);
54
67
 
55
68
  const RemoveTokenButton = ({
56
69
  'aria-label': ariaLabel,
@@ -39,7 +39,7 @@ const sizeVariants = (0, _styledSystem.variant)({
39
39
  const TextInputWrapper = _styledComponents.default.span.withConfig({
40
40
  displayName: "_TextInputWrapper__TextInputWrapper",
41
41
  componentId: "sc-5vfcis-0"
42
- })(["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:", ";}", " ", " ", " ", " ", ";"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('colors.fg.default'), (0, _constants.get)('colors.border.default'), (0, _constants.get)('radii.2'), (0, _constants.get)('shadows.primer.shadow.inset'), props => {
42
+ })(["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:", ";}", " ", " ", " ", " ", ";"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('colors.fg.default'), (0, _constants.get)('colors.border.default'), (0, _constants.get)('radii.2'), (0, _constants.get)('shadows.primer.shadow.inset'), props => {
43
43
  if (props.hasIcon) {
44
44
  return (0, _styledComponents.css)(["padding:0;"]);
45
45
  } else {
@@ -32,10 +32,6 @@ 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
- /**
36
- * The number of tokens to display before truncating
37
- */
38
- visibleTokenCount?: number | undefined;
39
35
  } & Pick<Omit<Pick<{
40
36
  [x: string]: any;
41
37
  [x: number]: any;
@@ -9,16 +9,9 @@ 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';
13
- import Text from './Text'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
-
15
- const overflowCountFontSizeMap = {
16
- small: 0,
17
- medium: 1,
18
- large: 1,
19
- extralarge: 2
20
- }; // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
12
+ import Box from './Box'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
13
 
14
+ // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
22
15
  function TextInputWithTokensInnerComponent({
23
16
  icon: IconComponent,
24
17
  contrast,
@@ -38,11 +31,9 @@ function TextInputWithTokensInnerComponent({
38
31
  minWidth: minWidthProp,
39
32
  maxWidth: maxWidthProp,
40
33
  variant: variantProp,
41
- visibleTokenCount,
42
34
  ...rest
43
35
  }, externalRef) {
44
36
  const {
45
- onBlur,
46
37
  onFocus,
47
38
  onKeyDown,
48
39
  ...inputPropsRest
@@ -51,7 +42,6 @@ function TextInputWithTokensInnerComponent({
51
42
  const localInputRef = useRef(null);
52
43
  const combinedInputRef = useCombinedRefs(localInputRef, ref);
53
44
  const [selectedTokenIndex, setSelectedTokenIndex] = useState();
54
- const [tokensAreTruncated, setTokensAreTruncated] = useState(Boolean(visibleTokenCount));
55
45
  const {
56
46
  containerRef
57
47
  } = useFocusZone({
@@ -101,45 +91,20 @@ function TextInputWithTokensInnerComponent({
101
91
  };
102
92
 
103
93
  const handleTokenBlur = () => {
104
- setSelectedTokenIndex(undefined); // HACK: wait a tick and check the focused element before hiding truncated tokens
105
- // this prevents the tokens from hiding when the user is moving focus between tokens,
106
- // but still hides the tokens when the user blurs the token by tabbing out or clicking somewhere else on the page
107
-
108
- setTimeout(() => {
109
- var _containerRef$current3;
110
-
111
- if (!((_containerRef$current3 = containerRef.current) !== null && _containerRef$current3 !== void 0 && _containerRef$current3.contains(document.activeElement)) && visibleTokenCount) {
112
- setTokensAreTruncated(true);
113
- }
114
- }, 0);
94
+ setSelectedTokenIndex(undefined);
115
95
  };
116
96
 
117
- const handleTokenKeyUp = event => {
118
- if (event.key === 'Escape') {
97
+ const handleTokenKeyUp = e => {
98
+ if (e.key === 'Escape') {
119
99
  var _ref$current;
120
100
 
121
101
  (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
122
102
  }
123
103
  };
124
104
 
125
- const handleInputFocus = event => {
126
- onFocus && onFocus(event);
105
+ const handleInputFocus = e => {
106
+ onFocus && onFocus(e);
127
107
  setSelectedTokenIndex(undefined);
128
- visibleTokenCount && setTokensAreTruncated(false);
129
- };
130
-
131
- const handleInputBlur = event => {
132
- onBlur && onBlur(event); // HACK: wait a tick and check the focused element before hiding truncated tokens
133
- // this prevents the tokens from hiding when the user is moving focus from the input to a token,
134
- // but still hides the tokens when the user blurs the input by tabbing out or clicking somewhere else on the page
135
-
136
- setTimeout(() => {
137
- var _containerRef$current4;
138
-
139
- if (!((_containerRef$current4 = containerRef.current) !== null && _containerRef$current4 !== void 0 && _containerRef$current4.contains(document.activeElement)) && visibleTokenCount) {
140
- setTokensAreTruncated(true);
141
- }
142
- }, 0);
143
108
  };
144
109
 
145
110
  const handleInputKeyDown = e => {
@@ -177,17 +142,6 @@ function TextInputWithTokensInnerComponent({
177
142
  }
178
143
  };
179
144
 
180
- const focusInput = () => {
181
- var _combinedInputRef$cur;
182
-
183
- (_combinedInputRef$cur = combinedInputRef.current) === null || _combinedInputRef$cur === void 0 ? void 0 : _combinedInputRef$cur.focus();
184
- };
185
-
186
- const preventTokenClickPropagation = event => {
187
- event.stopPropagation();
188
- };
189
-
190
- const visibleTokens = tokensAreTruncated ? tokens.slice(0, visibleTokenCount) : tokens;
191
145
  return /*#__PURE__*/React.createElement(TextInputWrapper, {
192
146
  block: block,
193
147
  className: className,
@@ -199,16 +153,7 @@ function TextInputWithTokensInnerComponent({
199
153
  minWidth: minWidthProp,
200
154
  maxWidth: maxWidthProp,
201
155
  variant: variantProp,
202
- ref: containerRef,
203
- onClick: focusInput,
204
- sx: {
205
- alignItems: 'center',
206
- flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
207
- gap: '0.25rem',
208
- '> *': {
209
- flexShrink: 0
210
- },
211
- ...(block ? {
156
+ sx: { ...(block ? {
212
157
  display: 'flex',
213
158
  width: '100%'
214
159
  } : {}),
@@ -221,6 +166,21 @@ function TextInputWithTokensInnerComponent({
221
166
  } : {}),
222
167
  ...sxProp
223
168
  }
169
+ }, /*#__PURE__*/React.createElement(Box, {
170
+ ref: containerRef,
171
+ display: "flex",
172
+ sx: {
173
+ alignItems: 'center',
174
+ flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
175
+ marginLeft: '-0.25rem',
176
+ marginBottom: '-0.25rem',
177
+ flexGrow: 1,
178
+ '> *': {
179
+ flexShrink: 0,
180
+ marginLeft: '0.25rem',
181
+ marginBottom: '0.25rem'
182
+ }
183
+ }
224
184
  }, /*#__PURE__*/React.createElement(Box, {
225
185
  sx: {
226
186
  order: 1,
@@ -232,13 +192,12 @@ function TextInputWithTokensInnerComponent({
232
192
  ref: combinedInputRef,
233
193
  disabled: disabled,
234
194
  onFocus: handleInputFocus,
235
- onBlur: handleInputBlur,
236
195
  onKeyDown: handleInputKeyDown,
237
196
  type: "text",
238
197
  sx: {
239
198
  height: '100%'
240
199
  }
241
- }, inputPropsRest))), TokenComponent ? visibleTokens.map(({
200
+ }, inputPropsRest))), tokens.length && TokenComponent ? tokens.map(({
242
201
  id,
243
202
  ...tokenRest
244
203
  }, i) => /*#__PURE__*/React.createElement(TokenComponent, _extends({
@@ -246,7 +205,6 @@ function TextInputWithTokensInnerComponent({
246
205
  onFocus: handleTokenFocus(i),
247
206
  onBlur: handleTokenBlur,
248
207
  onKeyUp: handleTokenKeyUp,
249
- onClick: preventTokenClickPropagation,
250
208
  isSelected: selectedTokenIndex === i,
251
209
  onRemove: () => {
252
210
  handleTokenRemove(id);
@@ -254,10 +212,7 @@ function TextInputWithTokensInnerComponent({
254
212
  hideRemoveButton: hideTokenRemoveButtons,
255
213
  size: size,
256
214
  tabIndex: 0
257
- }, tokenRest))) : null, tokensAreTruncated ? /*#__PURE__*/React.createElement(Text, {
258
- color: "fg.muted",
259
- fontSize: size && overflowCountFontSizeMap[size]
260
- }, "+", tokens.length - visibleTokens.length) : null);
215
+ }, tokenRest))) : null));
261
216
  }
262
217
 
263
218
  TextInputWithTokensInnerComponent.displayName = "TextInputWithTokensInnerComponent";
@@ -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, null, /*#__PURE__*/React.createElement(LeadingVisual, null)) : null, /*#__PURE__*/React.createElement(TokenTextContainer, hasMultipleActionTargets ? interactiveTokenProps : {}, text), !hideRemoveButton && onRemove ? /*#__PURE__*/React.createElement(RemoveTokenButton, {
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;&:hover,&:focus{background-color:", ";}&:active{background-color:", ";}", " ", ""], props => `translate(${props.borderOffset}px, -${props.borderOffset}px)`, get('colors.neutral.muted'), get('colors.neutral.subtle'), variants, sx);
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:", ";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 => {
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
25
  if (props.hasIcon) {
26
26
  return css(["padding:0;"]);
27
27
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-2021919202426",
3
+ "version": "0.0.0-2021921114926",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",