@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/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/TextInput.js
CHANGED
@@ -17,6 +17,8 @@ var _constants = require("./constants");
|
|
17
17
|
|
18
18
|
var _sx = _interopRequireDefault(require("./sx"));
|
19
19
|
|
20
|
+
var _UnstyledTextInput = _interopRequireDefault(require("./_UnstyledTextInput"));
|
21
|
+
|
20
22
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
21
23
|
|
22
24
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -42,25 +44,20 @@ const sizeVariants = (0, _styledSystem.variant)({
|
|
42
44
|
}
|
43
45
|
});
|
44
46
|
|
45
|
-
const Input = _styledComponents.default.input.withConfig({
|
46
|
-
displayName: "TextInput__Input",
|
47
|
-
componentId: "sc-1apmpmt-0"
|
48
|
-
})(["border:0;font-size:inherit;font-family:inherit;background-color:transparent;-webkit-appearance:none;color:inherit;width:100%;&:focus{outline:0;}"]);
|
49
|
-
|
50
47
|
const Wrapper = _styledComponents.default.span.withConfig({
|
51
48
|
displayName: "TextInput__Wrapper",
|
52
|
-
componentId: "sc-1apmpmt-
|
49
|
+
componentId: "sc-1apmpmt-0"
|
53
50
|
})(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('colors.fg.default'), (0, _constants.get)('colors.border.default'), (0, _constants.get)('radii.2'), (0, _constants.get)('shadows.primer.shadow.inset'), props => {
|
54
51
|
if (props.hasIcon) {
|
55
52
|
return (0, _styledComponents.css)(["padding:0;"]);
|
56
53
|
} else {
|
57
54
|
return (0, _styledComponents.css)(["padding:6px 12px;"]);
|
58
55
|
}
|
59
|
-
}, (0, _constants.get)('colors.fg.muted'), (0, _constants.get)('space.2'), (0, _constants.get)('colors.accent.emphasis'), (0, _constants.get)('shadows.primer.shadow.focus'), props => props.contrast && (0, _styledComponents.css)(["background-color:", ";"], (0, _constants.get)('colors.canvas.inset')), props => props.disabled && (0, _styledComponents.css)(["color:", ";background-color:", ";border-color:", ";"], (0, _constants.get)('colors.fg.muted'), (0, _constants.get)('colors.input.disabledBg'), (0, _constants.get)('colors.border.default')), props => props.block && (0, _styledComponents.css)(["display:block;width:100%;"]), (0, _constants.get)('breakpoints.1'), (0, _constants.get)('fontSizes.1'), _styledSystem.width, _styledSystem.minWidth, _styledSystem.maxWidth, sizeVariants, _sx.default);
|
60
|
-
|
56
|
+
}, (0, _constants.get)('colors.fg.muted'), (0, _constants.get)('space.2'), (0, _constants.get)('colors.accent.emphasis'), (0, _constants.get)('shadows.primer.shadow.focus'), props => props.contrast && (0, _styledComponents.css)(["background-color:", ";"], (0, _constants.get)('colors.canvas.inset')), props => props.disabled && (0, _styledComponents.css)(["color:", ";background-color:", ";border-color:", ";"], (0, _constants.get)('colors.fg.muted'), (0, _constants.get)('colors.input.disabledBg'), (0, _constants.get)('colors.border.default')), props => props.block && (0, _styledComponents.css)(["display:block;width:100%;"]), (0, _constants.get)('breakpoints.1'), (0, _constants.get)('fontSizes.1'), _styledSystem.width, _styledSystem.minWidth, _styledSystem.maxWidth, sizeVariants, _sx.default);
|
61
57
|
|
62
58
|
// using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input
|
63
59
|
const TextInput = /*#__PURE__*/_react.default.forwardRef(({
|
60
|
+
inputComponent: InputComponent,
|
64
61
|
icon: IconComponent,
|
65
62
|
block,
|
66
63
|
className,
|
@@ -72,6 +69,7 @@ const TextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
72
69
|
minWidth: minWidthProp,
|
73
70
|
maxWidth: maxWidthProp,
|
74
71
|
variant: variantProp,
|
72
|
+
wrapperRef,
|
75
73
|
...inputProps
|
76
74
|
}, ref) => {
|
77
75
|
// this class is necessary to style FilterSearch, plz no touchy!
|
@@ -87,10 +85,11 @@ const TextInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
87
85
|
width: widthProp,
|
88
86
|
minWidth: minWidthProp,
|
89
87
|
maxWidth: maxWidthProp,
|
90
|
-
variant: variantProp
|
88
|
+
variant: variantProp,
|
89
|
+
ref: wrapperRef
|
91
90
|
}, IconComponent && /*#__PURE__*/_react.default.createElement(IconComponent, {
|
92
91
|
className: "TextInput-icon"
|
93
|
-
}), /*#__PURE__*/_react.default.createElement(
|
92
|
+
}), /*#__PURE__*/_react.default.createElement(_UnstyledTextInput.default, _extends({
|
94
93
|
ref: ref,
|
95
94
|
disabled: disabled
|
96
95
|
}, 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,236 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
|
+
|
10
|
+
var _props = require("@styled-system/props");
|
11
|
+
|
12
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
13
|
+
|
14
|
+
var _focusZone = require("./behaviors/focusZone");
|
15
|
+
|
16
|
+
var _useCombinedRefs = require("./hooks/useCombinedRefs");
|
17
|
+
|
18
|
+
var _useFocusZone = require("./hooks/useFocusZone");
|
19
|
+
|
20
|
+
var _Token = _interopRequireDefault(require("./Token/Token"));
|
21
|
+
|
22
|
+
var _TextInput = _interopRequireDefault(require("./TextInput"));
|
23
|
+
|
24
|
+
var _hooks = require("./hooks");
|
25
|
+
|
26
|
+
var _UnstyledTextInput = _interopRequireDefault(require("./_UnstyledTextInput"));
|
27
|
+
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
29
|
+
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
31
|
+
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
33
|
+
|
34
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
35
|
+
|
36
|
+
const InputWrapper = _styledComponents.default.div.withConfig({
|
37
|
+
displayName: "TextInputWithTokens__InputWrapper",
|
38
|
+
componentId: "sc-8z94t5-0"
|
39
|
+
})(["order:1;flex-grow:1;"]);
|
40
|
+
|
41
|
+
// using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
42
|
+
const TextInputWithTokensComponent = /*#__PURE__*/_react.default.forwardRef(({
|
43
|
+
icon: IconComponent,
|
44
|
+
contrast,
|
45
|
+
className,
|
46
|
+
block,
|
47
|
+
disabled,
|
48
|
+
theme,
|
49
|
+
sx: sxProp,
|
50
|
+
tokens,
|
51
|
+
onTokenRemove,
|
52
|
+
tokenComponent: TokenComponent,
|
53
|
+
preventTokenWrapping,
|
54
|
+
tokenSizeVariant,
|
55
|
+
hideTokenRemoveButtons,
|
56
|
+
selectedTokenIdx,
|
57
|
+
setSelectedTokenIdx,
|
58
|
+
...rest
|
59
|
+
}, externalRef) => {
|
60
|
+
const ref = (0, _hooks.useProvidedRefOrCreate)(externalRef);
|
61
|
+
const {
|
62
|
+
onFocus,
|
63
|
+
onKeyDown,
|
64
|
+
...inputPropsRest
|
65
|
+
} = (0, _props.omit)(rest);
|
66
|
+
|
67
|
+
const handleTokenFocus = tokenIndex => () => {
|
68
|
+
setSelectedTokenIdx(tokenIndex);
|
69
|
+
};
|
70
|
+
|
71
|
+
const handleTokenBlur = () => {
|
72
|
+
setSelectedTokenIdx(undefined);
|
73
|
+
};
|
74
|
+
|
75
|
+
const handleTokenKeyUp = e => {
|
76
|
+
if (e.key === 'Escape') {
|
77
|
+
var _ref$current;
|
78
|
+
|
79
|
+
ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
80
|
+
}
|
81
|
+
};
|
82
|
+
|
83
|
+
const handleInputFocus = e => {
|
84
|
+
onFocus && onFocus(e);
|
85
|
+
setSelectedTokenIdx(undefined);
|
86
|
+
};
|
87
|
+
|
88
|
+
const handleInputKeyDown = e => {
|
89
|
+
var _ref$current2;
|
90
|
+
|
91
|
+
if (onKeyDown) {
|
92
|
+
onKeyDown(e);
|
93
|
+
}
|
94
|
+
|
95
|
+
if (ref !== null && ref !== void 0 && (_ref$current2 = ref.current) !== null && _ref$current2 !== void 0 && _ref$current2.value) {
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
|
99
|
+
const lastToken = tokens[tokens.length - 1];
|
100
|
+
|
101
|
+
if (e.key === 'Backspace' && lastToken) {
|
102
|
+
onTokenRemove(lastToken.id);
|
103
|
+
|
104
|
+
if (ref !== null && ref !== void 0 && ref.current) {
|
105
|
+
// TODO: eliminate the first hack by making changes to the Autocomplete component
|
106
|
+
//
|
107
|
+
// HACKS:
|
108
|
+
// 1. Directly setting `ref.current.value` instead of updating state because the autocomplete
|
109
|
+
// highlight behavior doesn't work correctly if we update the value with a setState action in onChange
|
110
|
+
// 2. Adding an extra space so that when I backspace, it doesn't delete the last letter
|
111
|
+
ref.current.value = `${lastToken.text} `;
|
112
|
+
} // HACK: for some reason we need to wait a tick for `.select()` to work
|
113
|
+
|
114
|
+
|
115
|
+
setTimeout(() => {
|
116
|
+
var _ref$current3;
|
117
|
+
|
118
|
+
ref === null || ref === void 0 ? void 0 : (_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.select();
|
119
|
+
}, 1);
|
120
|
+
}
|
121
|
+
};
|
122
|
+
|
123
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(InputWrapper, {
|
124
|
+
key: "inputWrapper"
|
125
|
+
}, /*#__PURE__*/_react.default.createElement(_UnstyledTextInput.default, _extends({
|
126
|
+
ref: ref,
|
127
|
+
disabled: disabled,
|
128
|
+
onFocus: handleInputFocus,
|
129
|
+
onKeyDown: handleInputKeyDown,
|
130
|
+
type: "text",
|
131
|
+
sx: {
|
132
|
+
height: '100%'
|
133
|
+
}
|
134
|
+
}, inputPropsRest))), tokens !== null && tokens !== void 0 && tokens.length && TokenComponent ? tokens.map(({
|
135
|
+
id,
|
136
|
+
...tokenRest
|
137
|
+
}, i) => /*#__PURE__*/_react.default.createElement(TokenComponent, _extends({
|
138
|
+
key: id,
|
139
|
+
onFocus: handleTokenFocus(i),
|
140
|
+
onBlur: handleTokenBlur,
|
141
|
+
onKeyUp: handleTokenKeyUp,
|
142
|
+
isSelected: selectedTokenIdx === i,
|
143
|
+
handleRemove: () => {
|
144
|
+
onTokenRemove(id);
|
145
|
+
},
|
146
|
+
hideRemoveButton: hideTokenRemoveButtons,
|
147
|
+
variant: tokenSizeVariant,
|
148
|
+
tabIndex: 0
|
149
|
+
}, tokenRest))) : null);
|
150
|
+
});
|
151
|
+
|
152
|
+
const TextInputWithTokens = /*#__PURE__*/_react.default.forwardRef(({
|
153
|
+
tokens,
|
154
|
+
onTokenRemove,
|
155
|
+
sx: sxProp,
|
156
|
+
...props
|
157
|
+
}, ref) => {
|
158
|
+
const localInputRef = (0, _react.useRef)(null);
|
159
|
+
const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(localInputRef, ref);
|
160
|
+
const [selectedTokenIdx, setSelectedTokenIdx] = (0, _react.useState)();
|
161
|
+
const {
|
162
|
+
containerRef
|
163
|
+
} = (0, _useFocusZone.useFocusZone)({
|
164
|
+
focusOutBehavior: 'wrap',
|
165
|
+
bindKeys: _focusZone.FocusKeys.ArrowHorizontal | _focusZone.FocusKeys.HomeAndEnd,
|
166
|
+
focusableElementFilter: element => {
|
167
|
+
return !element.getAttributeNames().includes('aria-hidden');
|
168
|
+
},
|
169
|
+
getNextFocusable: direction => {
|
170
|
+
var _containerRef$current;
|
171
|
+
|
172
|
+
if (!selectedTokenIdx && selectedTokenIdx !== 0) {
|
173
|
+
return undefined;
|
174
|
+
}
|
175
|
+
|
176
|
+
let nextIndex = selectedTokenIdx + 1; // "+ 1" accounts for the first element: the text input
|
177
|
+
|
178
|
+
if (direction === 'next') {
|
179
|
+
nextIndex += 1;
|
180
|
+
}
|
181
|
+
|
182
|
+
if (direction === 'previous') {
|
183
|
+
nextIndex -= 1;
|
184
|
+
}
|
185
|
+
|
186
|
+
if (nextIndex > tokens.length || nextIndex < 1) {
|
187
|
+
return combinedInputRef.current || undefined;
|
188
|
+
}
|
189
|
+
|
190
|
+
return containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
|
191
|
+
}
|
192
|
+
}, [selectedTokenIdx]);
|
193
|
+
|
194
|
+
const handleTokenRemove = tokenId => {
|
195
|
+
onTokenRemove(tokenId);
|
196
|
+
|
197
|
+
if (selectedTokenIdx) {
|
198
|
+
var _containerRef$current2;
|
199
|
+
|
200
|
+
const nextElementToFocus = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIdx];
|
201
|
+
nextElementToFocus.focus();
|
202
|
+
}
|
203
|
+
};
|
204
|
+
|
205
|
+
return /*#__PURE__*/_react.default.createElement(_TextInput.default, _extends({
|
206
|
+
ref: combinedInputRef,
|
207
|
+
wrapperRef: containerRef,
|
208
|
+
as: TextInputWithTokensComponent,
|
209
|
+
selectedTokenIdx: selectedTokenIdx,
|
210
|
+
setSelectedTokenIdx: setSelectedTokenIdx,
|
211
|
+
tokens: tokens,
|
212
|
+
onTokenRemove: handleTokenRemove,
|
213
|
+
sx: {
|
214
|
+
'alignItems': 'center',
|
215
|
+
'flexWrap': props.preventTokenWrapping ? 'nowrap' : 'wrap',
|
216
|
+
'gap': '0.25rem',
|
217
|
+
'> *': {
|
218
|
+
'flexShrink': 0
|
219
|
+
},
|
220
|
+
...(props.block ? {
|
221
|
+
display: 'flex',
|
222
|
+
width: '100%'
|
223
|
+
} : {}),
|
224
|
+
...sxProp
|
225
|
+
}
|
226
|
+
}, props));
|
227
|
+
});
|
228
|
+
|
229
|
+
TextInputWithTokens.defaultProps = {
|
230
|
+
tokenComponent: _Token.default,
|
231
|
+
tokenSizeVariant: "xl",
|
232
|
+
hideTokenRemoveButtons: false
|
233
|
+
};
|
234
|
+
TextInputWithTokens.displayName = 'TextInputWithTokens';
|
235
|
+
var _default = TextInputWithTokens;
|
236
|
+
exports.default = _default;
|
package/lib/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/Token/Token.js
CHANGED
@@ -7,7 +7,7 @@ exports.default = void 0;
|
|
7
7
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
9
9
|
|
10
|
-
var _styledComponents =
|
10
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
11
11
|
|
12
12
|
var _constants = require("../constants");
|
13
13
|
|
@@ -15,8 +15,6 @@ var _TokenBase = _interopRequireWildcard(require("./TokenBase"));
|
|
15
15
|
|
16
16
|
var _RemoveTokenButton = _interopRequireDefault(require("./_RemoveTokenButton"));
|
17
17
|
|
18
|
-
var _TokenTextContainer = _interopRequireDefault(require("./_TokenTextContainer"));
|
19
|
-
|
20
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
19
|
|
22
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
@@ -29,59 +27,49 @@ const tokenBorderWidthPx = 1;
|
|
29
27
|
const DefaultTokenStyled = (0, _styledComponents.default)(_TokenBase.default).withConfig({
|
30
28
|
displayName: "Token__DefaultTokenStyled",
|
31
29
|
componentId: "sc-1dg52pw-0"
|
32
|
-
})(["background-color:", ";border-color:", ";border-style:solid;border-width:1px;color:", ";max-width:100%;padding-right:", ";
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
});
|
30
|
+
})(["background-color:", ";border-color:", ";border-style:solid;border-width:1px;color:", ";max-width:100%;padding-right:", ";&:hover{background-color:", ";box-shadow:", ";color:", ";}"], (0, _constants.get)('colors.neutral.subtle'), props => props.isSelected ? (0, _constants.get)('colors.fg.default') : (0, _constants.get)('colors.border.subtle'), props => props.isSelected ? (0, _constants.get)('colors.fg.default') : (0, _constants.get)('colors.fg.muted'), props => !props.hideRemoveButton ? 0 : undefined, props => (0, _TokenBase.isTokenInteractive)(props) ? (0, _constants.get)('colors.neutral.muted') : undefined, props => (0, _TokenBase.isTokenInteractive)(props) ? (0, _constants.get)('colors.shadow.medium') : undefined, props => (0, _TokenBase.isTokenInteractive)(props) ? (0, _constants.get)('colors.fg.default') : undefined);
|
31
|
+
const TokenTextContainer = (0, _styledComponents.default)('span').withConfig({
|
32
|
+
displayName: "Token__TokenTextContainer",
|
33
|
+
componentId: "sc-1dg52pw-1"
|
34
|
+
})(["flex-grow:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"]);
|
37
35
|
const LeadingVisualContainer = (0, _styledComponents.default)('span').withConfig({
|
38
36
|
displayName: "Token__LeadingVisualContainer",
|
39
|
-
componentId: "sc-1dg52pw-
|
37
|
+
componentId: "sc-1dg52pw-2"
|
40
38
|
})(["flex-shrink:0;line-height:0;"]);
|
41
39
|
const Token = /*#__PURE__*/(0, _react.forwardRef)((props, forwardedRef) => {
|
42
40
|
const {
|
43
41
|
as,
|
44
|
-
|
42
|
+
handleRemove,
|
45
43
|
id,
|
46
44
|
leadingVisual: LeadingVisual,
|
47
45
|
ref,
|
48
46
|
text,
|
49
|
-
|
47
|
+
variant,
|
50
48
|
hideRemoveButton,
|
51
|
-
href,
|
52
|
-
onClick,
|
53
49
|
...rest
|
54
50
|
} = props;
|
55
|
-
const hasMultipleActionTargets = (0, _TokenBase.isTokenInteractive)(props) && Boolean(
|
51
|
+
const hasMultipleActionTargets = (0, _TokenBase.isTokenInteractive)(props) && Boolean(handleRemove) && !hideRemoveButton;
|
56
52
|
|
57
|
-
const
|
53
|
+
const handleRemoveClick = e => {
|
58
54
|
e.stopPropagation();
|
59
|
-
|
55
|
+
handleRemove && handleRemove();
|
60
56
|
};
|
61
57
|
|
62
|
-
const interactiveTokenProps = {
|
63
|
-
as,
|
64
|
-
href,
|
65
|
-
onClick
|
66
|
-
};
|
67
58
|
return /*#__PURE__*/_react.default.createElement(DefaultTokenStyled, _extends({
|
68
|
-
|
69
|
-
|
59
|
+
as: as,
|
60
|
+
handleRemove: handleRemove,
|
61
|
+
hideRemoveButton: hideRemoveButton || !handleRemove,
|
70
62
|
id: id === null || id === void 0 ? void 0 : id.toString(),
|
71
63
|
text: text,
|
72
64
|
ref: forwardedRef,
|
73
|
-
|
74
|
-
|
75
|
-
}, !hasMultipleActionTargets ? interactiveTokenProps : {}, rest), LeadingVisual ? /*#__PURE__*/_react.default.createElement(LeadingVisualContainer, null, /*#__PURE__*/_react.default.createElement(LeadingVisual, null)) : null, /*#__PURE__*/_react.default.createElement(_TokenTextContainer.default, hasMultipleActionTargets ? interactiveTokenProps : {}, text), !hideRemoveButton && onRemove ? /*#__PURE__*/_react.default.createElement(_RemoveTokenButton.default, {
|
65
|
+
variant: variant
|
66
|
+
}, rest), LeadingVisual ? /*#__PURE__*/_react.default.createElement(LeadingVisualContainer, null, /*#__PURE__*/_react.default.createElement(LeadingVisual, null)) : null, /*#__PURE__*/_react.default.createElement(TokenTextContainer, null, text), !hideRemoveButton && handleRemove ? /*#__PURE__*/_react.default.createElement(_RemoveTokenButton.default, {
|
76
67
|
borderOffset: tokenBorderWidthPx,
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
position: 'relative',
|
83
|
-
zIndex: '1'
|
84
|
-
} : {}
|
68
|
+
parentTokenTag: as || 'span',
|
69
|
+
onClick: handleRemoveClick,
|
70
|
+
variant: variant,
|
71
|
+
parentTokenIsInteractive: (0, _TokenBase.isTokenInteractive)(props),
|
72
|
+
"aria-hidden": hasMultipleActionTargets ? "true" : "false"
|
85
73
|
}) : null);
|
86
74
|
});
|
87
75
|
var _default = Token;
|
package/lib/Token/TokenBase.d.ts
CHANGED
@@ -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>;
|