@primer/components 0.0.0-20219151326 → 0.0.0-2021915134443
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -3
- package/codemods/deprecateUtilityComponents.js +1 -1
- package/dist/browser.esm.js +872 -767
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +877 -772
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +1 -1
- package/lib/ActionList/List.d.ts +2 -1
- package/lib/ActionList2/Item.d.ts +1 -0
- package/lib/ActionList2/Item.js +2 -2
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +2 -1
- package/lib/AnchoredOverlay/AnchoredOverlay.js +11 -3
- package/lib/Autocomplete/Autocomplete.d.ts +304 -0
- package/lib/Autocomplete/Autocomplete.js +145 -0
- package/lib/Autocomplete/AutocompleteContext.d.ts +17 -0
- package/lib/Autocomplete/AutocompleteContext.js +11 -0
- package/lib/Autocomplete/AutocompleteInput.d.ts +292 -0
- package/lib/Autocomplete/AutocompleteInput.js +157 -0
- package/lib/Autocomplete/AutocompleteMenu.d.ts +72 -0
- package/lib/Autocomplete/AutocompleteMenu.js +224 -0
- package/lib/Autocomplete/AutocompleteOverlay.d.ts +20 -0
- package/lib/Autocomplete/AutocompleteOverlay.js +80 -0
- package/lib/Autocomplete/index.d.ts +2 -0
- package/lib/Autocomplete/index.js +15 -0
- package/lib/BaseStyles.js +1 -1
- package/lib/BorderBox.js +1 -1
- package/lib/Caret.js +2 -2
- package/lib/Dialog.js +1 -1
- package/lib/FilteredActionList/FilteredActionList.d.ts +3 -2
- package/lib/FilteredActionList/FilteredActionList.js +8 -32
- package/lib/Flash.js +16 -16
- package/lib/Label.js +1 -1
- package/lib/Overlay.d.ts +1 -0
- package/lib/Overlay.js +3 -1
- package/lib/ProgressBar.js +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +10 -10
- package/lib/SelectPanel/SelectPanel.d.ts +1 -1
- package/lib/SelectPanel/SelectPanel.js +9 -11
- package/lib/StateLabel.js +13 -19
- package/lib/TextInput.d.ts +5 -13
- package/lib/TextInput.js +4 -46
- package/lib/TextInputWithTokens.d.ts +323 -0
- package/lib/TextInputWithTokens.js +245 -0
- package/lib/Token/AvatarToken.d.ts +7 -0
- package/lib/Token/AvatarToken.js +64 -0
- package/lib/Token/IssueLabelToken.d.ts +14 -0
- package/lib/Token/IssueLabelToken.js +144 -0
- package/lib/Token/Token.d.ts +15 -0
- package/lib/Token/Token.js +94 -0
- package/lib/Token/TokenBase.d.ts +31 -0
- package/lib/Token/TokenBase.js +108 -0
- package/lib/Token/_RemoveTokenButton.d.ts +12 -0
- package/lib/Token/_RemoveTokenButton.js +77 -0
- package/lib/Token/_TokenTextContainer.d.ts +3 -0
- package/lib/Token/_TokenTextContainer.js +17 -0
- package/lib/Token/index.d.ts +3 -0
- package/lib/Token/index.js +31 -0
- package/lib/_TextInputWrapper.d.ts +10 -0
- package/lib/_TextInputWrapper.js +51 -0
- package/lib/_UnstyledTextInput.d.ts +2 -0
- package/lib/_UnstyledTextInput.js +20 -0
- package/lib/behaviors/scrollIntoViewingArea.d.ts +1 -0
- package/lib/behaviors/scrollIntoViewingArea.js +39 -0
- package/lib/hooks/useOpenAndCloseFocus.d.ts +2 -1
- package/lib/hooks/useOpenAndCloseFocus.js +7 -2
- package/lib/hooks/useOverlay.d.ts +2 -1
- package/lib/hooks/useOverlay.js +4 -2
- package/lib/index.d.ts +6 -0
- package/lib/index.js +44 -0
- package/lib/theme-preval.js +370 -3100
- package/lib/utils/testing.d.ts +50 -493
- package/lib/utils/{types.d.ts → types/AriaRole.d.ts} +0 -13
- package/lib/utils/{types.js → types/AriaRole.js} +0 -0
- package/lib/utils/types/ComponentProps.d.ts +9 -0
- package/lib/utils/types/ComponentProps.js +1 -0
- package/lib/utils/types/Flatten.d.ts +4 -0
- package/lib/utils/types/Flatten.js +1 -0
- package/lib/utils/types/MandateProps.d.ts +3 -0
- package/lib/utils/types/MandateProps.js +1 -0
- package/lib/utils/types/Merge.d.ts +19 -0
- package/lib/utils/types/Merge.js +1 -0
- package/lib/utils/types/index.d.ts +5 -0
- package/lib/utils/types/index.js +70 -0
- package/lib-esm/ActionList/Item.js +1 -1
- package/lib-esm/ActionList/List.d.ts +2 -1
- package/lib-esm/ActionList2/Item.d.ts +1 -0
- package/lib-esm/ActionList2/Item.js +3 -2
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +2 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +11 -3
- package/lib-esm/Autocomplete/Autocomplete.d.ts +304 -0
- package/lib-esm/Autocomplete/Autocomplete.js +123 -0
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +17 -0
- package/lib-esm/Autocomplete/AutocompleteContext.js +2 -0
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +292 -0
- package/lib-esm/Autocomplete/AutocompleteInput.js +138 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +72 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.js +205 -0
- package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +20 -0
- package/lib-esm/Autocomplete/AutocompleteOverlay.js +62 -0
- package/lib-esm/Autocomplete/index.d.ts +2 -0
- package/lib-esm/Autocomplete/index.js +1 -0
- package/lib-esm/BaseStyles.js +1 -1
- package/lib-esm/BorderBox.js +1 -1
- package/lib-esm/Caret.js +2 -2
- package/lib-esm/Dialog.js +1 -1
- package/lib-esm/FilteredActionList/FilteredActionList.d.ts +3 -2
- package/lib-esm/FilteredActionList/FilteredActionList.js +6 -32
- package/lib-esm/Flash.js +16 -16
- package/lib-esm/Label.js +1 -1
- package/lib-esm/Overlay.d.ts +1 -0
- package/lib-esm/Overlay.js +3 -1
- package/lib-esm/ProgressBar.js +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +10 -10
- package/lib-esm/SelectPanel/SelectPanel.d.ts +1 -1
- package/lib-esm/SelectPanel/SelectPanel.js +9 -8
- package/lib-esm/StateLabel.js +13 -19
- package/lib-esm/TextInput.d.ts +5 -13
- package/lib-esm/TextInput.js +4 -37
- package/lib-esm/TextInputWithTokens.d.ts +323 -0
- package/lib-esm/TextInputWithTokens.js +220 -0
- package/lib-esm/Token/AvatarToken.d.ts +7 -0
- package/lib-esm/Token/AvatarToken.js +43 -0
- package/lib-esm/Token/IssueLabelToken.d.ts +14 -0
- package/lib-esm/Token/IssueLabelToken.js +124 -0
- package/lib-esm/Token/Token.d.ts +15 -0
- package/lib-esm/Token/Token.js +73 -0
- package/lib-esm/Token/TokenBase.d.ts +31 -0
- package/lib-esm/Token/TokenBase.js +87 -0
- package/lib-esm/Token/_RemoveTokenButton.d.ts +12 -0
- package/lib-esm/Token/_RemoveTokenButton.js +60 -0
- package/lib-esm/Token/_TokenTextContainer.d.ts +3 -0
- package/lib-esm/Token/_TokenTextContainer.js +6 -0
- package/lib-esm/Token/index.d.ts +3 -0
- package/lib-esm/Token/index.js +3 -0
- package/lib-esm/_TextInputWrapper.d.ts +10 -0
- package/lib-esm/_TextInputWrapper.js +31 -0
- package/lib-esm/_UnstyledTextInput.d.ts +2 -0
- package/lib-esm/_UnstyledTextInput.js +7 -0
- package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +1 -0
- package/lib-esm/behaviors/scrollIntoViewingArea.js +30 -0
- package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +2 -1
- package/lib-esm/hooks/useOpenAndCloseFocus.js +7 -2
- package/lib-esm/hooks/useOverlay.d.ts +2 -1
- package/lib-esm/hooks/useOverlay.js +4 -2
- package/lib-esm/index.d.ts +6 -0
- package/lib-esm/index.js +4 -0
- package/lib-esm/theme-preval.js +370 -3100
- package/lib-esm/utils/testing.d.ts +50 -493
- package/lib-esm/utils/{types.d.ts → types/AriaRole.d.ts} +0 -13
- package/lib-esm/utils/{types.js → types/AriaRole.js} +0 -0
- package/lib-esm/utils/types/ComponentProps.d.ts +9 -0
- package/lib-esm/utils/types/ComponentProps.js +1 -0
- package/lib-esm/utils/types/Flatten.d.ts +4 -0
- package/lib-esm/utils/types/Flatten.js +1 -0
- package/lib-esm/utils/types/MandateProps.d.ts +3 -0
- package/lib-esm/utils/types/MandateProps.js +1 -0
- package/lib-esm/utils/types/Merge.d.ts +19 -0
- package/lib-esm/utils/types/Merge.js +1 -0
- package/lib-esm/utils/types/index.d.ts +5 -0
- package/lib-esm/utils/types/index.js +5 -0
- package/package.json +4 -3
@@ -0,0 +1,220 @@
|
|
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;
|
@@ -0,0 +1,7 @@
|
|
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;
|
@@ -0,0 +1,43 @@
|
|
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;
|
@@ -0,0 +1,14 @@
|
|
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;
|
@@ -0,0 +1,124 @@
|
|
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;
|
@@ -0,0 +1,15 @@
|
|
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;
|
@@ -0,0 +1,73 @@
|
|
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;
|
@@ -0,0 +1,31 @@
|
|
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;
|