@trackunit/react-components 0.0.124 → 0.0.125
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/components/Menu/MenuItem.d.ts +2 -1
- package/components/Select/CreatableSelect.d.ts +32 -4
- package/components/Select/FieldContainer.d.ts +3 -3
- package/components/Select/Select.d.ts +132 -5
- package/components/Select/{Select/TagWithWidth.d.ts → TagWithWidth.d.ts} +1 -1
- package/components/Select/{Select/TagsContainer.d.ts → TagsContainer.d.ts} +0 -0
- package/components/Select/index.d.ts +4 -0
- package/components/Select/shared.d.ts +10 -67
- package/components/Select/useCustomComponents.d.ts +19 -0
- package/components/Select/useCustomStyles.d.ts +14 -0
- package/index.js +802 -181
- package/package.json +1 -1
- package/components/Select/Select/Select.d.ts +0 -122
- package/components/Select/Select/useCustomComponents.d.ts +0 -20
- package/components/Select/Select/useCustomStyles.d.ts +0 -10
- package/components/Select/Select/utils.d.ts +0 -10
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { tw, tws } from '@trackunit/tailwind-styled-components';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { useState, forwardRef, useCallback, useRef, Fragment as Fragment$1, createElement, useContext, useEffect, memo } from 'react';
|
|
4
|
+
import React__default, { useState, forwardRef, useCallback, useRef, Fragment as Fragment$1, createElement, useContext, useEffect, memo } from 'react';
|
|
5
5
|
import { HeroIconsArray, heroIconLookup, TrackunitSolidIconsArray, TrackunitOutlineIconsArray, trackunitIconLookup } from '@trackunit/ui-icons';
|
|
6
6
|
import EChart from 'echarts-for-react';
|
|
7
7
|
import { v4 } from 'uuid';
|
|
@@ -13,9 +13,10 @@ import usePortal from 'react-useportal';
|
|
|
13
13
|
import { createPopper } from '@popperjs/core';
|
|
14
14
|
import { Helmet } from 'react-helmet';
|
|
15
15
|
import { UNSAFE_LocationContext, UNSAFE_NavigationContext } from 'react-router-dom';
|
|
16
|
+
import ReactSelect, { components } from 'react-select';
|
|
17
|
+
export { default as ValueType } from 'react-select';
|
|
16
18
|
import ReactAsyncCreatableSelect from 'react-select/async-creatable';
|
|
17
19
|
import ReactCreatableSelect from 'react-select/creatable';
|
|
18
|
-
import ReactSelect from 'react-select';
|
|
19
20
|
import ReactAsyncSelect from 'react-select/async';
|
|
20
21
|
import { format, formatDistance } from 'date-fns';
|
|
21
22
|
|
|
@@ -79,6 +80,16 @@ function __rest(s, e) {
|
|
|
79
80
|
t[p[i]] = s[p[i]];
|
|
80
81
|
}
|
|
81
82
|
return t;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
86
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
87
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
88
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
89
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
90
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
91
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
92
|
+
});
|
|
82
93
|
}
|
|
83
94
|
|
|
84
95
|
/**
|
|
@@ -104,7 +115,7 @@ const Spinner = ({
|
|
|
104
115
|
containerClassName,
|
|
105
116
|
dataTestId
|
|
106
117
|
}) => {
|
|
107
|
-
return jsx(Container$
|
|
118
|
+
return jsx(Container$a, Object.assign({
|
|
108
119
|
"$mode": mode,
|
|
109
120
|
"$centered": centered,
|
|
110
121
|
className: containerClassName
|
|
@@ -140,7 +151,7 @@ const StyledSpinner$1 = tw.span`
|
|
|
140
151
|
${p => p.$mode === "dark" ? tws`tu-spinner--dark` : null}
|
|
141
152
|
${getSpinnerStyles()}
|
|
142
153
|
`;
|
|
143
|
-
const Container$
|
|
154
|
+
const Container$a = tw.div`
|
|
144
155
|
tu-spinner--container
|
|
145
156
|
${p => p.$centered ? tws`tu-spinner--container-centered` : null}
|
|
146
157
|
`;
|
|
@@ -672,7 +683,7 @@ const Alert = ({
|
|
|
672
683
|
ref && ref.current && ref.current.scrollIntoView && ref.current.scrollIntoView();
|
|
673
684
|
}
|
|
674
685
|
}, [ref, autoScroll]);
|
|
675
|
-
return jsxs(Container$
|
|
686
|
+
return jsxs(Container$9, Object.assign({
|
|
676
687
|
"$intent": intent,
|
|
677
688
|
className: className,
|
|
678
689
|
"data-testid": dataTestId,
|
|
@@ -760,7 +771,7 @@ const getBackgroundColor = () => ({
|
|
|
760
771
|
return colors[$intent];
|
|
761
772
|
};
|
|
762
773
|
|
|
763
|
-
const Container$
|
|
774
|
+
const Container$9 = tw.div`
|
|
764
775
|
tu-alert
|
|
765
776
|
${p => p.$inline ? tws`tu-alert--inline` : null}
|
|
766
777
|
${getBackgroundColor()}
|
|
@@ -1248,7 +1259,7 @@ const CardHeader = ({
|
|
|
1248
1259
|
className: className,
|
|
1249
1260
|
"$density": density
|
|
1250
1261
|
}, {
|
|
1251
|
-
children: jsxs(Container$
|
|
1262
|
+
children: jsxs(Container$8, {
|
|
1252
1263
|
children: [jsxs("div", {
|
|
1253
1264
|
children: [jsxs(HeadingContainer, {
|
|
1254
1265
|
children: [jsx(Heading, Object.assign({
|
|
@@ -1278,7 +1289,7 @@ const CardHeader = ({
|
|
|
1278
1289
|
const BottomBorderedDensityContainer = tw(DensityContainer)`
|
|
1279
1290
|
tu-card__header-density-container
|
|
1280
1291
|
`;
|
|
1281
|
-
const Container$
|
|
1292
|
+
const Container$8 = tw.div`
|
|
1282
1293
|
tu-card__header
|
|
1283
1294
|
`;
|
|
1284
1295
|
const HeadingContainer = tw.div`
|
|
@@ -2180,7 +2191,7 @@ const PopoverTitle = ({
|
|
|
2180
2191
|
className,
|
|
2181
2192
|
dataTestId
|
|
2182
2193
|
}) => {
|
|
2183
|
-
return jsxs(Container$
|
|
2194
|
+
return jsxs(Container$7, Object.assign({
|
|
2184
2195
|
"$divider": divider,
|
|
2185
2196
|
className: className,
|
|
2186
2197
|
"data-testid": dataTestId
|
|
@@ -2196,7 +2207,7 @@ const PopoverTitle = ({
|
|
|
2196
2207
|
})), action]
|
|
2197
2208
|
}));
|
|
2198
2209
|
};
|
|
2199
|
-
const Container$
|
|
2210
|
+
const Container$7 = tw.div`
|
|
2200
2211
|
tu-popover-title-container
|
|
2201
2212
|
${p => p.$divider && `tu-popover-title-container--divider`}
|
|
2202
2213
|
`;
|
|
@@ -2245,7 +2256,7 @@ const Tooltip = ({
|
|
|
2245
2256
|
"data-testid": dataTestId && `${dataTestId}-parent`
|
|
2246
2257
|
}, {
|
|
2247
2258
|
children: children
|
|
2248
|
-
})), !disabled && jsx(Container$
|
|
2259
|
+
})), !disabled && jsx(Container$6, Object.assign({
|
|
2249
2260
|
ref: popoverRef,
|
|
2250
2261
|
onRequestClose: onHide,
|
|
2251
2262
|
enterDelay: 450
|
|
@@ -2269,7 +2280,7 @@ const Tooltip = ({
|
|
|
2269
2280
|
const Flex$1 = tw.div`
|
|
2270
2281
|
inline-flex
|
|
2271
2282
|
`;
|
|
2272
|
-
const Container$
|
|
2283
|
+
const Container$6 = tw(AnimatedPopover)`
|
|
2273
2284
|
tu-tooltip__container
|
|
2274
2285
|
`;
|
|
2275
2286
|
const Content = tw.div`
|
|
@@ -2555,7 +2566,7 @@ const Indicator$1 = _a => {
|
|
|
2555
2566
|
} = _a,
|
|
2556
2567
|
rest = __rest(_a, ["dataTestId", "icon", "label", "color", "withBackground"]);
|
|
2557
2568
|
|
|
2558
|
-
return jsxs(Container$
|
|
2569
|
+
return jsxs(Container$5, Object.assign({
|
|
2559
2570
|
"$color": color,
|
|
2560
2571
|
"data-testid": dataTestId
|
|
2561
2572
|
}, rest, {
|
|
@@ -2571,7 +2582,7 @@ const Indicator$1 = _a => {
|
|
|
2571
2582
|
}))]
|
|
2572
2583
|
}));
|
|
2573
2584
|
};
|
|
2574
|
-
const Container$
|
|
2585
|
+
const Container$5 = tw.div`
|
|
2575
2586
|
tu-indicator
|
|
2576
2587
|
${({
|
|
2577
2588
|
$color
|
|
@@ -2748,7 +2759,7 @@ const MenuItem = ({
|
|
|
2748
2759
|
className,
|
|
2749
2760
|
dataTestId
|
|
2750
2761
|
});
|
|
2751
|
-
return jsxs(Container$
|
|
2762
|
+
return jsxs(Container$4, Object.assign({}, containerProps, {
|
|
2752
2763
|
onClick: e => {
|
|
2753
2764
|
e.stopPropagation();
|
|
2754
2765
|
onClick && onClick(e);
|
|
@@ -2762,16 +2773,18 @@ const MenuItem = ({
|
|
|
2762
2773
|
"$selected": selected
|
|
2763
2774
|
}, {
|
|
2764
2775
|
children: prefix
|
|
2765
|
-
})), jsx(Label$2, {
|
|
2776
|
+
})), jsx(Label$2, Object.assign({
|
|
2777
|
+
"data-testid": dataTestId + "-label"
|
|
2778
|
+
}, {
|
|
2766
2779
|
children: label
|
|
2767
|
-
}), icon && jsx(Icon, Object.assign({
|
|
2780
|
+
})), icon && jsx(Icon, Object.assign({
|
|
2768
2781
|
"$selected": selected
|
|
2769
2782
|
}, {
|
|
2770
2783
|
children: icon
|
|
2771
2784
|
}))]
|
|
2772
2785
|
}));
|
|
2773
2786
|
};
|
|
2774
|
-
const Container$
|
|
2787
|
+
const Container$4 = tw.div`
|
|
2775
2788
|
group tu-menu-item
|
|
2776
2789
|
${({
|
|
2777
2790
|
$selected
|
|
@@ -2822,7 +2835,7 @@ const MenuList = _a => {
|
|
|
2822
2835
|
dataTestId
|
|
2823
2836
|
}, args));
|
|
2824
2837
|
return jsx(Wrapper, {
|
|
2825
|
-
children: jsx(Container$
|
|
2838
|
+
children: jsx(Container$3, Object.assign({}, containerProps, {
|
|
2826
2839
|
style: width ? {
|
|
2827
2840
|
width
|
|
2828
2841
|
} : undefined,
|
|
@@ -2844,7 +2857,7 @@ const MenuList = _a => {
|
|
|
2844
2857
|
const Wrapper = tw.div`
|
|
2845
2858
|
tu-menu-list__wrapper
|
|
2846
2859
|
`;
|
|
2847
|
-
const Container$
|
|
2860
|
+
const Container$3 = tw.div`
|
|
2848
2861
|
tu-menu-list
|
|
2849
2862
|
`;
|
|
2850
2863
|
const Divider = tw.div`
|
|
@@ -3153,7 +3166,7 @@ const Tag = React.forwardRef((_a, ref) => {
|
|
|
3153
3166
|
return jsxs(StyledText, Object.assign({
|
|
3154
3167
|
className: className,
|
|
3155
3168
|
"$size": size,
|
|
3156
|
-
"data-testid": dataTestId
|
|
3169
|
+
"data-testid": `${dataTestId}-tag`,
|
|
3157
3170
|
"$as": "span",
|
|
3158
3171
|
"$color": color,
|
|
3159
3172
|
"$withXIcon": !!onClose,
|
|
@@ -3168,7 +3181,7 @@ const Tag = React.forwardRef((_a, ref) => {
|
|
|
3168
3181
|
dataTestId: dataTestId + "Icon",
|
|
3169
3182
|
type: "solid",
|
|
3170
3183
|
style: {
|
|
3171
|
-
|
|
3184
|
+
WebkitTransition: "-webkit-transform 0.150s"
|
|
3172
3185
|
},
|
|
3173
3186
|
className: size === "medium" ? tws`tu-tag__icon` : tws`tu-tag__icon tu-tag__icon--small`
|
|
3174
3187
|
})
|
|
@@ -3475,7 +3488,7 @@ tu-radioitem__description
|
|
|
3475
3488
|
* @returns {JSX.Element} SelectContainer component
|
|
3476
3489
|
*/
|
|
3477
3490
|
|
|
3478
|
-
const SelectContainer = ({
|
|
3491
|
+
const SelectContainer$1 = ({
|
|
3479
3492
|
children,
|
|
3480
3493
|
label,
|
|
3481
3494
|
hideLabel,
|
|
@@ -3484,10 +3497,13 @@ const SelectContainer = ({
|
|
|
3484
3497
|
error,
|
|
3485
3498
|
description,
|
|
3486
3499
|
info,
|
|
3487
|
-
dataTestId
|
|
3500
|
+
dataTestId,
|
|
3501
|
+
isDisabled
|
|
3488
3502
|
}) => {
|
|
3489
|
-
return jsxs(Container, Object.assign({
|
|
3490
|
-
"data-testid": dataTestId
|
|
3503
|
+
return jsxs(Container$2, Object.assign({
|
|
3504
|
+
"data-testid": dataTestId,
|
|
3505
|
+
"$hasError": hasError,
|
|
3506
|
+
"$isDisabled": isDisabled
|
|
3491
3507
|
}, {
|
|
3492
3508
|
children: [label && !hideLabel && jsx(Label$5, Object.assign({
|
|
3493
3509
|
htmlFor: id
|
|
@@ -3501,123 +3517,573 @@ const SelectContainer = ({
|
|
|
3501
3517
|
}))]
|
|
3502
3518
|
}));
|
|
3503
3519
|
};
|
|
3504
|
-
const Container = tw.label`
|
|
3505
|
-
tu-select__container
|
|
3520
|
+
const Container$2 = tw.label`
|
|
3521
|
+
tu-select__container
|
|
3522
|
+
tu-select
|
|
3523
|
+
${({
|
|
3524
|
+
$hasError
|
|
3525
|
+
}) => $hasError ? tws`tu-select--invalid` : null}
|
|
3526
|
+
${({
|
|
3527
|
+
$isDisabled
|
|
3528
|
+
}) => $isDisabled ? tws`tu-select--disabled` : null}
|
|
3506
3529
|
`;
|
|
3507
3530
|
const InformativeText = tw(Text)`
|
|
3508
3531
|
tu-informative-text
|
|
3509
3532
|
${p => p.$hasError ? `tu-informative-text--error` : null}
|
|
3510
3533
|
`;
|
|
3511
3534
|
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
return
|
|
3535
|
+
/**
|
|
3536
|
+
* @param {MultiValue<Option> | SingleValue<Option>} arg option to check type
|
|
3537
|
+
* @returns {arg is MultiValue<Option> } is Multivalue
|
|
3538
|
+
*/
|
|
3539
|
+
function isMultiValue(arg) {
|
|
3540
|
+
return Array.isArray(arg);
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
function isGroupBase(arg) {
|
|
3544
|
+
return arg.options !== undefined;
|
|
3545
|
+
}
|
|
3546
|
+
|
|
3547
|
+
const isSelectedOption = (option, selected) => {
|
|
3548
|
+
if (isGroupBase(option)) {
|
|
3549
|
+
return false;
|
|
3550
|
+
}
|
|
3551
|
+
|
|
3552
|
+
return isMultiValue(selected) ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3553
|
+
selected.some(v => v.value === option.value) : // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3554
|
+
option.value === (selected === null || selected === void 0 ? void 0 : selected.value);
|
|
3555
|
+
};
|
|
3556
|
+
|
|
3557
|
+
const removeSelectedFromGroups = (group, selected) => {
|
|
3558
|
+
if (isGroupBase(group)) {
|
|
3559
|
+
return Object.assign(Object.assign({}, group), {
|
|
3560
|
+
options: group.options.filter(option => !isSelectedOption(option, selected))
|
|
3561
|
+
});
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3564
|
+
return group;
|
|
3565
|
+
};
|
|
3566
|
+
/**
|
|
3567
|
+
* @template IsMulti
|
|
3568
|
+
* @template Group
|
|
3569
|
+
* @param {OptionsOrGroups<Option, Group> | undefined} options An array of options to select from
|
|
3570
|
+
* @param {PropsValue<Option> | undefined} value Selected values
|
|
3571
|
+
* @returns {OptionsOrGroups<Option, Group>} An array of ordered options with selected on top
|
|
3572
|
+
*/
|
|
3573
|
+
|
|
3574
|
+
|
|
3575
|
+
const getOrderedOptions = (options, value) => {
|
|
3576
|
+
if (value && options) {
|
|
3577
|
+
const orderedValues = isMultiValue(value) ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3578
|
+
[...value].sort((a, b) => a.label.localeCompare(b.label)) : [value];
|
|
3579
|
+
const selectableOptions = options.filter(option => !isSelectedOption(option, value)).map(option => removeSelectedFromGroups(option, value)); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3580
|
+
|
|
3581
|
+
return orderedValues.concat(selectableOptions) || [];
|
|
3582
|
+
}
|
|
3583
|
+
|
|
3584
|
+
return options || [];
|
|
3518
3585
|
};
|
|
3586
|
+
|
|
3519
3587
|
/**
|
|
3520
|
-
*
|
|
3588
|
+
* A single select menu item is a basic wrapper around Menu item designed to be used as a single value render in Select list
|
|
3521
3589
|
*
|
|
3522
|
-
* @param {
|
|
3523
|
-
* @
|
|
3524
|
-
* @param {boolean} isInvalid -
|
|
3525
|
-
* @param {SelectSize} size -
|
|
3526
|
-
* @returns {{StylesConfig}} useCustomStyles hook return
|
|
3590
|
+
* @param {SelectMenuItemProps} props - The props for the SingleSelectMenuItem
|
|
3591
|
+
* @returns {JSX.Element} SingleSelectMenuItem
|
|
3527
3592
|
*/
|
|
3528
3593
|
|
|
3594
|
+
const SingleSelectMenuItem = ({
|
|
3595
|
+
label,
|
|
3596
|
+
icon,
|
|
3597
|
+
onClick,
|
|
3598
|
+
selected,
|
|
3599
|
+
dataTestId,
|
|
3600
|
+
focused
|
|
3601
|
+
}) => {
|
|
3602
|
+
return jsx(MenuItem, {
|
|
3603
|
+
dataTestId: dataTestId,
|
|
3604
|
+
label: label,
|
|
3605
|
+
prefix: icon,
|
|
3606
|
+
onClick: onClick,
|
|
3607
|
+
selected: selected,
|
|
3608
|
+
focused: focused,
|
|
3609
|
+
icon: selected ? jsx(Icon$1, {
|
|
3610
|
+
name: "CheckIcon",
|
|
3611
|
+
size: "small"
|
|
3612
|
+
}) : undefined
|
|
3613
|
+
});
|
|
3614
|
+
};
|
|
3615
|
+
/**
|
|
3616
|
+
* A multi select menu item is a basic wrapper around Menu item designed to be used as a multi value render in Select list
|
|
3617
|
+
*
|
|
3618
|
+
* @param {SelectMenuItemProps} props - The props for the MultiSelectMenuItem
|
|
3619
|
+
* @returns {JSX.Element} multi select menu item
|
|
3620
|
+
*/
|
|
3529
3621
|
|
|
3530
|
-
const
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3622
|
+
const MultiSelectMenuItem = ({
|
|
3623
|
+
label,
|
|
3624
|
+
onClick,
|
|
3625
|
+
selected,
|
|
3626
|
+
dataTestId,
|
|
3627
|
+
focused,
|
|
3628
|
+
disabled
|
|
3629
|
+
}) => {
|
|
3630
|
+
return jsx(MenuItem, {
|
|
3631
|
+
dataTestId: dataTestId,
|
|
3632
|
+
label: label,
|
|
3633
|
+
disabled: disabled,
|
|
3634
|
+
prefix: jsx(Checkbox, {
|
|
3635
|
+
checked: selected,
|
|
3636
|
+
readOnly: false,
|
|
3637
|
+
onChange: () => null,
|
|
3638
|
+
disabled: disabled,
|
|
3639
|
+
onClick: e => {
|
|
3640
|
+
e.stopPropagation();
|
|
3641
|
+
}
|
|
3642
|
+
}),
|
|
3643
|
+
onClick: e => {
|
|
3644
|
+
e.stopPropagation();
|
|
3645
|
+
onClick && onClick(e);
|
|
3646
|
+
},
|
|
3647
|
+
selected: selected,
|
|
3648
|
+
focused: focused
|
|
3649
|
+
});
|
|
3650
|
+
};
|
|
3651
|
+
|
|
3652
|
+
/**
|
|
3653
|
+
* Extended Tag component with information about its own width.
|
|
3654
|
+
* Used in the select component.
|
|
3655
|
+
*
|
|
3656
|
+
* @param {TagProps} props - The props for the tag component
|
|
3657
|
+
* @returns {JSX.Element} TagWithWidth component
|
|
3658
|
+
*/
|
|
3659
|
+
|
|
3660
|
+
const TagWithWidth = _a => {
|
|
3661
|
+
var {
|
|
3662
|
+
onWidthKnown,
|
|
3663
|
+
children
|
|
3664
|
+
} = _a,
|
|
3665
|
+
rest = __rest(_a, ["onWidthKnown", "children"]);
|
|
3666
|
+
|
|
3667
|
+
const ref = React__default.useRef(null);
|
|
3668
|
+
React__default.useLayoutEffect(() => {
|
|
3669
|
+
var _a;
|
|
3670
|
+
|
|
3671
|
+
onWidthKnown && onWidthKnown({
|
|
3672
|
+
width: ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0
|
|
3673
|
+
});
|
|
3674
|
+
}, [ref, onWidthKnown]);
|
|
3675
|
+
return jsx(Tag, Object.assign({
|
|
3676
|
+
ref: ref
|
|
3677
|
+
}, rest, {
|
|
3678
|
+
children: children
|
|
3679
|
+
}));
|
|
3680
|
+
};
|
|
3681
|
+
|
|
3682
|
+
/**
|
|
3683
|
+
* TagsContainer component to display tags in limited space when children can't fit space it displays counter
|
|
3684
|
+
*
|
|
3685
|
+
* @param {TagsContainerProps} props - The props for the TagContainer
|
|
3686
|
+
* @returns {JSX.Element} TagsContainer
|
|
3687
|
+
*/
|
|
3688
|
+
|
|
3689
|
+
const TagsContainer = ({
|
|
3690
|
+
items,
|
|
3691
|
+
width = "100%",
|
|
3692
|
+
itemsGap = 5,
|
|
3693
|
+
postFix
|
|
3694
|
+
}) => {
|
|
3695
|
+
const [isReady, setIsReady] = React__default.useState(false);
|
|
3696
|
+
const [counterWidth, setCounterWidth] = React__default.useState(0);
|
|
3697
|
+
const containerRef = React__default.useRef(null);
|
|
3698
|
+
const availableWidth = React__default.useRef();
|
|
3699
|
+
const childrenWidth = React__default.useRef([]);
|
|
3700
|
+
const itemsCount = items.length;
|
|
3701
|
+
React__default.useLayoutEffect(() => {
|
|
3702
|
+
var _a;
|
|
3703
|
+
|
|
3704
|
+
availableWidth.current = ((_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
|
|
3705
|
+
}, [containerRef]);
|
|
3706
|
+
|
|
3707
|
+
const onWidthKnownHandler = ({
|
|
3708
|
+
width: reportedWidth
|
|
3709
|
+
}) => {
|
|
3710
|
+
childrenWidth.current.push({
|
|
3711
|
+
width: reportedWidth + itemsGap
|
|
3712
|
+
});
|
|
3713
|
+
|
|
3714
|
+
if (childrenWidth.current.length === itemsCount) {
|
|
3715
|
+
setIsReady(true);
|
|
3716
|
+
}
|
|
3582
3717
|
};
|
|
3718
|
+
|
|
3719
|
+
const requiredSpace = childrenWidth.current.reduce((previous, current) => {
|
|
3720
|
+
return previous + current.width;
|
|
3721
|
+
}, 0);
|
|
3722
|
+
let counter = 0;
|
|
3723
|
+
const availableSpace = ((availableWidth === null || availableWidth === void 0 ? void 0 : availableWidth.current) || 0) - counterWidth;
|
|
3724
|
+
const renderedElements = items.concat({
|
|
3725
|
+
text: "",
|
|
3726
|
+
onClick: () => null,
|
|
3727
|
+
disabled: false
|
|
3728
|
+
}) // reserved element for a potential counter
|
|
3729
|
+
.map((item, index) => {
|
|
3730
|
+
const spaceNeeded = childrenWidth.current.slice(0, index + 1).reduce((previous, current) => {
|
|
3731
|
+
return previous + current.width;
|
|
3732
|
+
}, 0);
|
|
3733
|
+
const isLast = index === items.length;
|
|
3734
|
+
const counterRequired = requiredSpace > availableSpace && counter !== 0;
|
|
3735
|
+
|
|
3736
|
+
if (isLast && counterRequired) {
|
|
3737
|
+
return jsx(TagWithWidth, Object.assign({
|
|
3738
|
+
onWidthKnown: ({
|
|
3739
|
+
width: reportedWidth
|
|
3740
|
+
}) => setCounterWidth(reportedWidth),
|
|
3741
|
+
color: "neutral"
|
|
3742
|
+
}, {
|
|
3743
|
+
children: jsxs(Counter, {
|
|
3744
|
+
children: ["+", counter]
|
|
3745
|
+
})
|
|
3746
|
+
}), item.text + index);
|
|
3747
|
+
}
|
|
3748
|
+
|
|
3749
|
+
if (isLast) {
|
|
3750
|
+
return null;
|
|
3751
|
+
}
|
|
3752
|
+
|
|
3753
|
+
const itemCanFit = spaceNeeded <= availableSpace;
|
|
3754
|
+
|
|
3755
|
+
if (itemCanFit) {
|
|
3756
|
+
return jsx(TagWithWidth, Object.assign({
|
|
3757
|
+
onWidthKnown: onWidthKnownHandler,
|
|
3758
|
+
className: tws`shrink-0 inline-flex`,
|
|
3759
|
+
onClose: e => {
|
|
3760
|
+
e.stopPropagation();
|
|
3761
|
+
item.onClick();
|
|
3762
|
+
},
|
|
3763
|
+
color: item.disabled ? "unknown" : "primary",
|
|
3764
|
+
dataTestId: item.text
|
|
3765
|
+
}, {
|
|
3766
|
+
children: item.text
|
|
3767
|
+
}), item.text + index);
|
|
3768
|
+
}
|
|
3769
|
+
|
|
3770
|
+
const fromTheItems = item.text !== "";
|
|
3771
|
+
|
|
3772
|
+
if (fromTheItems) {
|
|
3773
|
+
counter = counter + 1;
|
|
3774
|
+
}
|
|
3775
|
+
|
|
3776
|
+
return null;
|
|
3777
|
+
}).filter(element => element !== null);
|
|
3778
|
+
return jsxs(Container$1, Object.assign({
|
|
3779
|
+
style: {
|
|
3780
|
+
width: `${width}`
|
|
3781
|
+
},
|
|
3782
|
+
"$ready": isReady,
|
|
3783
|
+
ref: containerRef
|
|
3784
|
+
}, {
|
|
3785
|
+
children: [renderedElements, postFix]
|
|
3786
|
+
}));
|
|
3583
3787
|
};
|
|
3788
|
+
const Container$1 = tw.div`
|
|
3789
|
+
tu-select__dynamic-tag--container
|
|
3790
|
+
${({
|
|
3791
|
+
$ready
|
|
3792
|
+
}) => {
|
|
3793
|
+
return $ready ? tws`visible` : tws`invisible`;
|
|
3794
|
+
}}
|
|
3795
|
+
`;
|
|
3796
|
+
const Counter = tw.div`
|
|
3797
|
+
tu-select__counter
|
|
3798
|
+
`;
|
|
3799
|
+
|
|
3584
3800
|
/**
|
|
3585
|
-
*
|
|
3801
|
+
* A hook to retrieve components override object.
|
|
3802
|
+
* This complex object includes all the compositional components that are used in react-select. If you wish to overwrite a component, pass in an object with the appropriate namespace.
|
|
3586
3803
|
*
|
|
3587
|
-
* @
|
|
3588
|
-
* @
|
|
3804
|
+
* @template IsMulti
|
|
3805
|
+
* @template Group
|
|
3806
|
+
* @param {Partial<SelectComponents<Option, IsMulti, Group>> | undefined} componentsProps a custom component prop that you can to override defaults
|
|
3807
|
+
* @param {boolean} disabled decide to override disabled variant
|
|
3808
|
+
* @param {boolean} menuIsClosing a flag to trigger fade out animation for the menu
|
|
3809
|
+
* @param {React.MutableRefObject<boolean>} refMenuIsEnabled a flag to block menu from open
|
|
3810
|
+
* @param {string} dataTestId a test id
|
|
3811
|
+
* @param {number} maxSelectedDisplayCount a number of max display count
|
|
3812
|
+
* @param {JSX.Element} dropdownIcon an custom dropdown icon
|
|
3813
|
+
* @returns {Partial<SelectComponents<Option, boolean, GroupBase<Option>>> | undefined} components object to override react-select default components
|
|
3589
3814
|
*/
|
|
3590
3815
|
|
|
3591
|
-
const useCustomComponents =
|
|
3816
|
+
const useCustomComponents = (componentsProps, disabled, menuIsClosing, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon) => {
|
|
3592
3817
|
const customComponents = React.useMemo(() => {
|
|
3593
3818
|
return Object.assign({
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3819
|
+
ValueContainer: props => {
|
|
3820
|
+
if (props.isMulti) {
|
|
3821
|
+
const PLACEHOLDER_KEY = "placeholder";
|
|
3822
|
+
const key = props && props.children && props.children[0] ? props.children[0].key : "";
|
|
3823
|
+
const values = props && props.children ? props.children[0] : [];
|
|
3824
|
+
const tags = key === PLACEHOLDER_KEY ? [] : values;
|
|
3825
|
+
const searchInput = props && props.children && props.children[1];
|
|
3826
|
+
return jsx(components.ValueContainer, Object.assign({}, props, {
|
|
3827
|
+
isDisabled: props.selectProps.isDisabled
|
|
3828
|
+
}, {
|
|
3829
|
+
children: maxSelectedDisplayCount === undefined ? jsx(TagsContainer, {
|
|
3830
|
+
width: "100%",
|
|
3831
|
+
items: tags ? tags.map(({
|
|
3832
|
+
props: tagProps
|
|
3833
|
+
}) => {
|
|
3834
|
+
return {
|
|
3835
|
+
text: tagProps.children,
|
|
3836
|
+
onClick: disabled ? undefined : e => {
|
|
3837
|
+
var _a, _b;
|
|
3838
|
+
|
|
3839
|
+
refMenuIsEnabled.current = false;
|
|
3840
|
+
((_a = tagProps === null || tagProps === void 0 ? void 0 : tagProps.removeProps) === null || _a === void 0 ? void 0 : _a.onClick) && ((_b = tagProps === null || tagProps === void 0 ? void 0 : tagProps.removeProps) === null || _b === void 0 ? void 0 : _b.onClick(e));
|
|
3841
|
+
},
|
|
3842
|
+
disabled: disabled
|
|
3843
|
+
};
|
|
3844
|
+
}) : [],
|
|
3845
|
+
postFix: searchInput
|
|
3846
|
+
}) : jsxs(Fragment, {
|
|
3847
|
+
children: [tags && tags.slice(0, maxSelectedDisplayCount).map(({
|
|
3848
|
+
props: tagProps
|
|
3849
|
+
}) => {
|
|
3850
|
+
var _a, _b;
|
|
3851
|
+
|
|
3852
|
+
return jsx(Tag, Object.assign({
|
|
3853
|
+
className: tws`shrink-0 inline-flex`,
|
|
3854
|
+
onClose: e => {
|
|
3855
|
+
var _a, _b;
|
|
3856
|
+
|
|
3857
|
+
e.stopPropagation();
|
|
3858
|
+
refMenuIsEnabled.current = false;
|
|
3859
|
+
((_a = tagProps === null || tagProps === void 0 ? void 0 : tagProps.removeProps) === null || _a === void 0 ? void 0 : _a.onClick) && ((_b = tagProps === null || tagProps === void 0 ? void 0 : tagProps.removeProps) === null || _b === void 0 ? void 0 : _b.onClick(e));
|
|
3860
|
+
},
|
|
3861
|
+
color: disabled ? "unknown" : "primary",
|
|
3862
|
+
dataTestId: (_a = tagProps.children) === null || _a === void 0 ? void 0 : _a.toString()
|
|
3863
|
+
}, {
|
|
3864
|
+
children: tagProps.children
|
|
3865
|
+
}), (_b = tagProps.children) === null || _b === void 0 ? void 0 : _b.toString());
|
|
3866
|
+
}), tags && tags.length > maxSelectedDisplayCount && jsxs(Tag, Object.assign({
|
|
3867
|
+
color: "neutral",
|
|
3868
|
+
dataTestId: "counter"
|
|
3869
|
+
}, {
|
|
3870
|
+
children: ["+", tags.length - maxSelectedDisplayCount]
|
|
3871
|
+
})), searchInput]
|
|
3872
|
+
})
|
|
3873
|
+
}));
|
|
3874
|
+
}
|
|
3875
|
+
|
|
3876
|
+
return jsx(components.ValueContainer, Object.assign({}, props, {
|
|
3877
|
+
isDisabled: props.selectProps.isDisabled
|
|
3878
|
+
}, {
|
|
3879
|
+
children: props.children
|
|
3880
|
+
}));
|
|
3881
|
+
},
|
|
3882
|
+
LoadingIndicator: props => {
|
|
3883
|
+
return jsx(Spinner, {
|
|
3884
|
+
size: "small",
|
|
3885
|
+
className: tws`mt-1.5 mr-1`
|
|
3886
|
+
});
|
|
3887
|
+
},
|
|
3888
|
+
DropdownIndicator: props => {
|
|
3889
|
+
return jsx(components.DropdownIndicator, Object.assign({}, props, {
|
|
3890
|
+
children: jsx(StyledIcon, {
|
|
3891
|
+
children: dropdownIcon ? dropdownIcon : menuIsClosing ? jsx(Icon$1, {
|
|
3892
|
+
name: "ChevronDownIcon",
|
|
3893
|
+
size: "medium"
|
|
3894
|
+
}) : jsx(Icon$1, {
|
|
3895
|
+
name: "ChevronUpIcon",
|
|
3896
|
+
size: "medium"
|
|
3897
|
+
})
|
|
3898
|
+
})
|
|
3899
|
+
}));
|
|
3900
|
+
},
|
|
3901
|
+
IndicatorSeparator: () => null,
|
|
3902
|
+
ClearIndicator: props => {
|
|
3903
|
+
if (disabled) {
|
|
3904
|
+
return null;
|
|
3905
|
+
}
|
|
3906
|
+
|
|
3907
|
+
return jsx(components.ClearIndicator, Object.assign({}, props, {
|
|
3908
|
+
children: jsx(XIcon, Object.assign({
|
|
3909
|
+
onClick: props.clearValue,
|
|
3910
|
+
"data-testid": `${dataTestId}-XIcon`
|
|
3911
|
+
}, {
|
|
3912
|
+
children: jsx(Icon$1, {
|
|
3913
|
+
name: "XCircleIcon",
|
|
3914
|
+
size: "medium"
|
|
3915
|
+
})
|
|
3916
|
+
}))
|
|
3917
|
+
}));
|
|
3918
|
+
},
|
|
3919
|
+
Control: props => {
|
|
3920
|
+
return jsx(components.Control, Object.assign({}, props, {
|
|
3921
|
+
className: props.isDisabled ? tws`tu-select__control--disabled` : ""
|
|
3922
|
+
}));
|
|
3923
|
+
},
|
|
3924
|
+
SingleValue: props => {
|
|
3925
|
+
return jsx(components.SingleValue, Object.assign({}, props, {
|
|
3926
|
+
className: props.isDisabled ? tws`tu-select__single-value--disabled` : ""
|
|
3927
|
+
}, {
|
|
3928
|
+
children: jsx("div", Object.assign({
|
|
3929
|
+
"data-testid": dataTestId + "-singleValue"
|
|
3930
|
+
}, {
|
|
3931
|
+
children: props.children
|
|
3932
|
+
}))
|
|
3933
|
+
}));
|
|
3934
|
+
},
|
|
3935
|
+
Menu: props => {
|
|
3936
|
+
return jsx(components.Menu, Object.assign({}, props, {
|
|
3937
|
+
className: menuIsClosing ? tws`tu-menu-list animate-fade-out-fast` : tws`tu-menu-list animate-fade-in-fast`
|
|
3938
|
+
}));
|
|
3939
|
+
},
|
|
3940
|
+
MenuList: props => {
|
|
3941
|
+
return jsx(components.MenuList, Object.assign({}, props, {
|
|
3942
|
+
children: jsx(Container, Object.assign({
|
|
3943
|
+
"$disabled": disabled
|
|
3944
|
+
}, {
|
|
3945
|
+
children: props.children
|
|
3946
|
+
}))
|
|
3947
|
+
}));
|
|
3948
|
+
},
|
|
3949
|
+
Option: props => {
|
|
3950
|
+
const componentProps = {
|
|
3951
|
+
label: props.label,
|
|
3952
|
+
focused: props.isFocused,
|
|
3953
|
+
selected: props.isSelected,
|
|
3954
|
+
onClick: props.innerProps.onClick
|
|
3955
|
+
};
|
|
3956
|
+
return jsx(components.Option, Object.assign({}, props, {
|
|
3957
|
+
innerProps: Object.assign(Object.assign({}, props.innerProps), {
|
|
3958
|
+
onClick: () => {}
|
|
3959
|
+
})
|
|
3599
3960
|
}, {
|
|
3600
|
-
children: jsx(
|
|
3961
|
+
children: props.isMulti ? jsx(MultiSelectMenuItem, Object.assign({}, componentProps, {
|
|
3962
|
+
disabled: disabled,
|
|
3963
|
+
dataTestId: props.label
|
|
3964
|
+
})) : jsx(SingleSelectMenuItem, Object.assign({}, componentProps, {
|
|
3965
|
+
dataTestId: props.label
|
|
3966
|
+
}))
|
|
3601
3967
|
}));
|
|
3602
3968
|
}
|
|
3603
|
-
},
|
|
3604
|
-
}, [
|
|
3969
|
+
}, componentsProps); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3970
|
+
}, [componentsProps, disabled, menuIsClosing, refMenuIsEnabled, maxSelectedDisplayCount]); // do not add dropdownIcon (it will cause issue with opening/closing list for selects with custom icon)
|
|
3971
|
+
|
|
3972
|
+
return customComponents;
|
|
3973
|
+
};
|
|
3974
|
+
const Container = tw.div`
|
|
3975
|
+
tu-select__menu
|
|
3976
|
+
${({
|
|
3977
|
+
$disabled
|
|
3978
|
+
}) => {
|
|
3979
|
+
return $disabled ? tws`pointer-events-none` : "";
|
|
3980
|
+
}}
|
|
3981
|
+
`;
|
|
3982
|
+
const StyledIcon = tw.div`
|
|
3983
|
+
tu-select--icon
|
|
3984
|
+
`;
|
|
3985
|
+
const XIcon = tw.div`
|
|
3986
|
+
tu-select--icon
|
|
3987
|
+
tu-select__x-icon
|
|
3988
|
+
`;
|
|
3989
|
+
|
|
3990
|
+
/**
|
|
3991
|
+
* @template IsMulti
|
|
3992
|
+
* @template Group
|
|
3993
|
+
* @param {React.RefObject<HTMLDivElement>} refContainer react ref to container element
|
|
3994
|
+
* @param {React.RefObject<HTMLDivElement>} refPrefix react ref to prefix element
|
|
3995
|
+
* @param {number | undefined} maxSelectedDisplayCount a number of max display count
|
|
3996
|
+
* @param {StylesConfig<Option, IsMulti, Group> | undefined} styles a optional object to override styles of react-select
|
|
3997
|
+
* @returns {StylesConfig<Option, boolean>} styles to override in select
|
|
3998
|
+
*/
|
|
3999
|
+
|
|
4000
|
+
const useCustomStyles = (refContainer, refPrefix, maxSelectedDisplayCount, styles) => {
|
|
4001
|
+
const customStyles = React.useMemo(() => {
|
|
4002
|
+
return Object.assign({
|
|
4003
|
+
control: base => {
|
|
4004
|
+
return Object.assign(Object.assign({}, base), {
|
|
4005
|
+
border: "0",
|
|
4006
|
+
boxShadow: "0",
|
|
4007
|
+
"&:hover": {
|
|
4008
|
+
border: "0"
|
|
4009
|
+
},
|
|
4010
|
+
marginRight: "2px",
|
|
4011
|
+
backgroundColor: ""
|
|
4012
|
+
});
|
|
4013
|
+
},
|
|
4014
|
+
singleValue: base => Object.assign({}, base),
|
|
4015
|
+
multiValue: base => Object.assign({}, base),
|
|
4016
|
+
multiValueLabel: base => Object.assign({}, base),
|
|
4017
|
+
indicatorsContainer: base => Object.assign({}, base),
|
|
4018
|
+
indicatorSeparator: () => ({
|
|
4019
|
+
width: "0px"
|
|
4020
|
+
}),
|
|
4021
|
+
menu: () => {
|
|
4022
|
+
return {
|
|
4023
|
+
width: "100%",
|
|
4024
|
+
marginTop: "4px",
|
|
4025
|
+
marginBottom: "18px",
|
|
4026
|
+
transition: "all 1s ease-in-out"
|
|
4027
|
+
};
|
|
4028
|
+
},
|
|
4029
|
+
input: base => Object.assign(Object.assign({}, base), {
|
|
4030
|
+
marginLeft: "0px"
|
|
4031
|
+
}),
|
|
4032
|
+
placeholder: base => Object.assign({}, base),
|
|
4033
|
+
option: () => ({}),
|
|
4034
|
+
menuPortal: base => Object.assign(Object.assign({}, base), {
|
|
4035
|
+
width: (refContainer === null || refContainer === void 0 ? void 0 : refContainer.current) ? `${refContainer.current.clientWidth}px` : base.width,
|
|
4036
|
+
transform: (refPrefix === null || refPrefix === void 0 ? void 0 : refPrefix.current) ? `translate(-${refPrefix.current.clientWidth + 2}px)` : "translate(-2px)",
|
|
4037
|
+
backgroundColor: "#ffffff",
|
|
4038
|
+
borderRadius: "var(--border-radius-lg)",
|
|
4039
|
+
zIndex: 20,
|
|
4040
|
+
borderColor: "rgb(var(--color-slate-300))",
|
|
4041
|
+
boxShadow: "var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow)"
|
|
4042
|
+
}),
|
|
4043
|
+
menuList: base => {
|
|
4044
|
+
return Object.assign(Object.assign({}, base), {
|
|
4045
|
+
width: "100%",
|
|
4046
|
+
borderRadius: "0px",
|
|
4047
|
+
boxShadow: "none",
|
|
4048
|
+
paddingTop: "0px"
|
|
4049
|
+
});
|
|
4050
|
+
},
|
|
4051
|
+
valueContainer: base => {
|
|
4052
|
+
return Object.assign(Object.assign({}, base), {
|
|
4053
|
+
flexWrap: maxSelectedDisplayCount !== undefined ? "wrap" : "nowrap",
|
|
4054
|
+
gap: "0.25rem"
|
|
4055
|
+
});
|
|
4056
|
+
},
|
|
4057
|
+
container: base => Object.assign(Object.assign({}, base), {
|
|
4058
|
+
border: "none",
|
|
4059
|
+
width: "calc(100% - 2px)",
|
|
4060
|
+
paddingLeft: "2px"
|
|
4061
|
+
}),
|
|
4062
|
+
dropdownIndicator: base => Object.assign(Object.assign({}, base), {
|
|
4063
|
+
padding: "0px"
|
|
4064
|
+
}),
|
|
4065
|
+
clearIndicator: base => {
|
|
4066
|
+
return Object.assign(Object.assign({}, base), {
|
|
4067
|
+
padding: "0px"
|
|
4068
|
+
});
|
|
4069
|
+
}
|
|
4070
|
+
}, styles); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4071
|
+
}, [refContainer, refPrefix]);
|
|
3605
4072
|
return {
|
|
3606
|
-
|
|
4073
|
+
customStyles
|
|
3607
4074
|
};
|
|
3608
4075
|
};
|
|
3609
4076
|
|
|
3610
4077
|
/**
|
|
3611
4078
|
* The CreatableSelect component.
|
|
3612
4079
|
*
|
|
3613
|
-
* @param {
|
|
4080
|
+
* @param {CreateableSelectProps} props - The props for the CreatableSelect component
|
|
3614
4081
|
* @returns {JSX.Element} CreatableSelect component
|
|
3615
4082
|
*/
|
|
3616
4083
|
|
|
3617
4084
|
const CreatableSelect = _a => {
|
|
3618
4085
|
var {
|
|
3619
|
-
dataTestId,
|
|
3620
|
-
size = "medium",
|
|
4086
|
+
dataTestId = "createableSelect",
|
|
3621
4087
|
id,
|
|
3622
4088
|
label,
|
|
3623
4089
|
hideLabel,
|
|
@@ -3626,19 +4092,77 @@ const CreatableSelect = _a => {
|
|
|
3626
4092
|
info,
|
|
3627
4093
|
isInvalid,
|
|
3628
4094
|
maxMenuHeight = 308,
|
|
3629
|
-
|
|
3630
|
-
|
|
4095
|
+
components,
|
|
4096
|
+
disabled,
|
|
4097
|
+
async,
|
|
4098
|
+
value,
|
|
4099
|
+
onChange,
|
|
4100
|
+
isMulti,
|
|
4101
|
+
classNamePrefix,
|
|
4102
|
+
isLoading,
|
|
4103
|
+
options,
|
|
4104
|
+
onMenuOpen,
|
|
4105
|
+
styles
|
|
3631
4106
|
} = _a,
|
|
3632
|
-
props = __rest(_a, ["dataTestId", "
|
|
4107
|
+
props = __rest(_a, ["dataTestId", "id", "label", "hideLabel", "description", "error", "info", "isInvalid", "maxMenuHeight", "components", "disabled", "async", "value", "onChange", "isMulti", "classNamePrefix", "isLoading", "options", "onMenuOpen", "styles"]);
|
|
3633
4108
|
|
|
3634
4109
|
const hasError = !!error;
|
|
4110
|
+
const refContainer = React__default.useRef(null);
|
|
4111
|
+
const refPrefix = React__default.useRef(null);
|
|
4112
|
+
const [menuIsOpen, setMenuIsOpen] = React__default.useState(false);
|
|
4113
|
+
const [menuIsClosing, setMenuIsClosing] = React__default.useState(false);
|
|
4114
|
+
const refMenuIsEnabled = React__default.useRef(true);
|
|
3635
4115
|
const {
|
|
3636
4116
|
customStyles
|
|
3637
|
-
} = useCustomStyles(
|
|
3638
|
-
const
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
4117
|
+
} = useCustomStyles(refContainer, refPrefix, undefined, styles);
|
|
4118
|
+
const menuPlacement = "auto";
|
|
4119
|
+
const customComponents = useCustomComponents(components, disabled || false, menuIsClosing, refMenuIsEnabled, dataTestId, undefined);
|
|
4120
|
+
|
|
4121
|
+
const openMenuHandler = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
4122
|
+
onMenuOpen && onMenuOpen();
|
|
4123
|
+
|
|
4124
|
+
if (refMenuIsEnabled.current) {
|
|
4125
|
+
setMenuIsClosing(false);
|
|
4126
|
+
yield setMenuIsOpen(true);
|
|
4127
|
+
} else {
|
|
4128
|
+
refMenuIsEnabled.current = true;
|
|
4129
|
+
}
|
|
4130
|
+
});
|
|
4131
|
+
|
|
4132
|
+
const closeMenuHandler = () => {
|
|
4133
|
+
if (refMenuIsEnabled.current) {
|
|
4134
|
+
setMenuIsClosing(true);
|
|
4135
|
+
setTimeout(() => {
|
|
4136
|
+
setMenuIsOpen(false);
|
|
4137
|
+
}, 250);
|
|
4138
|
+
}
|
|
4139
|
+
};
|
|
4140
|
+
|
|
4141
|
+
const selectProps = {
|
|
4142
|
+
value,
|
|
4143
|
+
menuPlacement,
|
|
4144
|
+
maxMenuHeight,
|
|
4145
|
+
onChange,
|
|
4146
|
+
"aria-label": label,
|
|
4147
|
+
"data-testid": dataTestId,
|
|
4148
|
+
components: customComponents,
|
|
4149
|
+
styles: customStyles,
|
|
4150
|
+
tabSelectsValue: false,
|
|
4151
|
+
blurInputOnSelect: !isMulti,
|
|
4152
|
+
menuPortalTarget: document.body,
|
|
4153
|
+
isSearchable: disabled ? false : true,
|
|
4154
|
+
menuShouldBlockScroll: true,
|
|
4155
|
+
menuShouldScrollIntoView: true,
|
|
4156
|
+
openMenuOnFocus: disabled ? false : true,
|
|
4157
|
+
menuIsOpen: disabled ? false : menuIsOpen,
|
|
4158
|
+
openMenuOnClick: true,
|
|
4159
|
+
closeMenuOnSelect: false,
|
|
4160
|
+
isMulti: isMulti,
|
|
4161
|
+
classNamePrefix,
|
|
4162
|
+
isLoading,
|
|
4163
|
+
id
|
|
4164
|
+
};
|
|
4165
|
+
return jsx(SelectContainer$1, Object.assign({
|
|
3642
4166
|
label: label,
|
|
3643
4167
|
hideLabel: hideLabel,
|
|
3644
4168
|
id: id,
|
|
@@ -3646,88 +4170,185 @@ const CreatableSelect = _a => {
|
|
|
3646
4170
|
error: error,
|
|
3647
4171
|
description: description,
|
|
3648
4172
|
info: info,
|
|
3649
|
-
dataTestId: dataTestId
|
|
4173
|
+
dataTestId: dataTestId,
|
|
4174
|
+
isDisabled: disabled
|
|
3650
4175
|
}, {
|
|
3651
|
-
children:
|
|
3652
|
-
"aria-label": label,
|
|
3653
|
-
maxMenuHeight: maxMenuHeight,
|
|
3654
|
-
"data-testid": dataTestId,
|
|
3655
|
-
styles: customStyles,
|
|
3656
|
-
components: customComponents
|
|
3657
|
-
}, props)) : jsx(ReactCreatableSelect, Object.assign({
|
|
4176
|
+
children: async ? jsx(ReactAsyncCreatableSelect, Object.assign({
|
|
3658
4177
|
"aria-label": label,
|
|
3659
4178
|
maxMenuHeight: maxMenuHeight,
|
|
3660
4179
|
"data-testid": dataTestId,
|
|
3661
|
-
styles: customStyles,
|
|
3662
4180
|
components: customComponents
|
|
3663
|
-
}, props
|
|
4181
|
+
}, props, {
|
|
4182
|
+
onMenuOpen: () => {
|
|
4183
|
+
!disabled && openMenuHandler();
|
|
4184
|
+
},
|
|
4185
|
+
onMenuClose: () => {
|
|
4186
|
+
closeMenuHandler();
|
|
4187
|
+
}
|
|
4188
|
+
})) : jsx(ReactCreatableSelect, Object.assign({}, selectProps, {
|
|
4189
|
+
options: disabled ? getOrderedOptions(options, value).map(option => {
|
|
4190
|
+
return Object.assign(Object.assign({}, option), {
|
|
4191
|
+
disabled: true
|
|
4192
|
+
});
|
|
4193
|
+
}) : getOrderedOptions(options, value),
|
|
4194
|
+
isMulti: isMulti,
|
|
4195
|
+
onMenuOpen: () => {
|
|
4196
|
+
!disabled && openMenuHandler();
|
|
4197
|
+
},
|
|
4198
|
+
onMenuClose: () => {
|
|
4199
|
+
closeMenuHandler();
|
|
4200
|
+
}
|
|
4201
|
+
}))
|
|
3664
4202
|
}));
|
|
3665
4203
|
};
|
|
3666
4204
|
|
|
3667
4205
|
/**
|
|
3668
|
-
*
|
|
4206
|
+
* Selects are input components used to choose a value from a set.
|
|
3669
4207
|
*
|
|
3670
|
-
* @param {
|
|
4208
|
+
* @param {SelectProps} props - The props for the Select component
|
|
3671
4209
|
* @returns {JSX.Element} Select component
|
|
3672
4210
|
*/
|
|
3673
4211
|
|
|
3674
|
-
const Select =
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
4212
|
+
const Select = ({
|
|
4213
|
+
id,
|
|
4214
|
+
className,
|
|
4215
|
+
dataTestId = "select",
|
|
4216
|
+
prefix,
|
|
4217
|
+
async,
|
|
4218
|
+
dropdownIcon,
|
|
4219
|
+
maxMenuHeight = 200,
|
|
4220
|
+
label,
|
|
4221
|
+
hasError,
|
|
4222
|
+
disabled,
|
|
4223
|
+
isMulti,
|
|
4224
|
+
components,
|
|
4225
|
+
value,
|
|
4226
|
+
options,
|
|
4227
|
+
onChange,
|
|
4228
|
+
isLoading,
|
|
4229
|
+
classNamePrefix = "",
|
|
4230
|
+
onMenuOpen,
|
|
4231
|
+
onMenuClose,
|
|
4232
|
+
maxSelectedDisplayCount = undefined,
|
|
4233
|
+
isClearable = false,
|
|
4234
|
+
isSearchable = true,
|
|
4235
|
+
onMenuScrollToBottom,
|
|
4236
|
+
styles,
|
|
4237
|
+
filterOption,
|
|
4238
|
+
onInputChange
|
|
4239
|
+
}) => {
|
|
4240
|
+
const refContainer = React.useRef(null);
|
|
4241
|
+
const refPrefix = React.useRef(null);
|
|
3692
4242
|
const {
|
|
3693
4243
|
customStyles
|
|
3694
|
-
} = useCustomStyles(
|
|
3695
|
-
const
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
4244
|
+
} = useCustomStyles(refContainer, refPrefix, maxSelectedDisplayCount, styles);
|
|
4245
|
+
const [menuIsOpen, setMenuIsOpen] = React.useState(false);
|
|
4246
|
+
const [menuIsClosing, setMenuIsClosing] = React.useState(true);
|
|
4247
|
+
const refMenuIsEnabled = React.useRef(true);
|
|
4248
|
+
const customComponents = useCustomComponents(components, disabled || false, menuIsClosing, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon);
|
|
4249
|
+
const menuPlacement = "auto";
|
|
4250
|
+
|
|
4251
|
+
const openMenuHandler = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
4252
|
+
onMenuOpen && onMenuOpen();
|
|
4253
|
+
|
|
4254
|
+
if (refMenuIsEnabled.current) {
|
|
4255
|
+
setMenuIsClosing(false);
|
|
4256
|
+
yield setMenuIsOpen(true);
|
|
4257
|
+
} else {
|
|
4258
|
+
refMenuIsEnabled.current = true;
|
|
4259
|
+
}
|
|
4260
|
+
});
|
|
4261
|
+
|
|
4262
|
+
const closeMenuHandler = () => {
|
|
4263
|
+
if (refMenuIsEnabled.current) {
|
|
4264
|
+
setMenuIsClosing(true);
|
|
4265
|
+
setTimeout(() => {
|
|
4266
|
+
setMenuIsOpen(false);
|
|
4267
|
+
}, 250);
|
|
4268
|
+
}
|
|
4269
|
+
|
|
4270
|
+
onMenuClose && onMenuClose();
|
|
4271
|
+
};
|
|
4272
|
+
|
|
4273
|
+
const selectProps = {
|
|
4274
|
+
value,
|
|
4275
|
+
menuPlacement,
|
|
4276
|
+
maxMenuHeight,
|
|
4277
|
+
onChange,
|
|
4278
|
+
"aria-label": label,
|
|
4279
|
+
"data-testid": dataTestId,
|
|
4280
|
+
components: customComponents,
|
|
4281
|
+
styles: customStyles,
|
|
4282
|
+
tabSelectsValue: false,
|
|
4283
|
+
blurInputOnSelect: !isMulti,
|
|
4284
|
+
menuPortalTarget: document.body,
|
|
4285
|
+
isSearchable: disabled ? false : isSearchable,
|
|
4286
|
+
menuShouldBlockScroll: true,
|
|
4287
|
+
menuShouldScrollIntoView: true,
|
|
4288
|
+
openMenuOnFocus: true,
|
|
4289
|
+
menuIsOpen,
|
|
4290
|
+
openMenuOnClick: true,
|
|
4291
|
+
closeMenuOnSelect: false,
|
|
4292
|
+
isMulti,
|
|
4293
|
+
classNamePrefix,
|
|
4294
|
+
isLoading,
|
|
4295
|
+
isClearable,
|
|
4296
|
+
id,
|
|
4297
|
+
onMenuScrollToBottom,
|
|
4298
|
+
onInputChange
|
|
4299
|
+
};
|
|
4300
|
+
const orderedOptions = React.useMemo(() => {
|
|
4301
|
+
return disabled ? getOrderedOptions(options, value).map(option => {
|
|
4302
|
+
return Object.assign(Object.assign({}, option), {
|
|
4303
|
+
disabled: true
|
|
4304
|
+
});
|
|
4305
|
+
}) : getOrderedOptions(options, value);
|
|
4306
|
+
}, [options, value, disabled]);
|
|
4307
|
+
return jsxs(SelectContainer, Object.assign({
|
|
4308
|
+
ref: refContainer,
|
|
4309
|
+
className: className,
|
|
4310
|
+
"data-testid": dataTestId,
|
|
4311
|
+
"$hasError": hasError,
|
|
4312
|
+
"$isDisabled": disabled
|
|
3707
4313
|
}, {
|
|
3708
|
-
children:
|
|
3709
|
-
"
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
:
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
:
|
|
3728
|
-
|
|
4314
|
+
children: [prefix !== undefined && jsx(SelectPrefix, Object.assign({
|
|
4315
|
+
"data-testid": `${dataTestId}-prefix`,
|
|
4316
|
+
ref: refPrefix
|
|
4317
|
+
}, {
|
|
4318
|
+
children: prefix
|
|
4319
|
+
})), async ? jsx(ReactAsyncSelect, Object.assign({}, selectProps, async, {
|
|
4320
|
+
onMenuOpen: () => {
|
|
4321
|
+
openMenuHandler();
|
|
4322
|
+
},
|
|
4323
|
+
onMenuClose: () => {
|
|
4324
|
+
closeMenuHandler();
|
|
4325
|
+
}
|
|
4326
|
+
})) : jsx(ReactSelect, Object.assign({}, selectProps, {
|
|
4327
|
+
options: filterOption ? orderedOptions : options,
|
|
4328
|
+
hideSelectedOptions: false,
|
|
4329
|
+
isMulti: isMulti,
|
|
4330
|
+
onMenuOpen: () => {
|
|
4331
|
+
openMenuHandler();
|
|
4332
|
+
},
|
|
4333
|
+
onMenuClose: () => {
|
|
4334
|
+
closeMenuHandler();
|
|
4335
|
+
}
|
|
4336
|
+
}))]
|
|
3729
4337
|
}));
|
|
3730
4338
|
};
|
|
4339
|
+
const SelectPrefix = tw.div`
|
|
4340
|
+
tu-select__prefix
|
|
4341
|
+
`;
|
|
4342
|
+
const SelectContainer = tw.div`
|
|
4343
|
+
tu-select
|
|
4344
|
+
${({
|
|
4345
|
+
$hasError
|
|
4346
|
+
}) => $hasError ? tws`tu-select--invalid` : null}
|
|
4347
|
+
${({
|
|
4348
|
+
$isDisabled
|
|
4349
|
+
}) => $isDisabled ? tws`tu-select--disabled` : null}
|
|
4350
|
+
`;
|
|
4351
|
+
Select.displayName = "Select";
|
|
3731
4352
|
|
|
3732
4353
|
/**
|
|
3733
4354
|
* Display placeholder lines before the data gets loaded to reduce load-time frustration.
|
|
@@ -4548,4 +5169,4 @@ const Layout = tw.div`
|
|
|
4548
5169
|
tu-layout-TwoColumnLayout
|
|
4549
5170
|
`;
|
|
4550
5171
|
|
|
4551
|
-
export { Alert, AnimatedPopover, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$5 as Label, LegendItem, MenuButton, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, NumberField, NumberInput, PageHeading, PopoverLifecycle, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Select, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, activityColors, colors, criticalityColors, docs, generalColors, intentColors, useContainerProps, useCustomComponents,
|
|
5172
|
+
export { Alert, AnimatedPopover, Badge, BaseInput, Button, Card, CardBody, CardFooter, CardHeader, Chart, Checkbox, Collapse, CopyableText, CreatableSelect, DateField, DateInput, DayPicker, DayPickerPopover, DayRangePicker, DensityContainer, FilterListMapLayout, FormGroup, FullWidthRepeatingLayout, GridArea, Heading, Icon$1 as Icon, IconButton, Indicator$1 as Indicator, IntrinsicallyResponsiveGrid, Label$5 as Label, LegendItem, MenuButton, MenuItem, MenuList, MinTopFullContentLayout, Modal, ModalBackdrop, MultiSelectMenuItem, NumberField, NumberInput, PageHeading, PopoverLifecycle, PopoverList, PopoverListItem, PopoverTitle, Prompt, ROLE_CARD, RadioGroup, RadioItem, Select, SingleSelectMenuItem, SkeletonLines, Spacer, Spinner, StarButton, Tag, Text, TextArea, TextAreaField, TextField, TextInput, Timeline, TimelineElement, Tip, TitleNavContentLayout, Toggle, Tooltip, TwoColumnLayout, activityColors, colors, criticalityColors, docs, generalColors, getOrderedOptions, intentColors, isMultiValue, useContainerProps, useCustomComponents, useDebounce, useLocalStorage, useModal, usePopover, usePrompt, useTimeout };
|