@primer/components 0.0.0-2021913174146 → 0.0.0-2021913222914

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 (118) hide show
  1. package/CHANGELOG.md +1 -9
  2. package/dist/browser.esm.js +764 -869
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +770 -875
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Item.js +3 -3
  7. package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
  8. package/lib/AnchoredOverlay/AnchoredOverlay.js +3 -11
  9. package/lib/Button/Button.js +1 -1
  10. package/lib/Button/ButtonInvisible.js +1 -1
  11. package/lib/FilteredActionList/FilteredActionList.js +31 -5
  12. package/lib/Overlay.d.ts +0 -1
  13. package/lib/Overlay.js +1 -3
  14. package/lib/TextInput.d.ts +12 -4
  15. package/lib/TextInput.js +46 -4
  16. package/lib/hooks/useOpenAndCloseFocus.d.ts +1 -2
  17. package/lib/hooks/useOpenAndCloseFocus.js +2 -7
  18. package/lib/hooks/useOverlay.d.ts +1 -2
  19. package/lib/hooks/useOverlay.js +2 -4
  20. package/lib/index.d.ts +0 -5
  21. package/lib/index.js +0 -36
  22. package/lib/theme-preval.js +370 -3100
  23. package/lib/utils/testing.d.ts +50 -493
  24. package/lib/utils/types/index.d.ts +0 -1
  25. package/lib/utils/types/index.js +0 -13
  26. package/lib-esm/ActionList/Item.js +3 -3
  27. package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -2
  28. package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +3 -11
  29. package/lib-esm/Button/Button.js +1 -1
  30. package/lib-esm/Button/ButtonInvisible.js +1 -1
  31. package/lib-esm/FilteredActionList/FilteredActionList.js +31 -3
  32. package/lib-esm/Overlay.d.ts +0 -1
  33. package/lib-esm/Overlay.js +1 -3
  34. package/lib-esm/TextInput.d.ts +12 -4
  35. package/lib-esm/TextInput.js +37 -4
  36. package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +1 -2
  37. package/lib-esm/hooks/useOpenAndCloseFocus.js +2 -7
  38. package/lib-esm/hooks/useOverlay.d.ts +1 -2
  39. package/lib-esm/hooks/useOverlay.js +2 -4
  40. package/lib-esm/index.d.ts +0 -5
  41. package/lib-esm/index.js +0 -3
  42. package/lib-esm/theme-preval.js +370 -3100
  43. package/lib-esm/utils/testing.d.ts +50 -493
  44. package/lib-esm/utils/types/index.d.ts +0 -1
  45. package/lib-esm/utils/types/index.js +1 -2
  46. package/package.json +3 -4
  47. package/lib/Autocomplete/Autocomplete.d.ts +0 -304
  48. package/lib/Autocomplete/Autocomplete.js +0 -145
  49. package/lib/Autocomplete/AutocompleteContext.d.ts +0 -17
  50. package/lib/Autocomplete/AutocompleteContext.js +0 -11
  51. package/lib/Autocomplete/AutocompleteInput.d.ts +0 -292
  52. package/lib/Autocomplete/AutocompleteInput.js +0 -157
  53. package/lib/Autocomplete/AutocompleteMenu.d.ts +0 -72
  54. package/lib/Autocomplete/AutocompleteMenu.js +0 -224
  55. package/lib/Autocomplete/AutocompleteOverlay.d.ts +0 -20
  56. package/lib/Autocomplete/AutocompleteOverlay.js +0 -80
  57. package/lib/Autocomplete/index.d.ts +0 -2
  58. package/lib/Autocomplete/index.js +0 -15
  59. package/lib/TextInputWithTokens.d.ts +0 -323
  60. package/lib/TextInputWithTokens.js +0 -245
  61. package/lib/Token/AvatarToken.d.ts +0 -7
  62. package/lib/Token/AvatarToken.js +0 -64
  63. package/lib/Token/IssueLabelToken.d.ts +0 -14
  64. package/lib/Token/IssueLabelToken.js +0 -144
  65. package/lib/Token/Token.d.ts +0 -15
  66. package/lib/Token/Token.js +0 -94
  67. package/lib/Token/TokenBase.d.ts +0 -31
  68. package/lib/Token/TokenBase.js +0 -108
  69. package/lib/Token/_RemoveTokenButton.d.ts +0 -12
  70. package/lib/Token/_RemoveTokenButton.js +0 -77
  71. package/lib/Token/_TokenTextContainer.d.ts +0 -3
  72. package/lib/Token/_TokenTextContainer.js +0 -17
  73. package/lib/Token/index.d.ts +0 -3
  74. package/lib/Token/index.js +0 -31
  75. package/lib/_TextInputWrapper.d.ts +0 -10
  76. package/lib/_TextInputWrapper.js +0 -51
  77. package/lib/_UnstyledTextInput.d.ts +0 -2
  78. package/lib/_UnstyledTextInput.js +0 -20
  79. package/lib/behaviors/scrollIntoViewingArea.d.ts +0 -1
  80. package/lib/behaviors/scrollIntoViewingArea.js +0 -39
  81. package/lib/utils/types/MandateProps.d.ts +0 -3
  82. package/lib/utils/types/MandateProps.js +0 -1
  83. package/lib-esm/Autocomplete/Autocomplete.d.ts +0 -304
  84. package/lib-esm/Autocomplete/Autocomplete.js +0 -123
  85. package/lib-esm/Autocomplete/AutocompleteContext.d.ts +0 -17
  86. package/lib-esm/Autocomplete/AutocompleteContext.js +0 -2
  87. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +0 -292
  88. package/lib-esm/Autocomplete/AutocompleteInput.js +0 -138
  89. package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +0 -72
  90. package/lib-esm/Autocomplete/AutocompleteMenu.js +0 -205
  91. package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +0 -20
  92. package/lib-esm/Autocomplete/AutocompleteOverlay.js +0 -62
  93. package/lib-esm/Autocomplete/index.d.ts +0 -2
  94. package/lib-esm/Autocomplete/index.js +0 -1
  95. package/lib-esm/TextInputWithTokens.d.ts +0 -323
  96. package/lib-esm/TextInputWithTokens.js +0 -220
  97. package/lib-esm/Token/AvatarToken.d.ts +0 -7
  98. package/lib-esm/Token/AvatarToken.js +0 -43
  99. package/lib-esm/Token/IssueLabelToken.d.ts +0 -14
  100. package/lib-esm/Token/IssueLabelToken.js +0 -124
  101. package/lib-esm/Token/Token.d.ts +0 -15
  102. package/lib-esm/Token/Token.js +0 -73
  103. package/lib-esm/Token/TokenBase.d.ts +0 -31
  104. package/lib-esm/Token/TokenBase.js +0 -87
  105. package/lib-esm/Token/_RemoveTokenButton.d.ts +0 -12
  106. package/lib-esm/Token/_RemoveTokenButton.js +0 -60
  107. package/lib-esm/Token/_TokenTextContainer.d.ts +0 -3
  108. package/lib-esm/Token/_TokenTextContainer.js +0 -6
  109. package/lib-esm/Token/index.d.ts +0 -3
  110. package/lib-esm/Token/index.js +0 -3
  111. package/lib-esm/_TextInputWrapper.d.ts +0 -10
  112. package/lib-esm/_TextInputWrapper.js +0 -31
  113. package/lib-esm/_UnstyledTextInput.d.ts +0 -2
  114. package/lib-esm/_UnstyledTextInput.js +0 -7
  115. package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +0 -1
  116. package/lib-esm/behaviors/scrollIntoViewingArea.js +0 -30
  117. package/lib-esm/utils/types/MandateProps.d.ts +0 -3
  118. package/lib-esm/utils/types/MandateProps.js +0 -1
@@ -1,220 +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'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
-
14
- // using forwardRef is important so that other components (ex. Autocomplete) can use the ref
15
- function TextInputWithTokensInnerComponent({
16
- icon: IconComponent,
17
- contrast,
18
- className,
19
- block,
20
- disabled,
21
- theme,
22
- sx: sxProp,
23
- tokens,
24
- onTokenRemove,
25
- tokenComponent: TokenComponent,
26
- preventTokenWrapping,
27
- size,
28
- hideTokenRemoveButtons,
29
- maxHeight,
30
- width: widthProp,
31
- minWidth: minWidthProp,
32
- maxWidth: maxWidthProp,
33
- variant: variantProp,
34
- ...rest
35
- }, externalRef) {
36
- const {
37
- onFocus,
38
- onKeyDown,
39
- ...inputPropsRest
40
- } = omit(rest);
41
- const ref = useProvidedRefOrCreate(externalRef);
42
- const localInputRef = useRef(null);
43
- const combinedInputRef = useCombinedRefs(localInputRef, ref);
44
- const [selectedTokenIndex, setSelectedTokenIndex] = useState();
45
- const {
46
- containerRef
47
- } = useFocusZone({
48
- focusOutBehavior: 'wrap',
49
- bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
50
- focusableElementFilter: element => {
51
- return !element.getAttributeNames().includes('aria-hidden');
52
- },
53
- getNextFocusable: direction => {
54
- var _containerRef$current;
55
-
56
- if (!selectedTokenIndex && selectedTokenIndex !== 0) {
57
- return undefined;
58
- }
59
-
60
- let nextIndex = selectedTokenIndex + 1; // "+ 1" accounts for the first element: the text input
61
-
62
- if (direction === 'next') {
63
- nextIndex += 1;
64
- }
65
-
66
- if (direction === 'previous') {
67
- nextIndex -= 1;
68
- }
69
-
70
- if (nextIndex > tokens.length || nextIndex < 1) {
71
- return combinedInputRef.current || undefined;
72
- }
73
-
74
- return (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
75
- }
76
- }, [selectedTokenIndex]);
77
-
78
- const handleTokenRemove = tokenId => {
79
- onTokenRemove(tokenId);
80
-
81
- if (selectedTokenIndex) {
82
- var _containerRef$current2;
83
-
84
- const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
85
- nextElementToFocus.focus();
86
- }
87
- };
88
-
89
- const handleTokenFocus = tokenIndex => () => {
90
- setSelectedTokenIndex(tokenIndex);
91
- };
92
-
93
- const handleTokenBlur = () => {
94
- setSelectedTokenIndex(undefined);
95
- };
96
-
97
- const handleTokenKeyUp = e => {
98
- if (e.key === 'Escape') {
99
- var _ref$current;
100
-
101
- (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
102
- }
103
- };
104
-
105
- const handleInputFocus = e => {
106
- onFocus && onFocus(e);
107
- setSelectedTokenIndex(undefined);
108
- };
109
-
110
- const handleInputKeyDown = e => {
111
- var _ref$current2;
112
-
113
- if (onKeyDown) {
114
- onKeyDown(e);
115
- }
116
-
117
- if ((_ref$current2 = ref.current) !== null && _ref$current2 !== void 0 && _ref$current2.value) {
118
- return;
119
- }
120
-
121
- const lastToken = tokens[tokens.length - 1];
122
-
123
- if (e.key === 'Backspace' && lastToken) {
124
- handleTokenRemove(lastToken.id);
125
-
126
- if (ref.current) {
127
- // TODO: eliminate the first hack by making changes to the Autocomplete component
128
- //
129
- // HACKS:
130
- // 1. Directly setting `ref.current.value` instead of updating state because the autocomplete
131
- // highlight behavior doesn't work correctly if we update the value with a setState action in onChange
132
- // 2. Adding an extra space so that when I backspace, it doesn't delete the last letter
133
- ref.current.value = `${lastToken.text} `;
134
- } // HACK: for some reason we need to wait a tick for `.select()` to work
135
-
136
-
137
- setTimeout(() => {
138
- var _ref$current3;
139
-
140
- (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.select();
141
- }, 0);
142
- }
143
- };
144
-
145
- return /*#__PURE__*/React.createElement(TextInputWrapper, {
146
- block: block,
147
- className: className,
148
- contrast: contrast,
149
- disabled: disabled,
150
- hasIcon: !!IconComponent,
151
- theme: theme,
152
- width: widthProp,
153
- minWidth: minWidthProp,
154
- maxWidth: maxWidthProp,
155
- variant: variantProp,
156
- ref: containerRef,
157
- sx: {
158
- alignItems: 'center',
159
- flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
160
- gap: '0.25rem',
161
- '> *': {
162
- flexShrink: 0
163
- },
164
- ...(block ? {
165
- display: 'flex',
166
- width: '100%'
167
- } : {}),
168
- ...(maxHeight ? {
169
- maxHeight,
170
- overflow: 'auto'
171
- } : {}),
172
- ...(preventTokenWrapping ? {
173
- overflow: 'auto'
174
- } : {}),
175
- ...sxProp
176
- }
177
- }, /*#__PURE__*/React.createElement(Box, {
178
- sx: {
179
- order: 1,
180
- flexGrow: 1
181
- }
182
- }, IconComponent && /*#__PURE__*/React.createElement(IconComponent, {
183
- className: "TextInput-icon"
184
- }), /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
185
- ref: combinedInputRef,
186
- disabled: disabled,
187
- onFocus: handleInputFocus,
188
- onKeyDown: handleInputKeyDown,
189
- type: "text",
190
- sx: {
191
- height: '100%'
192
- }
193
- }, inputPropsRest))), tokens.length && TokenComponent ? tokens.map(({
194
- id,
195
- ...tokenRest
196
- }, i) => /*#__PURE__*/React.createElement(TokenComponent, _extends({
197
- key: id,
198
- onFocus: handleTokenFocus(i),
199
- onBlur: handleTokenBlur,
200
- onKeyUp: handleTokenKeyUp,
201
- isSelected: selectedTokenIndex === i,
202
- onRemove: () => {
203
- handleTokenRemove(id);
204
- },
205
- hideRemoveButton: hideTokenRemoveButtons,
206
- size: size,
207
- tabIndex: 0
208
- }, tokenRest))) : null);
209
- }
210
-
211
- TextInputWithTokensInnerComponent.displayName = "TextInputWithTokensInnerComponent";
212
- const TextInputWithTokens = /*#__PURE__*/React.forwardRef(TextInputWithTokensInnerComponent);
213
- TextInputWithTokens.defaultProps = {
214
- tokenComponent: Token,
215
- size: 'extralarge',
216
- hideTokenRemoveButtons: false,
217
- preventTokenWrapping: false
218
- };
219
- TextInputWithTokens.displayName = 'TextInputWithTokens';
220
- 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;