@primer/components 0.0.0-2021919202426 → 0.0.0-2021920152952

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.
Files changed (187) hide show
  1. package/CHANGELOG.md +1 -19
  2. package/codemods/deprecateUtilityComponents.js +1 -1
  3. package/dist/browser.esm.js +768 -879
  4. package/dist/browser.esm.js.map +1 -1
  5. package/dist/browser.umd.js +773 -884
  6. package/dist/browser.umd.js.map +1 -1
  7. package/lib/ActionList/Item.js +4 -4
  8. package/lib/ActionList/List.d.ts +1 -2
  9. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
  10. package/lib/AnchoredOverlay/AnchoredOverlay.js +3 -11
  11. package/lib/BaseStyles.js +1 -1
  12. package/lib/BorderBox.js +1 -1
  13. package/lib/Button/Button.js +1 -1
  14. package/lib/Button/ButtonInvisible.js +1 -1
  15. package/lib/Button/ButtonTableList.js +1 -1
  16. package/lib/Caret.js +2 -2
  17. package/lib/DatePicker/DatePicker.d.ts +47 -0
  18. package/lib/DatePicker/DatePicker.js +76 -0
  19. package/lib/DatePicker/DatePickerAnchor.d.ts +10 -0
  20. package/lib/DatePicker/DatePickerAnchor.js +83 -0
  21. package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
  22. package/lib/DatePicker/DatePickerPanel.js +38 -0
  23. package/lib/DatePicker/Day.d.ts +13 -0
  24. package/lib/DatePicker/Day.js +136 -0
  25. package/lib/DatePicker/Month.d.ts +9 -0
  26. package/lib/DatePicker/Month.js +97 -0
  27. package/lib/DatePicker/index.d.ts +2 -0
  28. package/lib/DatePicker/index.js +13 -0
  29. package/lib/DatePicker/useDatePicker.d.ts +51 -0
  30. package/lib/DatePicker/useDatePicker.js +133 -0
  31. package/lib/Dialog.js +1 -1
  32. package/lib/FilteredActionList/FilteredActionList.js +31 -5
  33. package/lib/Flash.js +16 -16
  34. package/lib/Label.js +1 -1
  35. package/lib/Overlay.d.ts +0 -1
  36. package/lib/Overlay.js +1 -3
  37. package/lib/Pagination/Pagination.js +1 -1
  38. package/lib/ProgressBar.js +1 -1
  39. package/lib/SelectMenu/SelectMenu.d.ts +10 -10
  40. package/lib/StateLabel.js +19 -13
  41. package/lib/TextInput.d.ts +13 -5
  42. package/lib/TextInput.js +46 -4
  43. package/lib/hooks/useOpenAndCloseFocus.d.ts +1 -2
  44. package/lib/hooks/useOpenAndCloseFocus.js +2 -7
  45. package/lib/hooks/useOverlay.d.ts +1 -2
  46. package/lib/hooks/useOverlay.js +2 -4
  47. package/lib/index.d.ts +0 -5
  48. package/lib/index.js +0 -36
  49. package/lib/theme-preval.js +3105 -375
  50. package/lib/utils/testing.d.ts +493 -50
  51. package/{lib-esm/utils/types/AriaRole.d.ts → lib/utils/types.d.ts} +13 -0
  52. package/lib/utils/{types/AriaRole.js → types.js} +0 -0
  53. package/lib-esm/ActionList/Item.js +4 -4
  54. package/lib-esm/ActionList/List.d.ts +1 -2
  55. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
  56. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -11
  57. package/lib-esm/BaseStyles.js +1 -1
  58. package/lib-esm/BorderBox.js +1 -1
  59. package/lib-esm/Button/Button.js +1 -1
  60. package/lib-esm/Button/ButtonInvisible.js +1 -1
  61. package/lib-esm/Button/ButtonTableList.js +1 -1
  62. package/lib-esm/Caret.js +2 -2
  63. package/lib-esm/DatePicker/DatePicker.d.ts +47 -0
  64. package/lib-esm/DatePicker/DatePicker.js +57 -0
  65. package/lib-esm/DatePicker/DatePickerAnchor.d.ts +10 -0
  66. package/lib-esm/DatePicker/DatePickerAnchor.js +59 -0
  67. package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
  68. package/lib-esm/DatePicker/DatePickerPanel.js +20 -0
  69. package/lib-esm/DatePicker/Day.d.ts +13 -0
  70. package/lib-esm/DatePicker/Day.js +113 -0
  71. package/lib-esm/DatePicker/Month.d.ts +9 -0
  72. package/lib-esm/DatePicker/Month.js +74 -0
  73. package/lib-esm/DatePicker/index.d.ts +2 -0
  74. package/lib-esm/DatePicker/index.js +1 -0
  75. package/lib-esm/DatePicker/useDatePicker.d.ts +51 -0
  76. package/lib-esm/DatePicker/useDatePicker.js +114 -0
  77. package/lib-esm/Dialog.js +1 -1
  78. package/lib-esm/FilteredActionList/FilteredActionList.js +31 -3
  79. package/lib-esm/Flash.js +16 -16
  80. package/lib-esm/Label.js +1 -1
  81. package/lib-esm/Overlay.d.ts +0 -1
  82. package/lib-esm/Overlay.js +1 -3
  83. package/lib-esm/Pagination/Pagination.js +1 -1
  84. package/lib-esm/ProgressBar.js +1 -1
  85. package/lib-esm/SelectMenu/SelectMenu.d.ts +10 -10
  86. package/lib-esm/StateLabel.js +19 -13
  87. package/lib-esm/TextInput.d.ts +13 -5
  88. package/lib-esm/TextInput.js +37 -4
  89. package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +1 -2
  90. package/lib-esm/hooks/useOpenAndCloseFocus.js +2 -7
  91. package/lib-esm/hooks/useOverlay.d.ts +1 -2
  92. package/lib-esm/hooks/useOverlay.js +2 -4
  93. package/lib-esm/index.d.ts +0 -5
  94. package/lib-esm/index.js +0 -3
  95. package/lib-esm/theme-preval.js +3105 -375
  96. package/lib-esm/utils/testing.d.ts +493 -50
  97. package/{lib/utils/types/AriaRole.d.ts → lib-esm/utils/types.d.ts} +13 -0
  98. package/lib-esm/utils/{types/AriaRole.js → types.js} +0 -0
  99. package/package.json +4 -4
  100. package/lib/Autocomplete/Autocomplete.d.ts +0 -304
  101. package/lib/Autocomplete/Autocomplete.js +0 -145
  102. package/lib/Autocomplete/AutocompleteContext.d.ts +0 -17
  103. package/lib/Autocomplete/AutocompleteContext.js +0 -11
  104. package/lib/Autocomplete/AutocompleteInput.d.ts +0 -292
  105. package/lib/Autocomplete/AutocompleteInput.js +0 -157
  106. package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -72
  107. package/lib/Autocomplete/AutocompleteMenu.js +0 -224
  108. package/lib/Autocomplete/AutocompleteOverlay.d.ts +0 -20
  109. package/lib/Autocomplete/AutocompleteOverlay.js +0 -80
  110. package/lib/Autocomplete/index.d.ts +0 -2
  111. package/lib/Autocomplete/index.js +0 -15
  112. package/lib/TextInputWithTokens.d.ts +0 -327
  113. package/lib/TextInputWithTokens.js +0 -298
  114. package/lib/Token/AvatarToken.d.ts +0 -7
  115. package/lib/Token/AvatarToken.js +0 -64
  116. package/lib/Token/IssueLabelToken.d.ts +0 -14
  117. package/lib/Token/IssueLabelToken.js +0 -144
  118. package/lib/Token/Token.d.ts +0 -15
  119. package/lib/Token/Token.js +0 -94
  120. package/lib/Token/TokenBase.d.ts +0 -31
  121. package/lib/Token/TokenBase.js +0 -108
  122. package/lib/Token/_RemoveTokenButton.d.ts +0 -12
  123. package/lib/Token/_RemoveTokenButton.js +0 -77
  124. package/lib/Token/_TokenTextContainer.d.ts +0 -3
  125. package/lib/Token/_TokenTextContainer.js +0 -17
  126. package/lib/Token/index.d.ts +0 -3
  127. package/lib/Token/index.js +0 -31
  128. package/lib/_TextInputWrapper.d.ts +0 -10
  129. package/lib/_TextInputWrapper.js +0 -51
  130. package/lib/_UnstyledTextInput.d.ts +0 -2
  131. package/lib/_UnstyledTextInput.js +0 -20
  132. package/lib/behaviors/scrollIntoViewingArea.d.ts +0 -1
  133. package/lib/behaviors/scrollIntoViewingArea.js +0 -39
  134. package/lib/utils/types/ComponentProps.d.ts +0 -9
  135. package/lib/utils/types/ComponentProps.js +0 -1
  136. package/lib/utils/types/Flatten.d.ts +0 -4
  137. package/lib/utils/types/Flatten.js +0 -1
  138. package/lib/utils/types/MandateProps.d.ts +0 -3
  139. package/lib/utils/types/MandateProps.js +0 -1
  140. package/lib/utils/types/Merge.d.ts +0 -19
  141. package/lib/utils/types/Merge.js +0 -1
  142. package/lib/utils/types/index.d.ts +0 -5
  143. package/lib/utils/types/index.js +0 -70
  144. package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -304
  145. package/lib-esm/Autocomplete/Autocomplete.js +0 -123
  146. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -17
  147. package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
  148. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -292
  149. package/lib-esm/Autocomplete/AutocompleteInput.js +0 -138
  150. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -72
  151. package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -205
  152. package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +0 -20
  153. package/lib-esm/Autocomplete/AutocompleteOverlay.js +0 -62
  154. package/lib-esm/Autocomplete/index.d.ts +0 -2
  155. package/lib-esm/Autocomplete/index.js +0 -1
  156. package/lib-esm/TextInputWithTokens.d.ts +0 -327
  157. package/lib-esm/TextInputWithTokens.js +0 -272
  158. package/lib-esm/Token/AvatarToken.d.ts +0 -7
  159. package/lib-esm/Token/AvatarToken.js +0 -43
  160. package/lib-esm/Token/IssueLabelToken.d.ts +0 -14
  161. package/lib-esm/Token/IssueLabelToken.js +0 -124
  162. package/lib-esm/Token/Token.d.ts +0 -15
  163. package/lib-esm/Token/Token.js +0 -73
  164. package/lib-esm/Token/TokenBase.d.ts +0 -31
  165. package/lib-esm/Token/TokenBase.js +0 -87
  166. package/lib-esm/Token/_RemoveTokenButton.d.ts +0 -12
  167. package/lib-esm/Token/_RemoveTokenButton.js +0 -60
  168. package/lib-esm/Token/_TokenTextContainer.d.ts +0 -3
  169. package/lib-esm/Token/_TokenTextContainer.js +0 -6
  170. package/lib-esm/Token/index.d.ts +0 -3
  171. package/lib-esm/Token/index.js +0 -3
  172. package/lib-esm/_TextInputWrapper.d.ts +0 -10
  173. package/lib-esm/_TextInputWrapper.js +0 -31
  174. package/lib-esm/_UnstyledTextInput.d.ts +0 -2
  175. package/lib-esm/_UnstyledTextInput.js +0 -7
  176. package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +0 -1
  177. package/lib-esm/behaviors/scrollIntoViewingArea.js +0 -30
  178. package/lib-esm/utils/types/ComponentProps.d.ts +0 -9
  179. package/lib-esm/utils/types/ComponentProps.js +0 -1
  180. package/lib-esm/utils/types/Flatten.d.ts +0 -4
  181. package/lib-esm/utils/types/Flatten.js +0 -1
  182. package/lib-esm/utils/types/MandateProps.d.ts +0 -3
  183. package/lib-esm/utils/types/MandateProps.js +0 -1
  184. package/lib-esm/utils/types/Merge.d.ts +0 -19
  185. package/lib-esm/utils/types/Merge.js +0 -1
  186. package/lib-esm/utils/types/index.d.ts +0 -5
  187. package/lib-esm/utils/types/index.js +0 -5
@@ -1,272 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import React, { useRef, useState } from 'react';
4
- import { omit } from '@styled-system/props';
5
- import { FocusKeys } from './behaviors/focusZone';
6
- import { useCombinedRefs } from './hooks/useCombinedRefs';
7
- import { useFocusZone } from './hooks/useFocusZone';
8
- import Token from './Token/Token';
9
- import { useProvidedRefOrCreate } from './hooks';
10
- import UnstyledTextInput from './_UnstyledTextInput';
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
21
-
22
- function TextInputWithTokensInnerComponent({
23
- icon: IconComponent,
24
- contrast,
25
- className,
26
- block,
27
- disabled,
28
- theme,
29
- sx: sxProp,
30
- tokens,
31
- onTokenRemove,
32
- tokenComponent: TokenComponent,
33
- preventTokenWrapping,
34
- size,
35
- hideTokenRemoveButtons,
36
- maxHeight,
37
- width: widthProp,
38
- minWidth: minWidthProp,
39
- maxWidth: maxWidthProp,
40
- variant: variantProp,
41
- visibleTokenCount,
42
- ...rest
43
- }, externalRef) {
44
- const {
45
- onBlur,
46
- onFocus,
47
- onKeyDown,
48
- ...inputPropsRest
49
- } = omit(rest);
50
- const ref = useProvidedRefOrCreate(externalRef);
51
- const localInputRef = useRef(null);
52
- const combinedInputRef = useCombinedRefs(localInputRef, ref);
53
- const [selectedTokenIndex, setSelectedTokenIndex] = useState();
54
- const [tokensAreTruncated, setTokensAreTruncated] = useState(Boolean(visibleTokenCount));
55
- const {
56
- containerRef
57
- } = useFocusZone({
58
- focusOutBehavior: 'wrap',
59
- bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
60
- focusableElementFilter: element => {
61
- return !element.getAttributeNames().includes('aria-hidden');
62
- },
63
- getNextFocusable: direction => {
64
- var _containerRef$current;
65
-
66
- if (!selectedTokenIndex && selectedTokenIndex !== 0) {
67
- return undefined;
68
- }
69
-
70
- let nextIndex = selectedTokenIndex + 1; // "+ 1" accounts for the first element: the text input
71
-
72
- if (direction === 'next') {
73
- nextIndex += 1;
74
- }
75
-
76
- if (direction === 'previous') {
77
- nextIndex -= 1;
78
- }
79
-
80
- if (nextIndex > tokens.length || nextIndex < 1) {
81
- return combinedInputRef.current || undefined;
82
- }
83
-
84
- return (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
85
- }
86
- }, [selectedTokenIndex]);
87
-
88
- const handleTokenRemove = tokenId => {
89
- onTokenRemove(tokenId);
90
-
91
- if (selectedTokenIndex) {
92
- var _containerRef$current2;
93
-
94
- const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
95
- nextElementToFocus.focus();
96
- }
97
- };
98
-
99
- const handleTokenFocus = tokenIndex => () => {
100
- setSelectedTokenIndex(tokenIndex);
101
- };
102
-
103
- 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);
115
- };
116
-
117
- const handleTokenKeyUp = event => {
118
- if (event.key === 'Escape') {
119
- var _ref$current;
120
-
121
- (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
122
- }
123
- };
124
-
125
- const handleInputFocus = event => {
126
- onFocus && onFocus(event);
127
- 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
- };
144
-
145
- const handleInputKeyDown = e => {
146
- var _ref$current2;
147
-
148
- if (onKeyDown) {
149
- onKeyDown(e);
150
- }
151
-
152
- if ((_ref$current2 = ref.current) !== null && _ref$current2 !== void 0 && _ref$current2.value) {
153
- return;
154
- }
155
-
156
- const lastToken = tokens[tokens.length - 1];
157
-
158
- if (e.key === 'Backspace' && lastToken) {
159
- handleTokenRemove(lastToken.id);
160
-
161
- if (ref.current) {
162
- // TODO: eliminate the first hack by making changes to the Autocomplete component
163
- //
164
- // HACKS:
165
- // 1. Directly setting `ref.current.value` instead of updating state because the autocomplete
166
- // highlight behavior doesn't work correctly if we update the value with a setState action in onChange
167
- // 2. Adding an extra space so that when I backspace, it doesn't delete the last letter
168
- ref.current.value = `${lastToken.text} `;
169
- } // HACK: for some reason we need to wait a tick for `.select()` to work
170
-
171
-
172
- setTimeout(() => {
173
- var _ref$current3;
174
-
175
- (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.select();
176
- }, 0);
177
- }
178
- };
179
-
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
- return /*#__PURE__*/React.createElement(TextInputWrapper, {
192
- block: block,
193
- className: className,
194
- contrast: contrast,
195
- disabled: disabled,
196
- hasIcon: !!IconComponent,
197
- theme: theme,
198
- width: widthProp,
199
- minWidth: minWidthProp,
200
- maxWidth: maxWidthProp,
201
- 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 ? {
212
- display: 'flex',
213
- width: '100%'
214
- } : {}),
215
- ...(maxHeight ? {
216
- maxHeight,
217
- overflow: 'auto'
218
- } : {}),
219
- ...(preventTokenWrapping ? {
220
- overflow: 'auto'
221
- } : {}),
222
- ...sxProp
223
- }
224
- }, /*#__PURE__*/React.createElement(Box, {
225
- sx: {
226
- order: 1,
227
- flexGrow: 1
228
- }
229
- }, IconComponent && /*#__PURE__*/React.createElement(IconComponent, {
230
- className: "TextInput-icon"
231
- }), /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
232
- ref: combinedInputRef,
233
- disabled: disabled,
234
- onFocus: handleInputFocus,
235
- onBlur: handleInputBlur,
236
- onKeyDown: handleInputKeyDown,
237
- type: "text",
238
- sx: {
239
- height: '100%'
240
- }
241
- }, inputPropsRest))), TokenComponent ? visibleTokens.map(({
242
- id,
243
- ...tokenRest
244
- }, i) => /*#__PURE__*/React.createElement(TokenComponent, _extends({
245
- key: id,
246
- onFocus: handleTokenFocus(i),
247
- onBlur: handleTokenBlur,
248
- onKeyUp: handleTokenKeyUp,
249
- onClick: preventTokenClickPropagation,
250
- isSelected: selectedTokenIndex === i,
251
- onRemove: () => {
252
- handleTokenRemove(id);
253
- },
254
- hideRemoveButton: hideTokenRemoveButtons,
255
- size: size,
256
- 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);
261
- }
262
-
263
- TextInputWithTokensInnerComponent.displayName = "TextInputWithTokensInnerComponent";
264
- const TextInputWithTokens = /*#__PURE__*/React.forwardRef(TextInputWithTokensInnerComponent);
265
- TextInputWithTokens.defaultProps = {
266
- tokenComponent: Token,
267
- size: 'extralarge',
268
- hideTokenRemoveButtons: false,
269
- preventTokenWrapping: false
270
- };
271
- TextInputWithTokens.displayName = 'TextInputWithTokens';
272
- export default TextInputWithTokens;
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- import { TokenBaseProps } from './TokenBase';
3
- export interface AvatarTokenProps extends TokenBaseProps {
4
- avatarSrc: string;
5
- }
6
- declare const AvatarToken: React.ForwardRefExoticComponent<Pick<AvatarTokenProps, "sizes" | "color" | "content" | "height" | "translate" | "width" | "hidden" | "children" | "value" | "cite" | "data" | "form" | "label" | "slot" | "span" | "style" | "summary" | "title" | "pattern" | "text" | "list" | "default" | "type" | "name" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "start" | "step" | "size" | "wrap" | "open" | "max" | "media" | "method" | "min" | "target" | "crossOrigin" | "href" | "classID" | "useMap" | "wmode" | "download" | "hrefLang" | "rel" | "alt" | "coords" | "shape" | "autoPlay" | "controls" | "loop" | "mediaGroup" | "muted" | "playsInline" | "preload" | "src" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "dateTime" | "acceptCharset" | "action" | "autoComplete" | "encType" | "noValidate" | "manifest" | "allowFullScreen" | "allowTransparency" | "frameBorder" | "marginHeight" | "marginWidth" | "sandbox" | "scrolling" | "seamless" | "srcDoc" | "srcSet" | "async" | "accept" | "capture" | "checked" | "maxLength" | "minLength" | "multiple" | "readOnly" | "required" | "challenge" | "keyType" | "keyParams" | "htmlFor" | "as" | "integrity" | "charSet" | "httpEquiv" | "high" | "low" | "optimum" | "reversed" | "selected" | "defer" | "nonce" | "scoped" | "cellPadding" | "cellSpacing" | "colSpan" | "headers" | "rowSpan" | "scope" | "cols" | "rows" | "kind" | "srcLang" | "poster" | "onRemove" | "isSelected" | "avatarSrc"> & React.RefAttributes<HTMLElement>>;
7
- export default AvatarToken;
@@ -1,43 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import React, { forwardRef } from 'react';
4
- import styled from 'styled-components';
5
- import { get } from '../constants';
6
- import { defaultTokenSize, tokenSizes } from './TokenBase';
7
- import Token from './Token';
8
- import { Avatar } from '..';
9
- const AvatarContainer = styled.span.withConfig({
10
- displayName: "AvatarToken__AvatarContainer",
11
- componentId: "ubyudc-0"
12
- })(["--spacing:calc(", " * 2);display:block;height:", ";width:", ";"], get('space.1'), props => `calc(${tokenSizes[props.avatarSize]} - var(--spacing))`, props => `calc(${tokenSizes[props.avatarSize]} - var(--spacing))`);
13
- const AvatarToken = /*#__PURE__*/forwardRef(({
14
- avatarSrc,
15
- id,
16
- size,
17
- ...rest
18
- }, forwardedRef) => {
19
- return /*#__PURE__*/React.createElement(Token, _extends({
20
- leadingVisual: () => /*#__PURE__*/React.createElement(AvatarContainer, {
21
- avatarSize: size || defaultTokenSize
22
- }, /*#__PURE__*/React.createElement(Avatar, {
23
- src: avatarSrc,
24
- size: parseInt(tokenSizes[size || defaultTokenSize], 10),
25
- sx: {
26
- width: '100%',
27
- height: '100%'
28
- }
29
- })),
30
- size: size,
31
- id: id === null || id === void 0 ? void 0 : id.toString(),
32
- sx: {
33
- paddingLeft: get('space.1')
34
- }
35
- }, rest, {
36
- ref: forwardedRef
37
- }));
38
- });
39
- AvatarToken.defaultProps = {
40
- size: defaultTokenSize
41
- };
42
- AvatarToken.displayName = 'AvatarToken';
43
- export default AvatarToken;
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import { TokenBaseProps } from './TokenBase';
3
- export interface IssueLabelTokenProps extends TokenBaseProps {
4
- /**
5
- * The color that corresponds to the label
6
- */
7
- fillColor?: string;
8
- /**
9
- * Whether the remove button should be rendered in the token
10
- */
11
- hideRemoveButton?: boolean;
12
- }
13
- declare const IssueLabelToken: React.ForwardRefExoticComponent<Pick<IssueLabelTokenProps, "sizes" | "color" | "content" | "height" | "translate" | "width" | "hidden" | "children" | "value" | "cite" | "data" | "form" | "label" | "slot" | "span" | "style" | "summary" | "title" | "pattern" | "text" | "list" | "default" | "type" | "name" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "start" | "step" | "size" | "wrap" | "open" | "max" | "media" | "method" | "min" | "target" | "crossOrigin" | "href" | "classID" | "useMap" | "wmode" | "download" | "hrefLang" | "rel" | "alt" | "coords" | "shape" | "autoPlay" | "controls" | "loop" | "mediaGroup" | "muted" | "playsInline" | "preload" | "src" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "dateTime" | "acceptCharset" | "action" | "autoComplete" | "encType" | "noValidate" | "manifest" | "allowFullScreen" | "allowTransparency" | "frameBorder" | "marginHeight" | "marginWidth" | "sandbox" | "scrolling" | "seamless" | "srcDoc" | "srcSet" | "async" | "accept" | "capture" | "checked" | "maxLength" | "minLength" | "multiple" | "readOnly" | "required" | "challenge" | "keyType" | "keyParams" | "htmlFor" | "as" | "integrity" | "charSet" | "httpEquiv" | "high" | "low" | "optimum" | "reversed" | "selected" | "defer" | "nonce" | "scoped" | "cellPadding" | "cellSpacing" | "colSpan" | "headers" | "rowSpan" | "scope" | "cols" | "rows" | "kind" | "srcLang" | "poster" | "onRemove" | "isSelected" | "hideRemoveButton" | "fillColor"> & React.RefAttributes<HTMLElement>>;
14
- export default IssueLabelToken;
@@ -1,124 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import React, { forwardRef, useMemo } from 'react';
4
- import TokenBase, { defaultTokenSize, isTokenInteractive } from './TokenBase';
5
- import RemoveTokenButton from './_RemoveTokenButton';
6
- import { parseToHsla, parseToRgba } from 'color2k';
7
- import { useTheme } from '../ThemeProvider';
8
- import TokenTextContainer from './_TokenTextContainer';
9
- const tokenBorderWidthPx = 1;
10
- const lightModeStyles = {
11
- '--lightness-threshold': '0.453',
12
- '--border-threshold': '0.96',
13
- '--border-alpha': 'max(0, min(calc((var(--perceived-lightness) - var(--border-threshold)) * 100), 1))',
14
- background: 'rgb(var(--label-r), var(--label-g), var(--label-b))',
15
- color: 'hsl(0, 0%, calc(var(--lightness-switch) * 100%))',
16
- borderWidth: tokenBorderWidthPx,
17
- borderStyle: 'solid',
18
- borderColor: 'hsla(var(--label-h),calc(var(--label-s) * 1%),calc((var(--label-l) - 25) * 1%),var(--border-alpha))'
19
- };
20
- const darkModeStyles = {
21
- '--lightness-threshold': '0.6',
22
- '--background-alpha': '0.18',
23
- '--border-alpha': '0.3',
24
- '--lighten-by': 'calc(((var(--lightness-threshold) - var(--perceived-lightness)) * 100) * var(--lightness-switch))',
25
- borderWidth: tokenBorderWidthPx,
26
- borderStyle: 'solid',
27
- background: 'rgba(var(--label-r), var(--label-g), var(--label-b), var(--background-alpha))',
28
- color: 'hsl(var(--label-h), calc(var(--label-s) * 1%), calc((var(--label-l) + var(--lighten-by)) * 1%))',
29
- borderColor: 'hsla(var(--label-h), calc(var(--label-s) * 1%),calc((var(--label-l) + var(--lighten-by)) * 1%),var(--border-alpha))'
30
- };
31
- const IssueLabelToken = /*#__PURE__*/forwardRef((props, forwardedRef) => {
32
- const {
33
- as,
34
- fillColor = '#999',
35
- onRemove,
36
- id,
37
- isSelected,
38
- text,
39
- size,
40
- hideRemoveButton,
41
- href,
42
- onClick,
43
- ...rest
44
- } = props;
45
- const interactiveTokenProps = {
46
- as,
47
- href,
48
- onClick
49
- };
50
- const {
51
- colorScheme
52
- } = useTheme();
53
- const hasMultipleActionTargets = isTokenInteractive(props) && Boolean(onRemove) && !hideRemoveButton;
54
-
55
- const onRemoveClick = e => {
56
- e.stopPropagation();
57
- onRemove && onRemove();
58
- };
59
-
60
- const labelStyles = useMemo(() => {
61
- const [r, g, b] = parseToRgba(fillColor);
62
- const [h, s, l] = parseToHsla(fillColor); // label hack taken from https://github.com/github/github/blob/master/app/assets/stylesheets/hacks/hx_primer-labels.scss#L43-L108
63
- // this logic should eventually live in primer/components. Also worthy of note is that the dotcom hack code will be moving to primer/css soon.
64
-
65
- return {
66
- '--label-r': String(r),
67
- '--label-g': String(g),
68
- '--label-b': String(b),
69
- '--label-h': String(Math.round(h)),
70
- '--label-s': String(Math.round(s * 100)),
71
- '--label-l': String(Math.round(l * 100)),
72
- '--perceived-lightness': 'calc(((var(--label-r) * 0.2126) + (var(--label-g) * 0.7152) + (var(--label-b) * 0.0722)) / 255)',
73
- '--lightness-switch': 'max(0, min(calc((var(--perceived-lightness) - var(--lightness-threshold)) * -1000), 1))',
74
- paddingRight: hideRemoveButton || !onRemove ? undefined : 0,
75
- position: 'relative',
76
- ...(colorScheme === 'light' ? lightModeStyles : darkModeStyles),
77
- ...(isSelected ? {
78
- background: colorScheme === 'light' ? 'hsl(var(--label-h), calc(var(--label-s) * 1%), calc((var(--label-l) - 5) * 1%))' : darkModeStyles.background,
79
- ':focus': {
80
- outline: 'none'
81
- },
82
- ':after': {
83
- content: '""',
84
- position: 'absolute',
85
- zIndex: 1,
86
- top: `-${tokenBorderWidthPx * 2}px`,
87
- right: `-${tokenBorderWidthPx * 2}px`,
88
- bottom: `-${tokenBorderWidthPx * 2}px`,
89
- left: `-${tokenBorderWidthPx * 2}px`,
90
- display: 'block',
91
- pointerEvents: 'none',
92
- boxShadow: `0 0 0 ${tokenBorderWidthPx * 2}px ${colorScheme === 'light' ? 'rgb(var(--label-r), var(--label-g), var(--label-b))' : 'hsl(var(--label-h), calc(var(--label-s) * 1%), calc((var(--label-l) + var(--lighten-by)) * 1%))'}`,
93
- borderRadius: '999px'
94
- }
95
- } : {})
96
- };
97
- }, [colorScheme, fillColor, isSelected, hideRemoveButton, onRemove]);
98
- return /*#__PURE__*/React.createElement(TokenBase, _extends({
99
- onRemove: onRemove,
100
- id: id === null || id === void 0 ? void 0 : id.toString(),
101
- isSelected: isSelected,
102
- text: text,
103
- size: size,
104
- sx: labelStyles
105
- }, !hasMultipleActionTargets ? interactiveTokenProps : {}, rest, {
106
- ref: forwardedRef
107
- }), /*#__PURE__*/React.createElement(TokenTextContainer, hasMultipleActionTargets ? interactiveTokenProps : {}, text), !hideRemoveButton && onRemove ? /*#__PURE__*/React.createElement(RemoveTokenButton, {
108
- borderOffset: tokenBorderWidthPx,
109
- onClick: onRemoveClick,
110
- size: size,
111
- "aria-hidden": hasMultipleActionTargets ? 'true' : 'false',
112
- isParentInteractive: isTokenInteractive(props),
113
- sx: hasMultipleActionTargets ? {
114
- position: 'relative',
115
- zIndex: '1'
116
- } : {}
117
- }) : null);
118
- });
119
- IssueLabelToken.defaultProps = {
120
- fillColor: '#999',
121
- size: defaultTokenSize
122
- };
123
- IssueLabelToken.displayName = 'IssueLabelToken';
124
- export default IssueLabelToken;
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- import { SxProp } from '../sx';
3
- import { TokenBaseProps } from './TokenBase';
4
- export interface TokenProps extends TokenBaseProps {
5
- /**
6
- * A function that renders a component before the token text
7
- */
8
- leadingVisual?: React.ComponentType<any>;
9
- /**
10
- * Whether the remove button should be rendered in the token
11
- */
12
- hideRemoveButton?: boolean;
13
- }
14
- declare const Token: React.ForwardRefExoticComponent<Pick<TokenProps & SxProp, "sizes" | "color" | "content" | "height" | "translate" | "width" | "hidden" | "children" | "value" | "cite" | "data" | "form" | "label" | "slot" | "span" | "style" | "summary" | "title" | "pattern" | "text" | "list" | "default" | "type" | "name" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "start" | "step" | "size" | "wrap" | "open" | "sx" | "max" | "media" | "method" | "min" | "target" | "crossOrigin" | "href" | "classID" | "useMap" | "wmode" | "download" | "hrefLang" | "rel" | "alt" | "coords" | "shape" | "autoPlay" | "controls" | "loop" | "mediaGroup" | "muted" | "playsInline" | "preload" | "src" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "dateTime" | "acceptCharset" | "action" | "autoComplete" | "encType" | "noValidate" | "manifest" | "allowFullScreen" | "allowTransparency" | "frameBorder" | "marginHeight" | "marginWidth" | "sandbox" | "scrolling" | "seamless" | "srcDoc" | "srcSet" | "async" | "accept" | "capture" | "checked" | "maxLength" | "minLength" | "multiple" | "readOnly" | "required" | "challenge" | "keyType" | "keyParams" | "htmlFor" | "as" | "integrity" | "charSet" | "httpEquiv" | "high" | "low" | "optimum" | "reversed" | "selected" | "defer" | "nonce" | "scoped" | "cellPadding" | "cellSpacing" | "colSpan" | "headers" | "rowSpan" | "scope" | "cols" | "rows" | "kind" | "srcLang" | "poster" | "leadingVisual" | "onRemove" | "isSelected" | "hideRemoveButton"> & React.RefAttributes<HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement>>;
15
- export default Token;
@@ -1,73 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import React, { forwardRef } from 'react';
4
- import styled, { css } from 'styled-components';
5
- import { get } from '../constants';
6
- import sx from '../sx';
7
- import TokenBase, { defaultTokenSize, isTokenInteractive } from './TokenBase';
8
- import RemoveTokenButton from './_RemoveTokenButton';
9
- import TokenTextContainer from './_TokenTextContainer';
10
- const tokenBorderWidthPx = 1;
11
- const DefaultTokenStyled = styled(TokenBase).withConfig({
12
- displayName: "Token__DefaultTokenStyled",
13
- componentId: "sc-1dg52pw-0"
14
- })(["background-color:", ";border-color:", ";border-style:solid;border-width:", "px;color:", ";max-width:100%;padding-right:", ";position:relative;", " ", ""], get('colors.neutral.subtle'), props => props.isSelected ? get('colors.fg.default') : get('colors.border.subtle'), tokenBorderWidthPx, props => props.isSelected ? get('colors.fg.default') : get('colors.fg.muted'), props => !props.hideRemoveButton ? 0 : undefined, sx, props => {
15
- if (props.isTokenInteractive) {
16
- return css(["&:hover{background-color:", ";box-shadow:", ";color:", ";}"], get('colors.neutral.muted'), get('colors.shadow.medium'), get('colors.fg.default'));
17
- }
18
- });
19
- const LeadingVisualContainer = styled('span').withConfig({
20
- displayName: "Token__LeadingVisualContainer",
21
- componentId: "sc-1dg52pw-1"
22
- })(["flex-shrink:0;line-height:0;"]);
23
- const Token = /*#__PURE__*/forwardRef((props, forwardedRef) => {
24
- const {
25
- as,
26
- onRemove,
27
- id,
28
- leadingVisual: LeadingVisual,
29
- text,
30
- size,
31
- hideRemoveButton,
32
- href,
33
- onClick,
34
- ...rest
35
- } = props;
36
- const hasMultipleActionTargets = isTokenInteractive(props) && Boolean(onRemove) && !hideRemoveButton;
37
-
38
- const onRemoveClick = e => {
39
- e.stopPropagation();
40
- onRemove && onRemove();
41
- };
42
-
43
- const interactiveTokenProps = {
44
- as,
45
- href,
46
- onClick
47
- };
48
- return /*#__PURE__*/React.createElement(DefaultTokenStyled, _extends({
49
- onRemove: onRemove,
50
- hideRemoveButton: hideRemoveButton || !onRemove,
51
- id: id === null || id === void 0 ? void 0 : id.toString(),
52
- text: text,
53
- size: size,
54
- isTokenInteractive: isTokenInteractive(props)
55
- }, !hasMultipleActionTargets ? interactiveTokenProps : {}, rest, {
56
- 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, {
58
- borderOffset: tokenBorderWidthPx,
59
- onClick: onRemoveClick,
60
- size: size,
61
- isParentInteractive: isTokenInteractive(props),
62
- "aria-hidden": hasMultipleActionTargets ? 'true' : 'false',
63
- sx: hasMultipleActionTargets ? {
64
- position: 'relative',
65
- zIndex: '1'
66
- } : {}
67
- }) : null);
68
- });
69
- Token.displayName = 'Token';
70
- Token.defaultProps = {
71
- size: defaultTokenSize
72
- };
73
- export default Token;
@@ -1,31 +0,0 @@
1
- /// <reference types="react" />
2
- import { SxProp } from '../sx';
3
- export declare type TokenSizeKeys = 'small' | 'medium' | 'large' | 'extralarge';
4
- export declare const tokenSizes: Record<TokenSizeKeys, string>;
5
- export declare const defaultTokenSize: TokenSizeKeys;
6
- export interface TokenBaseProps extends Omit<React.HTMLProps<HTMLSpanElement | HTMLButtonElement | HTMLAnchorElement>, 'size' | 'id'> {
7
- as?: 'button' | 'a' | 'span';
8
- /**
9
- * The function that gets called when a user clicks the remove button, or keys "Backspace" or "Delete" when focused on the token
10
- */
11
- onRemove?: () => void;
12
- /**
13
- * Whether the token is selected
14
- */
15
- isSelected?: boolean;
16
- /**
17
- * The text label inside the token
18
- */
19
- text: string;
20
- /**
21
- * A unique identifier that can be associated with the token
22
- */
23
- id?: number | string;
24
- /**
25
- * Which size the token will be rendered at
26
- */
27
- size?: TokenSizeKeys;
28
- }
29
- export declare const isTokenInteractive: ({ as, onClick, onFocus, tabIndex }: TokenBaseProps) => boolean;
30
- declare const TokenBase: import("styled-components").StyledComponent<"span", any, TokenBaseProps & SxProp, never>;
31
- export default TokenBase;