@primer/components 0.0.0-202195162314 → 0.0.0-202195163539
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 +1 -1
- package/dist/browser.esm.js +106 -120
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +93 -107
- package/dist/browser.umd.js.map +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +8 -2
- package/lib/TextInput.d.ts +6 -3
- package/lib/TextInput.js +9 -10
- package/lib/TextInputWithTokens.d.ts +43 -0
- package/lib/TextInputWithTokens.js +236 -0
- package/lib/Token/Token.d.ts +2 -2
- package/lib/Token/Token.js +22 -34
- package/lib/Token/TokenBase.d.ts +3 -3
- package/lib/Token/TokenBase.js +20 -36
- package/lib/Token/TokenLabel.d.ts +14 -0
- package/lib/Token/{IssueLabelToken.js → TokenLabel.js} +28 -35
- package/lib/Token/{ProfileToken.d.ts → TokenProfile.d.ts} +3 -3
- package/lib/Token/{ProfileToken.js → TokenProfile.js} +7 -7
- package/lib/Token/_RemoveTokenButton.d.ts +2 -11
- package/lib/Token/_RemoveTokenButton.js +22 -53
- package/lib/Token/_tokenButtonUtils.d.ts +10 -0
- package/lib/Token/_tokenButtonUtils.js +42 -0
- package/lib/Token/index.d.ts +2 -2
- package/lib/Token/index.js +6 -6
- package/lib/_UnstyledTextInput.d.ts +2 -0
- package/lib/_UnstyledTextInput.js +20 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +12 -4
- package/lib-esm/SelectMenu/SelectMenu.d.ts +8 -2
- package/lib-esm/TextInput.d.ts +6 -3
- package/lib-esm/TextInput.js +8 -9
- package/lib-esm/TextInputWithTokens.d.ts +43 -0
- package/lib-esm/TextInputWithTokens.js +209 -0
- package/lib-esm/Token/Token.d.ts +2 -2
- package/lib-esm/Token/Token.js +22 -33
- package/lib-esm/Token/TokenBase.d.ts +3 -3
- package/lib-esm/Token/TokenBase.js +20 -36
- package/lib-esm/Token/TokenLabel.d.ts +14 -0
- package/lib-esm/Token/{IssueLabelToken.js → TokenLabel.js} +28 -34
- package/lib-esm/Token/{ProfileToken.d.ts → TokenProfile.d.ts} +3 -3
- package/lib-esm/Token/{ProfileToken.js → TokenProfile.js} +7 -7
- package/lib-esm/Token/_RemoveTokenButton.d.ts +2 -11
- package/lib-esm/Token/_RemoveTokenButton.js +22 -52
- package/lib-esm/Token/_tokenButtonUtils.d.ts +10 -0
- package/lib-esm/Token/_tokenButtonUtils.js +26 -0
- package/lib-esm/Token/index.d.ts +2 -2
- package/lib-esm/Token/index.js +2 -2
- package/lib-esm/_UnstyledTextInput.d.ts +2 -0
- package/lib-esm/_UnstyledTextInput.js +7 -0
- package/lib-esm/index.d.ts +2 -1
- package/lib-esm/index.js +2 -1
- package/package.json +1 -1
- package/lib/Token/IssueLabelToken.d.ts +0 -14
- package/lib/Token/_TokenTextContainer.d.ts +0 -3
- package/lib/Token/_TokenTextContainer.js +0 -34
- package/lib-esm/Token/IssueLabelToken.d.ts +0 -14
- package/lib-esm/Token/_TokenTextContainer.d.ts +0 -3
- package/lib-esm/Token/_TokenTextContainer.js +0 -21
@@ -32,11 +32,15 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
|
|
32
32
|
Divider: import("styled-components").StyledComponent<"div", any, SystemCommonProps & SxProp, never>;
|
33
33
|
Filter: React.ForwardRefExoticComponent<Pick<{
|
34
34
|
value?: string | undefined;
|
35
|
-
} & Pick<{
|
35
|
+
} & Omit<Pick<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "key" | keyof React.InputHTMLAttributes<HTMLInputElement>> & {
|
36
|
+
ref?: ((instance: HTMLInputElement | null) => void) | React.RefObject<HTMLInputElement> | null | undefined;
|
37
|
+
}, string | number | symbol> & {
|
36
38
|
className?: string | undefined;
|
37
39
|
icon?: React.ComponentType<{
|
38
40
|
className?: string | undefined;
|
39
41
|
}> | undefined;
|
42
|
+
inputComponent?: React.ComponentType<HTMLInputElement> | undefined;
|
43
|
+
wrapperRef?: React.RefObject<HTMLSpanElement> | undefined;
|
40
44
|
} & Pick<{
|
41
45
|
color?: string | undefined;
|
42
46
|
maxWidth?: import("styled-system").ResponsiveValue<import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>, Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> | undefined;
|
@@ -315,7 +319,9 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
|
|
315
319
|
} & {
|
316
320
|
as?: string | React.ComponentType<any> | undefined;
|
317
321
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
318
|
-
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast"
|
322
|
+
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "theme" | "className" | "block" | "icon" | "sx" | "disabled" | "variant" | "contrast" | "inputComponent" | "wrapperRef"> & {
|
323
|
+
as?: "input" | undefined;
|
324
|
+
}, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
319
325
|
Footer: import("styled-components").StyledComponent<"footer", any, SystemCommonProps & SxProp, never>;
|
320
326
|
Item: React.ForwardRefExoticComponent<Pick<{
|
321
327
|
as?: React.ElementType<any> | undefined;
|
package/lib-esm/TextInput.d.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
|
3
|
+
import type * as Polymorphic from "@radix-ui/react-polymorphic";
|
3
4
|
import { SxProp } from './sx';
|
4
5
|
import { ComponentProps } from './utils/types';
|
5
|
-
|
6
|
+
import UnstyledTextInput from './_UnstyledTextInput';
|
6
7
|
declare const Wrapper: import("styled-components").StyledComponent<"span", any, {
|
7
8
|
disabled?: boolean | undefined;
|
8
9
|
hasIcon?: boolean | undefined;
|
@@ -15,8 +16,10 @@ declare type NonPassthroughProps = {
|
|
15
16
|
icon?: React.ComponentType<{
|
16
17
|
className?: string;
|
17
18
|
}>;
|
19
|
+
inputComponent?: React.ComponentType<HTMLInputElement>;
|
20
|
+
wrapperRef?: React.RefObject<HTMLSpanElement>;
|
18
21
|
} & Pick<ComponentProps<typeof Wrapper>, 'block' | 'contrast' | 'disabled' | 'sx' | 'theme' | 'width' | 'maxWidth' | 'minWidth' | 'variant'>;
|
19
|
-
declare type TextInputInternalProps = NonPassthroughProps & Omit<React.ComponentPropsWithoutRef<typeof
|
20
|
-
declare const TextInput:
|
22
|
+
declare type TextInputInternalProps = NonPassthroughProps & Omit<React.ComponentPropsWithoutRef<typeof UnstyledTextInput>, keyof NonPassthroughProps>;
|
23
|
+
declare const TextInput: Polymorphic.ForwardRefComponent<"input", TextInputInternalProps>;
|
21
24
|
export declare type TextInputProps = ComponentProps<typeof TextInput>;
|
22
25
|
export default TextInput;
|
package/lib-esm/TextInput.js
CHANGED
@@ -6,6 +6,7 @@ import styled, { css } from 'styled-components';
|
|
6
6
|
import { maxWidth, minWidth, variant, width } from 'styled-system';
|
7
7
|
import { get } from './constants';
|
8
8
|
import sx from './sx';
|
9
|
+
import UnstyledTextInput from './_UnstyledTextInput';
|
9
10
|
const sizeVariants = variant({
|
10
11
|
variants: {
|
11
12
|
small: {
|
@@ -22,23 +23,19 @@ const sizeVariants = variant({
|
|
22
23
|
}
|
23
24
|
}
|
24
25
|
});
|
25
|
-
const Input = styled.input.withConfig({
|
26
|
-
displayName: "TextInput__Input",
|
27
|
-
componentId: "sc-1apmpmt-0"
|
28
|
-
})(["border:0;font-size:inherit;font-family:inherit;background-color:transparent;-webkit-appearance:none;color:inherit;width:100%;&:focus{outline:0;}"]);
|
29
26
|
const Wrapper = styled.span.withConfig({
|
30
27
|
displayName: "TextInput__Wrapper",
|
31
|
-
componentId: "sc-1apmpmt-
|
28
|
+
componentId: "sc-1apmpmt-0"
|
32
29
|
})(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.fg.default'), get('colors.border.default'), get('radii.2'), get('shadows.primer.shadow.inset'), props => {
|
33
30
|
if (props.hasIcon) {
|
34
31
|
return css(["padding:0;"]);
|
35
32
|
} else {
|
36
33
|
return css(["padding:6px 12px;"]);
|
37
34
|
}
|
38
|
-
}, get('colors.fg.muted'), get('space.2'), get('colors.accent.emphasis'), get('shadows.primer.shadow.focus'), props => props.contrast && css(["background-color:", ";"], get('colors.canvas.inset')), props => props.disabled && css(["color:", ";background-color:", ";border-color:", ";"], get('colors.fg.muted'), get('colors.input.disabledBg'), get('colors.border.default')), props => props.block && css(["display:block;width:100%;"]), get('breakpoints.1'), get('fontSizes.1'), width, minWidth, maxWidth, sizeVariants, sx);
|
39
|
-
|
35
|
+
}, get('colors.fg.muted'), get('space.2'), get('colors.accent.emphasis'), get('shadows.primer.shadow.focus'), props => props.contrast && css(["background-color:", ";"], get('colors.canvas.inset')), props => props.disabled && css(["color:", ";background-color:", ";border-color:", ";"], get('colors.fg.muted'), get('colors.input.disabledBg'), get('colors.border.default')), props => props.block && css(["display:block;width:100%;"]), get('breakpoints.1'), get('fontSizes.1'), width, minWidth, maxWidth, sizeVariants, sx);
|
40
36
|
// using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input
|
41
37
|
const TextInput = /*#__PURE__*/React.forwardRef(({
|
38
|
+
inputComponent: InputComponent,
|
42
39
|
icon: IconComponent,
|
43
40
|
block,
|
44
41
|
className,
|
@@ -50,6 +47,7 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
50
47
|
minWidth: minWidthProp,
|
51
48
|
maxWidth: maxWidthProp,
|
52
49
|
variant: variantProp,
|
50
|
+
wrapperRef,
|
53
51
|
...inputProps
|
54
52
|
}, ref) => {
|
55
53
|
// this class is necessary to style FilterSearch, plz no touchy!
|
@@ -65,10 +63,11 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
65
63
|
width: widthProp,
|
66
64
|
minWidth: minWidthProp,
|
67
65
|
maxWidth: maxWidthProp,
|
68
|
-
variant: variantProp
|
66
|
+
variant: variantProp,
|
67
|
+
ref: wrapperRef
|
69
68
|
}, IconComponent && /*#__PURE__*/React.createElement(IconComponent, {
|
70
69
|
className: "TextInput-icon"
|
71
|
-
}), /*#__PURE__*/React.createElement(
|
70
|
+
}), /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
|
72
71
|
ref: ref,
|
73
72
|
disabled: disabled
|
74
73
|
}, inputProps)));
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import React, { ComponentPropsWithoutRef } from 'react';
|
2
|
+
import { ComponentProps, MandateProps } from './utils/types';
|
3
|
+
import Token, { TokenProps } from './Token/Token';
|
4
|
+
import TokenLabel, { TokenLabelProps } from './Token/TokenLabel';
|
5
|
+
import TokenProfile, { TokenProfileProps } from './Token/TokenProfile';
|
6
|
+
import { TokenSizeKeys } from './Token/TokenBase';
|
7
|
+
import { TextInputProps } from './TextInput';
|
8
|
+
declare type AnyTokenProps = Partial<TokenProps & TokenLabelProps & TokenProfileProps>;
|
9
|
+
declare type TokenDatum = MandateProps<AnyTokenProps, 'id' | 'text'>;
|
10
|
+
declare type TextInputWithTokensInternalProps = {
|
11
|
+
/**
|
12
|
+
* The array of tokens to render
|
13
|
+
*/
|
14
|
+
tokens: TokenDatum[];
|
15
|
+
/**
|
16
|
+
* The function that gets called when a token is removed
|
17
|
+
*/
|
18
|
+
onTokenRemove: (tokenId: string | number) => void;
|
19
|
+
/**
|
20
|
+
* The component used to render each token
|
21
|
+
*/
|
22
|
+
tokenComponent?: React.ComponentType<ComponentPropsWithoutRef<typeof Token> | ComponentPropsWithoutRef<typeof TokenLabel> | ComponentPropsWithoutRef<typeof TokenProfile>>;
|
23
|
+
/**
|
24
|
+
* The maximum height of the component. If the content in the input exceeds this height,
|
25
|
+
* it will scroll vertically
|
26
|
+
*/
|
27
|
+
maxHeight?: React.CSSProperties['maxHeight'];
|
28
|
+
/**
|
29
|
+
* Whether tokens should render inline horizontally. By default, tokens wrap to new lines.
|
30
|
+
*/
|
31
|
+
preventTokenWrapping?: boolean;
|
32
|
+
/**
|
33
|
+
* The size of the tokens
|
34
|
+
*/
|
35
|
+
tokenSizeVariant?: TokenSizeKeys;
|
36
|
+
/**
|
37
|
+
* Whether the remove buttons should be rendered in the tokens
|
38
|
+
*/
|
39
|
+
hideTokenRemoveButtons?: boolean;
|
40
|
+
} & TextInputProps;
|
41
|
+
declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<TextInputWithTokensInternalProps, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
42
|
+
export declare type TextInputWithTokensProps = ComponentProps<typeof TextInputWithTokens>;
|
43
|
+
export default TextInputWithTokens;
|
@@ -0,0 +1,209 @@
|
|
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 styled from 'styled-components';
|
6
|
+
import { FocusKeys } from './behaviors/focusZone';
|
7
|
+
import { useCombinedRefs } from './hooks/useCombinedRefs';
|
8
|
+
import { useFocusZone } from './hooks/useFocusZone';
|
9
|
+
import Token from './Token/Token';
|
10
|
+
import TextInput from './TextInput';
|
11
|
+
import { useProvidedRefOrCreate } from './hooks';
|
12
|
+
import UnstyledTextInput from './_UnstyledTextInput';
|
13
|
+
const InputWrapper = styled.div.withConfig({
|
14
|
+
displayName: "TextInputWithTokens__InputWrapper",
|
15
|
+
componentId: "sc-8z94t5-0"
|
16
|
+
})(["order:1;flex-grow:1;"]);
|
17
|
+
// using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
18
|
+
const TextInputWithTokensComponent = /*#__PURE__*/React.forwardRef(({
|
19
|
+
icon: IconComponent,
|
20
|
+
contrast,
|
21
|
+
className,
|
22
|
+
block,
|
23
|
+
disabled,
|
24
|
+
theme,
|
25
|
+
sx: sxProp,
|
26
|
+
tokens,
|
27
|
+
onTokenRemove,
|
28
|
+
tokenComponent: TokenComponent,
|
29
|
+
preventTokenWrapping,
|
30
|
+
tokenSizeVariant,
|
31
|
+
hideTokenRemoveButtons,
|
32
|
+
selectedTokenIdx,
|
33
|
+
setSelectedTokenIdx,
|
34
|
+
...rest
|
35
|
+
}, externalRef) => {
|
36
|
+
const ref = useProvidedRefOrCreate(externalRef);
|
37
|
+
const {
|
38
|
+
onFocus,
|
39
|
+
onKeyDown,
|
40
|
+
...inputPropsRest
|
41
|
+
} = omit(rest);
|
42
|
+
|
43
|
+
const handleTokenFocus = tokenIndex => () => {
|
44
|
+
setSelectedTokenIdx(tokenIndex);
|
45
|
+
};
|
46
|
+
|
47
|
+
const handleTokenBlur = () => {
|
48
|
+
setSelectedTokenIdx(undefined);
|
49
|
+
};
|
50
|
+
|
51
|
+
const handleTokenKeyUp = e => {
|
52
|
+
if (e.key === 'Escape') {
|
53
|
+
var _ref$current;
|
54
|
+
|
55
|
+
ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
const handleInputFocus = e => {
|
60
|
+
onFocus && onFocus(e);
|
61
|
+
setSelectedTokenIdx(undefined);
|
62
|
+
};
|
63
|
+
|
64
|
+
const handleInputKeyDown = e => {
|
65
|
+
var _ref$current2;
|
66
|
+
|
67
|
+
if (onKeyDown) {
|
68
|
+
onKeyDown(e);
|
69
|
+
}
|
70
|
+
|
71
|
+
if (ref !== null && ref !== void 0 && (_ref$current2 = ref.current) !== null && _ref$current2 !== void 0 && _ref$current2.value) {
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
|
75
|
+
const lastToken = tokens[tokens.length - 1];
|
76
|
+
|
77
|
+
if (e.key === 'Backspace' && lastToken) {
|
78
|
+
onTokenRemove(lastToken.id);
|
79
|
+
|
80
|
+
if (ref !== null && ref !== void 0 && ref.current) {
|
81
|
+
// TODO: eliminate the first hack by making changes to the Autocomplete component
|
82
|
+
//
|
83
|
+
// HACKS:
|
84
|
+
// 1. Directly setting `ref.current.value` instead of updating state because the autocomplete
|
85
|
+
// highlight behavior doesn't work correctly if we update the value with a setState action in onChange
|
86
|
+
// 2. Adding an extra space so that when I backspace, it doesn't delete the last letter
|
87
|
+
ref.current.value = `${lastToken.text} `;
|
88
|
+
} // HACK: for some reason we need to wait a tick for `.select()` to work
|
89
|
+
|
90
|
+
|
91
|
+
setTimeout(() => {
|
92
|
+
var _ref$current3;
|
93
|
+
|
94
|
+
ref === null || ref === void 0 ? void 0 : (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.select();
|
95
|
+
}, 1);
|
96
|
+
}
|
97
|
+
};
|
98
|
+
|
99
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(InputWrapper, {
|
100
|
+
key: "inputWrapper"
|
101
|
+
}, /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
|
102
|
+
ref: ref,
|
103
|
+
disabled: disabled,
|
104
|
+
onFocus: handleInputFocus,
|
105
|
+
onKeyDown: handleInputKeyDown,
|
106
|
+
type: "text",
|
107
|
+
sx: {
|
108
|
+
height: '100%'
|
109
|
+
}
|
110
|
+
}, inputPropsRest))), tokens !== null && tokens !== void 0 && tokens.length && TokenComponent ? tokens.map(({
|
111
|
+
id,
|
112
|
+
...tokenRest
|
113
|
+
}, i) => /*#__PURE__*/React.createElement(TokenComponent, _extends({
|
114
|
+
key: id,
|
115
|
+
onFocus: handleTokenFocus(i),
|
116
|
+
onBlur: handleTokenBlur,
|
117
|
+
onKeyUp: handleTokenKeyUp,
|
118
|
+
isSelected: selectedTokenIdx === i,
|
119
|
+
handleRemove: () => {
|
120
|
+
onTokenRemove(id);
|
121
|
+
},
|
122
|
+
hideRemoveButton: hideTokenRemoveButtons,
|
123
|
+
variant: tokenSizeVariant,
|
124
|
+
tabIndex: 0
|
125
|
+
}, tokenRest))) : null);
|
126
|
+
});
|
127
|
+
const TextInputWithTokens = /*#__PURE__*/React.forwardRef(({
|
128
|
+
tokens,
|
129
|
+
onTokenRemove,
|
130
|
+
sx: sxProp,
|
131
|
+
...props
|
132
|
+
}, ref) => {
|
133
|
+
const localInputRef = useRef(null);
|
134
|
+
const combinedInputRef = useCombinedRefs(localInputRef, ref);
|
135
|
+
const [selectedTokenIdx, setSelectedTokenIdx] = useState();
|
136
|
+
const {
|
137
|
+
containerRef
|
138
|
+
} = useFocusZone({
|
139
|
+
focusOutBehavior: 'wrap',
|
140
|
+
bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
|
141
|
+
focusableElementFilter: element => {
|
142
|
+
return !element.getAttributeNames().includes('aria-hidden');
|
143
|
+
},
|
144
|
+
getNextFocusable: direction => {
|
145
|
+
var _containerRef$current;
|
146
|
+
|
147
|
+
if (!selectedTokenIdx && selectedTokenIdx !== 0) {
|
148
|
+
return undefined;
|
149
|
+
}
|
150
|
+
|
151
|
+
let nextIndex = selectedTokenIdx + 1; // "+ 1" accounts for the first element: the text input
|
152
|
+
|
153
|
+
if (direction === 'next') {
|
154
|
+
nextIndex += 1;
|
155
|
+
}
|
156
|
+
|
157
|
+
if (direction === 'previous') {
|
158
|
+
nextIndex -= 1;
|
159
|
+
}
|
160
|
+
|
161
|
+
if (nextIndex > tokens.length || nextIndex < 1) {
|
162
|
+
return combinedInputRef.current || undefined;
|
163
|
+
}
|
164
|
+
|
165
|
+
return containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
|
166
|
+
}
|
167
|
+
}, [selectedTokenIdx]);
|
168
|
+
|
169
|
+
const handleTokenRemove = tokenId => {
|
170
|
+
onTokenRemove(tokenId);
|
171
|
+
|
172
|
+
if (selectedTokenIdx) {
|
173
|
+
var _containerRef$current2;
|
174
|
+
|
175
|
+
const nextElementToFocus = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIdx];
|
176
|
+
nextElementToFocus.focus();
|
177
|
+
}
|
178
|
+
};
|
179
|
+
|
180
|
+
return /*#__PURE__*/React.createElement(TextInput, _extends({
|
181
|
+
ref: combinedInputRef,
|
182
|
+
wrapperRef: containerRef,
|
183
|
+
as: TextInputWithTokensComponent,
|
184
|
+
selectedTokenIdx: selectedTokenIdx,
|
185
|
+
setSelectedTokenIdx: setSelectedTokenIdx,
|
186
|
+
tokens: tokens,
|
187
|
+
onTokenRemove: handleTokenRemove,
|
188
|
+
sx: {
|
189
|
+
'alignItems': 'center',
|
190
|
+
'flexWrap': props.preventTokenWrapping ? 'nowrap' : 'wrap',
|
191
|
+
'gap': '0.25rem',
|
192
|
+
'> *': {
|
193
|
+
'flexShrink': 0
|
194
|
+
},
|
195
|
+
...(props.block ? {
|
196
|
+
display: 'flex',
|
197
|
+
width: '100%'
|
198
|
+
} : {}),
|
199
|
+
...sxProp
|
200
|
+
}
|
201
|
+
}, props));
|
202
|
+
});
|
203
|
+
TextInputWithTokens.defaultProps = {
|
204
|
+
tokenComponent: Token,
|
205
|
+
tokenSizeVariant: "xl",
|
206
|
+
hideTokenRemoveButtons: false
|
207
|
+
};
|
208
|
+
TextInputWithTokens.displayName = 'TextInputWithTokens';
|
209
|
+
export default TextInputWithTokens;
|
package/lib-esm/Token/Token.d.ts
CHANGED
@@ -4,11 +4,11 @@ export interface TokenProps extends TokenBaseProps {
|
|
4
4
|
/**
|
5
5
|
* A function that renders a component before the token text
|
6
6
|
*/
|
7
|
-
leadingVisual?: React.
|
7
|
+
leadingVisual?: React.FunctionComponent<any>;
|
8
8
|
/**
|
9
9
|
* Whether the remove button should be rendered in the token
|
10
10
|
*/
|
11
11
|
hideRemoveButton?: boolean;
|
12
12
|
}
|
13
|
-
declare const Token: React.ForwardRefExoticComponent<Pick<TokenProps, "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" | "
|
13
|
+
declare const Token: React.ForwardRefExoticComponent<Pick<TokenProps, "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" | "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" | "variant" | "leadingVisual" | "handleRemove" | "isSelected" | "hideRemoveButton"> & React.RefAttributes<HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement>>;
|
14
14
|
export default Token;
|
package/lib-esm/Token/Token.js
CHANGED
@@ -1,68 +1,57 @@
|
|
1
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
2
|
|
3
3
|
import React, { forwardRef } from 'react';
|
4
|
-
import styled
|
4
|
+
import styled from 'styled-components';
|
5
5
|
import { get } from '../constants';
|
6
6
|
import TokenBase, { isTokenInteractive } from './TokenBase';
|
7
7
|
import RemoveTokenButton from './_RemoveTokenButton';
|
8
|
-
import TokenTextContainer from './_TokenTextContainer';
|
9
8
|
const tokenBorderWidthPx = 1;
|
10
9
|
const DefaultTokenStyled = styled(TokenBase).withConfig({
|
11
10
|
displayName: "Token__DefaultTokenStyled",
|
12
11
|
componentId: "sc-1dg52pw-0"
|
13
|
-
})(["background-color:", ";border-color:", ";border-style:solid;border-width:1px;color:", ";max-width:100%;padding-right:", ";
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
});
|
12
|
+
})(["background-color:", ";border-color:", ";border-style:solid;border-width:1px;color:", ";max-width:100%;padding-right:", ";&:hover{background-color:", ";box-shadow:", ";color:", ";}"], get('colors.neutral.subtle'), props => props.isSelected ? get('colors.fg.default') : get('colors.border.subtle'), props => props.isSelected ? get('colors.fg.default') : get('colors.fg.muted'), props => !props.hideRemoveButton ? 0 : undefined, props => isTokenInteractive(props) ? get('colors.neutral.muted') : undefined, props => isTokenInteractive(props) ? get('colors.shadow.medium') : undefined, props => isTokenInteractive(props) ? get('colors.fg.default') : undefined);
|
13
|
+
const TokenTextContainer = styled('span').withConfig({
|
14
|
+
displayName: "Token__TokenTextContainer",
|
15
|
+
componentId: "sc-1dg52pw-1"
|
16
|
+
})(["flex-grow:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"]);
|
18
17
|
const LeadingVisualContainer = styled('span').withConfig({
|
19
18
|
displayName: "Token__LeadingVisualContainer",
|
20
|
-
componentId: "sc-1dg52pw-
|
19
|
+
componentId: "sc-1dg52pw-2"
|
21
20
|
})(["flex-shrink:0;line-height:0;"]);
|
22
21
|
const Token = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
23
22
|
const {
|
24
23
|
as,
|
25
|
-
|
24
|
+
handleRemove,
|
26
25
|
id,
|
27
26
|
leadingVisual: LeadingVisual,
|
28
27
|
ref,
|
29
28
|
text,
|
30
|
-
|
29
|
+
variant,
|
31
30
|
hideRemoveButton,
|
32
|
-
href,
|
33
|
-
onClick,
|
34
31
|
...rest
|
35
32
|
} = props;
|
36
|
-
const hasMultipleActionTargets = isTokenInteractive(props) && Boolean(
|
33
|
+
const hasMultipleActionTargets = isTokenInteractive(props) && Boolean(handleRemove) && !hideRemoveButton;
|
37
34
|
|
38
|
-
const
|
35
|
+
const handleRemoveClick = e => {
|
39
36
|
e.stopPropagation();
|
40
|
-
|
37
|
+
handleRemove && handleRemove();
|
41
38
|
};
|
42
39
|
|
43
|
-
const interactiveTokenProps = {
|
44
|
-
as,
|
45
|
-
href,
|
46
|
-
onClick
|
47
|
-
};
|
48
40
|
return /*#__PURE__*/React.createElement(DefaultTokenStyled, _extends({
|
49
|
-
|
50
|
-
|
41
|
+
as: as,
|
42
|
+
handleRemove: handleRemove,
|
43
|
+
hideRemoveButton: hideRemoveButton || !handleRemove,
|
51
44
|
id: id === null || id === void 0 ? void 0 : id.toString(),
|
52
45
|
text: text,
|
53
46
|
ref: forwardedRef,
|
54
|
-
|
55
|
-
|
56
|
-
}, !hasMultipleActionTargets ? interactiveTokenProps : {}, rest), 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, {
|
47
|
+
variant: variant
|
48
|
+
}, rest), LeadingVisual ? /*#__PURE__*/React.createElement(LeadingVisualContainer, null, /*#__PURE__*/React.createElement(LeadingVisual, null)) : null, /*#__PURE__*/React.createElement(TokenTextContainer, null, text), !hideRemoveButton && handleRemove ? /*#__PURE__*/React.createElement(RemoveTokenButton, {
|
57
49
|
borderOffset: tokenBorderWidthPx,
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
position: 'relative',
|
64
|
-
zIndex: '1'
|
65
|
-
} : {}
|
50
|
+
parentTokenTag: as || 'span',
|
51
|
+
onClick: handleRemoveClick,
|
52
|
+
variant: variant,
|
53
|
+
parentTokenIsInteractive: isTokenInteractive(props),
|
54
|
+
"aria-hidden": hasMultipleActionTargets ? "true" : "false"
|
66
55
|
}) : null);
|
67
56
|
});
|
68
57
|
export default Token;
|
@@ -1,15 +1,15 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
export declare type TokenSizeKeys = 'sm' | 'md' | 'lg' | 'xl';
|
3
|
-
export declare const tokenSizes: Record<TokenSizeKeys,
|
3
|
+
export declare const tokenSizes: Record<TokenSizeKeys, number>;
|
4
4
|
export declare const defaultTokenSize = "md";
|
5
5
|
export interface TokenBaseProps extends Omit<React.HTMLProps<HTMLSpanElement | HTMLButtonElement | HTMLAnchorElement>, 'size' | 'id'> {
|
6
6
|
as?: 'button' | 'a' | 'span';
|
7
|
-
|
7
|
+
handleRemove?: () => void;
|
8
8
|
isSelected?: boolean;
|
9
9
|
tabIndex?: number;
|
10
10
|
text: string;
|
11
11
|
id?: number | string;
|
12
|
-
|
12
|
+
variant?: TokenSizeKeys;
|
13
13
|
}
|
14
14
|
export declare const isTokenInteractive: ({ as, onClick, onFocus, tabIndex }: TokenBaseProps) => boolean;
|
15
15
|
declare const TokenBase: import("styled-components").StyledComponent<"span", any, TokenBaseProps, never>;
|
@@ -2,10 +2,10 @@ import styled from 'styled-components';
|
|
2
2
|
import { variant } from 'styled-system';
|
3
3
|
import { get } from '../constants';
|
4
4
|
export const tokenSizes = {
|
5
|
-
sm:
|
6
|
-
md:
|
7
|
-
lg:
|
8
|
-
xl:
|
5
|
+
sm: 16,
|
6
|
+
md: 20,
|
7
|
+
lg: 24,
|
8
|
+
xl: 32
|
9
9
|
};
|
10
10
|
export const defaultTokenSize = 'md';
|
11
11
|
export const isTokenInteractive = ({
|
@@ -15,72 +15,56 @@ export const isTokenInteractive = ({
|
|
15
15
|
tabIndex = -1
|
16
16
|
}) => Boolean(onFocus || onClick || tabIndex > -1 || ['a', 'button'].includes(as));
|
17
17
|
const variants = variant({
|
18
|
-
prop: 'size',
|
19
18
|
variants: {
|
20
19
|
sm: {
|
21
20
|
fontSize: 0,
|
22
21
|
gap: 1,
|
23
|
-
height: tokenSizes.sm
|
24
|
-
// without setting lineHeight to match height, the "x" appears vertically mis-aligned
|
25
|
-
lineHeight: tokenSizes.sm,
|
22
|
+
height: `${tokenSizes.sm}px`,
|
26
23
|
paddingLeft: 1,
|
27
|
-
paddingRight: 1
|
28
|
-
// need to explicitly set padding top and bottom to "0" to override default `<button>` element styles
|
29
|
-
// without setting these, the "x" appears vertically mis-aligned
|
30
|
-
paddingTop: 0,
|
31
|
-
paddingBottom: 0
|
24
|
+
paddingRight: 1
|
32
25
|
},
|
33
26
|
md: {
|
34
27
|
fontSize: 0,
|
35
28
|
gap: 1,
|
36
|
-
height: tokenSizes.md
|
37
|
-
lineHeight: tokenSizes.md,
|
29
|
+
height: `${tokenSizes.md}px`,
|
38
30
|
paddingLeft: 2,
|
39
|
-
paddingRight: 2
|
40
|
-
paddingTop: 0,
|
41
|
-
paddingBottom: 0
|
31
|
+
paddingRight: 2
|
42
32
|
},
|
43
33
|
lg: {
|
44
34
|
fontSize: 0,
|
45
35
|
gap: 2,
|
46
|
-
height: tokenSizes.lg
|
47
|
-
lineHeight: tokenSizes.lg,
|
36
|
+
height: `${tokenSizes.lg}px`,
|
48
37
|
paddingLeft: 2,
|
49
|
-
paddingRight: 2
|
50
|
-
paddingTop: 0,
|
51
|
-
paddingBottom: 0
|
38
|
+
paddingRight: 2
|
52
39
|
},
|
53
40
|
xl: {
|
54
41
|
fontSize: 1,
|
55
42
|
gap: 2,
|
56
|
-
height: tokenSizes.xl
|
57
|
-
lineHeight: tokenSizes.xl,
|
43
|
+
height: `${tokenSizes.xl}px`,
|
58
44
|
paddingLeft: 3,
|
59
|
-
paddingRight: 3
|
60
|
-
paddingTop: 0,
|
61
|
-
paddingBottom: 0
|
45
|
+
paddingRight: 3
|
62
46
|
}
|
63
47
|
}
|
64
48
|
});
|
65
49
|
const TokenBase = styled.span.attrs(({
|
66
50
|
text,
|
67
|
-
|
68
|
-
|
51
|
+
handleRemove,
|
52
|
+
onKeyUp
|
69
53
|
}) => ({
|
70
|
-
|
71
|
-
|
54
|
+
onKeyUp: e => {
|
55
|
+
onKeyUp && onKeyUp(e);
|
72
56
|
|
73
|
-
if ((
|
74
|
-
|
57
|
+
if ((e.key === 'Backspace' || e.key === 'Delete') && handleRemove) {
|
58
|
+
handleRemove();
|
75
59
|
}
|
76
60
|
},
|
77
|
-
'aria-label':
|
61
|
+
'aria-label': handleRemove ? `${text}, press backspace or delete to remove` : undefined
|
78
62
|
})).withConfig({
|
79
63
|
displayName: "TokenBase",
|
80
64
|
componentId: "opajvp-0"
|
81
65
|
})(["align-items:center;border-radius:999px;cursor:", ";display:inline-flex;font-weight:", ";text-decoration:none;white-space:nowrap;", ""], props => isTokenInteractive(props) ? 'pointer' : 'auto', get('fontWeights.bold'), variants);
|
82
66
|
TokenBase.defaultProps = {
|
83
67
|
as: 'span',
|
84
|
-
|
68
|
+
variant: defaultTokenSize
|
85
69
|
};
|
86
70
|
export default TokenBase;
|