@trackunit/react-components 0.0.123 → 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.
Files changed (30) hide show
  1. package/common/CommonProps.d.ts +1 -0
  2. package/components/Badge/Badge.d.ts +1 -1
  3. package/components/BaseInput/BaseInput.d.ts +1 -1
  4. package/components/DayPicker/DayPickerPopover.d.ts +3 -2
  5. package/components/Icon/Icon.d.ts +4 -4
  6. package/components/Menu/MenuItem.d.ts +2 -1
  7. package/components/Select/CreatableSelect.d.ts +32 -4
  8. package/components/Select/FieldContainer.d.ts +3 -3
  9. package/components/Select/Select.d.ts +132 -5
  10. package/components/Select/{Select/TagWithWidth.d.ts → TagWithWidth.d.ts} +1 -1
  11. package/components/Select/{Select/TagsContainer.d.ts → TagsContainer.d.ts} +0 -0
  12. package/components/Select/index.d.ts +4 -0
  13. package/components/Select/shared.d.ts +10 -67
  14. package/components/Select/useCustomComponents.d.ts +19 -0
  15. package/components/Select/useCustomStyles.d.ts +14 -0
  16. package/components/Spinner/Spinner.d.ts +2 -3
  17. package/components/Tag/Tag.d.ts +1 -1
  18. package/components/Text/Text.d.ts +5 -6
  19. package/components/Toggle/Toggle.d.ts +1 -1
  20. package/components/buttons/Button/Button.d.ts +3 -2
  21. package/components/buttons/IconButton/IconButton.d.ts +3 -2
  22. package/components/buttons/shared/ButtonProps.d.ts +2 -3
  23. package/components/buttons/shared/helpers.d.ts +3 -2
  24. package/index.css +1 -1
  25. package/index.js +841 -234
  26. package/package.json +1 -1
  27. package/components/Select/Select/Select.d.ts +0 -122
  28. package/components/Select/Select/useCustomComponents.d.ts +0 -20
  29. package/components/Select/Select/useCustomStyles.d.ts +0 -10
  30. 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
  /**
@@ -98,13 +109,13 @@ function __rest(s, e) {
98
109
 
99
110
  const Spinner = ({
100
111
  mode = "light",
101
- size = "regular",
112
+ size = "medium",
102
113
  centered = false,
103
114
  className,
104
115
  containerClassName,
105
116
  dataTestId
106
117
  }) => {
107
- return jsx(Container$8, Object.assign({
118
+ return jsx(Container$a, Object.assign({
108
119
  "$mode": mode,
109
120
  "$centered": centered,
110
121
  className: containerClassName
@@ -129,7 +140,7 @@ const getSpinnerStyles = () => ({
129
140
  case "large":
130
141
  return tws`tu-spinner--large`;
131
142
 
132
- case "regular":
143
+ case "medium":
133
144
  default:
134
145
  return;
135
146
  }
@@ -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$8 = tw.div`
154
+ const Container$a = tw.div`
144
155
  tu-spinner--container
145
156
  ${p => p.$centered ? tws`tu-spinner--container-centered` : null}
146
157
  `;
@@ -214,7 +225,7 @@ const Button = React.forwardRef((_a, ref) => {
214
225
  intent = "primary",
215
226
  variant = "filled",
216
227
  type = "button",
217
- size = "normal",
228
+ size = "medium",
218
229
  square = false,
219
230
  dataTestId,
220
231
  title,
@@ -335,9 +346,9 @@ const activityColors = {
335
346
  const colors = Object.assign(Object.assign(Object.assign(Object.assign({}, generalColors), intentColors), criticalityColors), activityColors);
336
347
 
337
348
  const IconSizeClassMap = {
338
- small: tws`w-4`,
339
- normal: tws`w-5`,
340
- large: tws`w-6` // 24x24px
349
+ small: tws`tu-icon--small`,
350
+ medium: tws`tu-icon--medium`,
351
+ large: tws`tu-icon--large` // 24x24px
341
352
 
342
353
  };
343
354
  /**
@@ -398,72 +409,58 @@ const Icon$1 = ({
398
409
  }));
399
410
  };
400
411
  const LoadingDot = tw.span`
401
- relative
402
- aspect-square
403
-
404
- after:content-['']
405
- after:absolute
406
- after:h-2
407
- after:w-2
408
- after:bg-current
409
- after:rounded-full
410
- after:inset-1/2
411
- after:-translate-x-1/2
412
- after:-translate-y-1/2
413
- after:opacity-50
412
+ tu-loading-dot
414
413
  `;
415
414
  const Root$3 = tw.span`
416
- inline
417
- relative
418
-
415
+ tu-icon
419
416
  ${({
420
417
  $color
421
418
  }) => {
422
419
  switch ($color) {
423
420
  case colors.PRIMARY:
424
- return tws`text-primary-600`;
421
+ return tws`tu-icon--primary`;
425
422
 
426
423
  case colors.ACCENT:
427
- return tws`text-accent-600`;
424
+ return tws`tu-icon--accent`;
428
425
 
429
426
  case colors.NEUTRAL:
430
- return tws`text-neutral-600`;
427
+ return tws`tu-icon--neutral`;
431
428
 
432
429
  case colors.INFO:
433
- return tws`text-info-600`;
430
+ return tws`tu-icon--info`;
434
431
 
435
432
  case colors.SUCCESS:
436
- return tws`text-success-600`;
433
+ return tws`tu-icon--success`;
437
434
 
438
435
  case colors.WARNING:
439
- return tws`text-warning-600`;
436
+ return tws`tu-icon--warning`;
440
437
 
441
438
  case colors.DANGER:
442
- return tws`text-danger-600`;
439
+ return tws`tu-icon--danger`;
443
440
 
444
441
  case colors.GOOD:
445
- return tws`text-good-600`;
442
+ return tws`tu-icon--good`;
446
443
 
447
444
  case colors.LOW:
448
- return tws`text-low-600`;
445
+ return tws`tu-icon--low`;
449
446
 
450
447
  case colors.CRITICAL:
451
- return tws`text-critical-600`;
448
+ return tws`tu-icon--critical`;
452
449
 
453
450
  case colors.WORKING:
454
- return tws`text-working-600`;
451
+ return tws`tu-icon--working`;
455
452
 
456
453
  case colors.IDLE:
457
- return tws`text-idle-600`;
454
+ return tws`tu-icon--idle`;
458
455
 
459
456
  case colors.STOPPED:
460
- return tws`text-stopped-600`;
457
+ return tws`tu-icon--stopped`;
461
458
 
462
459
  case colors.UNKNOWN:
463
- return tws`text-unknown-600`;
460
+ return tws`tu-icon--unknown`;
464
461
 
465
462
  default:
466
- return "text-current";
463
+ return "tu-icon--default";
467
464
  }
468
465
  }}
469
466
  `;
@@ -516,9 +513,9 @@ const CustomIcon = tw(Icon$1)`
516
513
  const Text = ({
517
514
  children,
518
515
  type = "p",
519
- size = "default",
516
+ size = "medium",
520
517
  align = "left",
521
- weight = "default",
518
+ weight = "normal",
522
519
  underline = false,
523
520
  inverted = false,
524
521
  subtle = false,
@@ -664,7 +661,7 @@ const Alert = ({
664
661
  }, {
665
662
  children: title !== null && title !== void 0 ? title : children
666
663
  })), children && jsx(Description$2, Object.assign({
667
- weight: !title ? "bold" : "default",
664
+ weight: !title ? "bold" : "normal",
668
665
  "$hasTitle": !!title
669
666
  }, {
670
667
  children: children
@@ -675,7 +672,7 @@ const Alert = ({
675
672
  }, {
676
673
  children: title !== null && title !== void 0 ? title : children
677
674
  })), children && jsx(Description$2, Object.assign({
678
- weight: !title ? "bold" : "default",
675
+ weight: !title ? "bold" : "normal",
679
676
  "$hasTitle": !!title
680
677
  }, {
681
678
  children: children
@@ -686,7 +683,7 @@ const Alert = ({
686
683
  ref && ref.current && ref.current.scrollIntoView && ref.current.scrollIntoView();
687
684
  }
688
685
  }, [ref, autoScroll]);
689
- return jsxs(Container$7, Object.assign({
686
+ return jsxs(Container$9, Object.assign({
690
687
  "$intent": intent,
691
688
  className: className,
692
689
  "data-testid": dataTestId,
@@ -774,7 +771,7 @@ const getBackgroundColor = () => ({
774
771
  return colors[$intent];
775
772
  };
776
773
 
777
- const Container$7 = tw.div`
774
+ const Container$9 = tw.div`
778
775
  tu-alert
779
776
  ${p => p.$inline ? tws`tu-alert--inline` : null}
780
777
  ${getBackgroundColor()}
@@ -816,7 +813,7 @@ const Badge = _a => {
816
813
  max,
817
814
  hideZero = false,
818
815
  dataTestId,
819
- size = "default"
816
+ size = "medium"
820
817
  } = _a;
821
818
  __rest(_a, ["color", "subtle", "className", "count", "max", "hideZero", "dataTestId", "size"]);
822
819
 
@@ -843,7 +840,7 @@ const getSizeModifierClass$1 = () => ({
843
840
  }) => {
844
841
  const sizeModifierClass = {
845
842
  large: tws`tu-badge--large`,
846
- default: ""
843
+ medium: ""
847
844
  };
848
845
  return sizeModifierClass[$size];
849
846
  };
@@ -899,7 +896,7 @@ const BaseInput = React.forwardRef((_a, ref) => {
899
896
  addonBefore,
900
897
  addonAfter,
901
898
  actions,
902
- fieldSize = "default"
899
+ fieldSize = "medium"
903
900
  } = _a,
904
901
  rest = __rest(_a, ["className", "isInvalid", "dataTestId", "prefix", "suffix", "addonBefore", "addonAfter", "actions", "fieldSize"]);
905
902
 
@@ -1262,7 +1259,7 @@ const CardHeader = ({
1262
1259
  className: className,
1263
1260
  "$density": density
1264
1261
  }, {
1265
- children: jsxs(Container$6, {
1262
+ children: jsxs(Container$8, {
1266
1263
  children: [jsxs("div", {
1267
1264
  children: [jsxs(HeadingContainer, {
1268
1265
  children: [jsx(Heading, Object.assign({
@@ -1292,7 +1289,7 @@ const CardHeader = ({
1292
1289
  const BottomBorderedDensityContainer = tw(DensityContainer)`
1293
1290
  tu-card__header-density-container
1294
1291
  `;
1295
- const Container$6 = tw.div`
1292
+ const Container$8 = tw.div`
1296
1293
  tu-card__header
1297
1294
  `;
1298
1295
  const HeadingContainer = tw.div`
@@ -1633,7 +1630,7 @@ const Collapse = ({
1633
1630
  size: "small",
1634
1631
  "$expanded": expanded
1635
1632
  }),
1636
- size: "normal",
1633
+ size: "medium",
1637
1634
  variant: "transparent",
1638
1635
  intent: "secondary"
1639
1636
  })]
@@ -2049,7 +2046,7 @@ const DateInput = forwardRef((_a, ref) => {
2049
2046
  suffix: jsx(Icon$1, {
2050
2047
  dataTestId: "calendar",
2051
2048
  name: "CalendarIcon",
2052
- size: "normal",
2049
+ size: "medium",
2053
2050
  type: "solid",
2054
2051
  onClick: !disabled ? onShow : undefined,
2055
2052
  forwardedRef: targetRef
@@ -2143,7 +2140,7 @@ const PopoverListItem = ({
2143
2140
  children: [prefix && jsx("div", {
2144
2141
  children: prefix
2145
2142
  }), jsx(StyledText$2, Object.assign({
2146
- weight: selected ? "bold" : "default",
2143
+ weight: selected ? "bold" : "normal",
2147
2144
  "$selected": selected
2148
2145
  }, {
2149
2146
  children: children
@@ -2194,7 +2191,7 @@ const PopoverTitle = ({
2194
2191
  className,
2195
2192
  dataTestId
2196
2193
  }) => {
2197
- return jsxs(Container$5, Object.assign({
2194
+ return jsxs(Container$7, Object.assign({
2198
2195
  "$divider": divider,
2199
2196
  className: className,
2200
2197
  "data-testid": dataTestId
@@ -2210,7 +2207,7 @@ const PopoverTitle = ({
2210
2207
  })), action]
2211
2208
  }));
2212
2209
  };
2213
- const Container$5 = tw.div`
2210
+ const Container$7 = tw.div`
2214
2211
  tu-popover-title-container
2215
2212
  ${p => p.$divider && `tu-popover-title-container--divider`}
2216
2213
  `;
@@ -2259,7 +2256,7 @@ const Tooltip = ({
2259
2256
  "data-testid": dataTestId && `${dataTestId}-parent`
2260
2257
  }, {
2261
2258
  children: children
2262
- })), !disabled && jsx(Container$4, Object.assign({
2259
+ })), !disabled && jsx(Container$6, Object.assign({
2263
2260
  ref: popoverRef,
2264
2261
  onRequestClose: onHide,
2265
2262
  enterDelay: 450
@@ -2283,7 +2280,7 @@ const Tooltip = ({
2283
2280
  const Flex$1 = tw.div`
2284
2281
  inline-flex
2285
2282
  `;
2286
- const Container$4 = tw(AnimatedPopover)`
2283
+ const Container$6 = tw(AnimatedPopover)`
2287
2284
  tu-tooltip__container
2288
2285
  `;
2289
2286
  const Content = tw.div`
@@ -2320,7 +2317,7 @@ const Tip = _a => {
2320
2317
  }, {
2321
2318
  children: jsx(Icon$1, Object.assign({
2322
2319
  name: "QuestionMarkCircleIcon",
2323
- size: "normal",
2320
+ size: "medium",
2324
2321
  dataTestId: `${dataTestId}-icon`
2325
2322
  }, iconProps))
2326
2323
  }))
@@ -2569,7 +2566,7 @@ const Indicator$1 = _a => {
2569
2566
  } = _a,
2570
2567
  rest = __rest(_a, ["dataTestId", "icon", "label", "color", "withBackground"]);
2571
2568
 
2572
- return jsxs(Container$3, Object.assign({
2569
+ return jsxs(Container$5, Object.assign({
2573
2570
  "$color": color,
2574
2571
  "data-testid": dataTestId
2575
2572
  }, rest, {
@@ -2585,7 +2582,7 @@ const Indicator$1 = _a => {
2585
2582
  }))]
2586
2583
  }));
2587
2584
  };
2588
- const Container$3 = tw.div`
2585
+ const Container$5 = tw.div`
2589
2586
  tu-indicator
2590
2587
  ${({
2591
2588
  $color
@@ -2762,7 +2759,7 @@ const MenuItem = ({
2762
2759
  className,
2763
2760
  dataTestId
2764
2761
  });
2765
- return jsxs(Container$2, Object.assign({}, containerProps, {
2762
+ return jsxs(Container$4, Object.assign({}, containerProps, {
2766
2763
  onClick: e => {
2767
2764
  e.stopPropagation();
2768
2765
  onClick && onClick(e);
@@ -2776,16 +2773,18 @@ const MenuItem = ({
2776
2773
  "$selected": selected
2777
2774
  }, {
2778
2775
  children: prefix
2779
- })), jsx(Label$2, {
2776
+ })), jsx(Label$2, Object.assign({
2777
+ "data-testid": dataTestId + "-label"
2778
+ }, {
2780
2779
  children: label
2781
- }), icon && jsx(Icon, Object.assign({
2780
+ })), icon && jsx(Icon, Object.assign({
2782
2781
  "$selected": selected
2783
2782
  }, {
2784
2783
  children: icon
2785
2784
  }))]
2786
2785
  }));
2787
2786
  };
2788
- const Container$2 = tw.div`
2787
+ const Container$4 = tw.div`
2789
2788
  group tu-menu-item
2790
2789
  ${({
2791
2790
  $selected
@@ -2836,7 +2835,7 @@ const MenuList = _a => {
2836
2835
  dataTestId
2837
2836
  }, args));
2838
2837
  return jsx(Wrapper, {
2839
- children: jsx(Container$1, Object.assign({}, containerProps, {
2838
+ children: jsx(Container$3, Object.assign({}, containerProps, {
2840
2839
  style: width ? {
2841
2840
  width
2842
2841
  } : undefined,
@@ -2858,7 +2857,7 @@ const MenuList = _a => {
2858
2857
  const Wrapper = tw.div`
2859
2858
  tu-menu-list__wrapper
2860
2859
  `;
2861
- const Container$1 = tw.div`
2860
+ const Container$3 = tw.div`
2862
2861
  tu-menu-list
2863
2862
  `;
2864
2863
  const Divider = tw.div`
@@ -3158,7 +3157,7 @@ const Tag = React.forwardRef((_a, ref) => {
3158
3157
  className,
3159
3158
  dataTestId,
3160
3159
  children,
3161
- size = "default",
3160
+ size = "medium",
3162
3161
  onClose,
3163
3162
  color = "primary"
3164
3163
  } = _a;
@@ -3167,7 +3166,7 @@ const Tag = React.forwardRef((_a, ref) => {
3167
3166
  return jsxs(StyledText, Object.assign({
3168
3167
  className: className,
3169
3168
  "$size": size,
3170
- "data-testid": dataTestId,
3169
+ "data-testid": `${dataTestId}-tag`,
3171
3170
  "$as": "span",
3172
3171
  "$color": color,
3173
3172
  "$withXIcon": !!onClose,
@@ -3182,9 +3181,9 @@ const Tag = React.forwardRef((_a, ref) => {
3182
3181
  dataTestId: dataTestId + "Icon",
3183
3182
  type: "solid",
3184
3183
  style: {
3185
- "-webkit-transition": "-webkit-transform 0.150s"
3184
+ WebkitTransition: "-webkit-transform 0.150s"
3186
3185
  },
3187
- className: size === "default" ? tws`tu-tag__icon` : tws`tu-tag__icon tu-tag__icon--small`
3186
+ className: size === "medium" ? tws`tu-tag__icon` : tws`tu-tag__icon tu-tag__icon--small`
3188
3187
  })
3189
3188
  }))]
3190
3189
  }));
@@ -3195,7 +3194,7 @@ const getSizeModifierClass = () => ({
3195
3194
  $withXIcon
3196
3195
  }) => {
3197
3196
  const tagSizeModifierClass = {
3198
- default: $withXIcon ? tws`tu-tag--with-icon ` : tws` `,
3197
+ medium: $withXIcon ? tws`tu-tag--with-icon ` : tws` `,
3199
3198
  small: $withXIcon ? tws`tu-tag--small tu-tag--with-icon` : tws`tu-tag--small`
3200
3199
  };
3201
3200
  return tagSizeModifierClass[$size];
@@ -3489,7 +3488,7 @@ tu-radioitem__description
3489
3488
  * @returns {JSX.Element} SelectContainer component
3490
3489
  */
3491
3490
 
3492
- const SelectContainer = ({
3491
+ const SelectContainer$1 = ({
3493
3492
  children,
3494
3493
  label,
3495
3494
  hideLabel,
@@ -3498,10 +3497,13 @@ const SelectContainer = ({
3498
3497
  error,
3499
3498
  description,
3500
3499
  info,
3501
- dataTestId
3500
+ dataTestId,
3501
+ isDisabled
3502
3502
  }) => {
3503
- return jsxs(Container, Object.assign({
3504
- "data-testid": dataTestId
3503
+ return jsxs(Container$2, Object.assign({
3504
+ "data-testid": dataTestId,
3505
+ "$hasError": hasError,
3506
+ "$isDisabled": isDisabled
3505
3507
  }, {
3506
3508
  children: [label && !hideLabel && jsx(Label$5, Object.assign({
3507
3509
  htmlFor: id
@@ -3515,123 +3517,573 @@ const SelectContainer = ({
3515
3517
  }))]
3516
3518
  }));
3517
3519
  };
3518
- const Container = tw.label`
3519
- 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}
3520
3529
  `;
3521
3530
  const InformativeText = tw(Text)`
3522
3531
  tu-informative-text
3523
3532
  ${p => p.$hasError ? `tu-informative-text--error` : null}
3524
3533
  `;
3525
3534
 
3526
- const getSelectHeight = size => {
3527
- const tokens = {
3528
- small: "var(--spacing-8)",
3529
- default: "var(--spacing-10)"
3530
- };
3531
- return tokens[size];
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 || [];
3532
3585
  };
3586
+
3533
3587
  /**
3534
- * The useCustomStyles hook for getting trackunit specific styling on react-select.
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
3535
3589
  *
3536
- * @param {StylesConfig} styles -
3537
- * @param {boolean} hasError -
3538
- * @param {boolean} isInvalid -
3539
- * @param {SelectSize} size -
3540
- * @returns {{StylesConfig}} useCustomStyles hook return
3590
+ * @param {SelectMenuItemProps} props - The props for the SingleSelectMenuItem
3591
+ * @returns {JSX.Element} SingleSelectMenuItem
3541
3592
  */
3542
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
+ */
3543
3621
 
3544
- const useCustomStyles = (styles, hasError, isInvalid, size) => {
3545
- const customStyles = React.useMemo(() => {
3546
- return Object.assign({
3547
- control: (base, state) => Object.assign(Object.assign({}, base), {
3548
- minHeight: getSelectHeight(size),
3549
- borderRadius: "var(--spacing-1)",
3550
- backgroundColor: state.isDisabled ? "rgb(var(--color-neutral-50))" : "#FFF",
3551
- border: "none",
3552
- fontSize: "0.875rem",
3553
- color: state.isDisabled ? "rgb(var(--color-neutral-50))" : "#1a1b1c",
3554
- cursor: state.isDisabled ? "not-allowed" : "pointer",
3555
- boxShadow: state.isFocused ? `inset 0 0 0 2px ${hasError ? "rgb(var(--color-danger-600))" : "rgb(var(--color-primary-600))"}, 0 0 0 2px ${hasError ? "rgb(var(--color-danger-100))" : "rgb(var(--color-primary-300))"}` : `inset 0 0 0 2px ${hasError ? "rgb(var(--color-danger-500))" : isInvalid ? "rgb(var(--color-warning-300))" : "rgb(var(--color-neutral-300))"}`,
3556
- "&:hover": {
3557
- boxShadow: state.isDisabled ? "" : `inset 0 0 0 2px ${hasError ? "rgb(var(--color-danger-600))" : "rgb(var(--color-neutral-400))"}`
3558
- }
3559
- }),
3560
- singleValue: base => Object.assign(Object.assign({}, base), {
3561
- color: "#1a1b1c"
3562
- }),
3563
- multiValue: base => Object.assign(Object.assign({}, base), {
3564
- backgroundColor: "rgb(var(--color-neutral-100))"
3565
- }),
3566
- multiValueLabel: base => Object.assign(Object.assign({}, base), {
3567
- fontWeight: 600,
3568
- fontSize: "rgb(var(--color-neutral-400))",
3569
- color: "#1a1b1c"
3570
- }),
3571
- indicatorsContainer: base => Object.assign(Object.assign({}, base), {
3572
- color: "rgb(var(--color-neutral-300))"
3573
- }),
3574
- menu: base => Object.assign(Object.assign({}, base), {
3575
- borderRadius: "var(--spacing-1)",
3576
- marginTop: "var(--spacing-1)",
3577
- fontSize: "var(--font-size-sm)",
3578
- zIndex: "var(--z-popover)"
3579
- }),
3580
- input: base => Object.assign(Object.assign({}, base), {
3581
- color: "#1a1b1c"
3582
- }),
3583
- placeholder: base => Object.assign(Object.assign({}, base), {
3584
- color: "rgb(var(--color-neutral-500))"
3585
- }),
3586
- option: base => Object.assign(Object.assign({}, base), {
3587
- cursor: "pointer"
3588
- }),
3589
- menuPortal: base => Object.assign(Object.assign({}, base), {
3590
- zIndex: "var(--z-popover)"
3591
- })
3592
- }, styles);
3593
- }, [styles, size, hasError, isInvalid]);
3594
- return {
3595
- customStyles
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
+ }
3596
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
+ }));
3597
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
+
3598
3800
  /**
3599
- * The useCustomComponents hook for getting trackunit specific components on react-select.
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.
3600
3803
  *
3601
- * @param {SelectComponents} components -
3602
- * @returns {*}} useCustomComponents hook return
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
3603
3814
  */
3604
3815
 
3605
- const useCustomComponents = components => {
3816
+ const useCustomComponents = (componentsProps, disabled, menuIsClosing, refMenuIsEnabled, dataTestId, maxSelectedDisplayCount, dropdownIcon) => {
3606
3817
  const customComponents = React.useMemo(() => {
3607
3818
  return Object.assign({
3608
- LoadingIndicator: loadingIndicatorProps => {
3609
- const loadingIndicatorStyles = loadingIndicatorProps === null || loadingIndicatorProps === void 0 ? void 0 : loadingIndicatorProps.getStyles("loadingIndicator", loadingIndicatorProps);
3610
- delete loadingIndicatorStyles.label;
3611
- return jsx("div", Object.assign({
3612
- style: loadingIndicatorStyles
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
+ })
3613
3960
  }, {
3614
- children: jsx(Spinner, {})
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
+ }))
3615
3967
  }));
3616
3968
  }
3617
- }, components);
3618
- }, [components]);
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]);
3619
4072
  return {
3620
- customComponents
4073
+ customStyles
3621
4074
  };
3622
4075
  };
3623
4076
 
3624
4077
  /**
3625
4078
  * The CreatableSelect component.
3626
4079
  *
3627
- * @param {ISelectProps} props - The props for the CreatableSelect component
4080
+ * @param {CreateableSelectProps} props - The props for the CreatableSelect component
3628
4081
  * @returns {JSX.Element} CreatableSelect component
3629
4082
  */
3630
4083
 
3631
4084
  const CreatableSelect = _a => {
3632
4085
  var {
3633
- dataTestId,
3634
- size = "default",
4086
+ dataTestId = "createableSelect",
3635
4087
  id,
3636
4088
  label,
3637
4089
  hideLabel,
@@ -3640,19 +4092,77 @@ const CreatableSelect = _a => {
3640
4092
  info,
3641
4093
  isInvalid,
3642
4094
  maxMenuHeight = 308,
3643
- styles,
3644
- components
4095
+ components,
4096
+ disabled,
4097
+ async,
4098
+ value,
4099
+ onChange,
4100
+ isMulti,
4101
+ classNamePrefix,
4102
+ isLoading,
4103
+ options,
4104
+ onMenuOpen,
4105
+ styles
3645
4106
  } = _a,
3646
- props = __rest(_a, ["dataTestId", "size", "id", "label", "hideLabel", "description", "error", "info", "isInvalid", "maxMenuHeight", "styles", "components"]);
4107
+ props = __rest(_a, ["dataTestId", "id", "label", "hideLabel", "description", "error", "info", "isInvalid", "maxMenuHeight", "components", "disabled", "async", "value", "onChange", "isMulti", "classNamePrefix", "isLoading", "options", "onMenuOpen", "styles"]);
3647
4108
 
3648
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);
3649
4115
  const {
3650
4116
  customStyles
3651
- } = useCustomStyles(styles, hasError, isInvalid, size);
3652
- const {
3653
- customComponents
3654
- } = useCustomComponents(components);
3655
- return jsx(SelectContainer, Object.assign({
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({
3656
4166
  label: label,
3657
4167
  hideLabel: hideLabel,
3658
4168
  id: id,
@@ -3660,88 +4170,185 @@ const CreatableSelect = _a => {
3660
4170
  error: error,
3661
4171
  description: description,
3662
4172
  info: info,
3663
- dataTestId: dataTestId
4173
+ dataTestId: dataTestId,
4174
+ isDisabled: disabled
3664
4175
  }, {
3665
- children: props.isAsync ? jsx(ReactAsyncCreatableSelect, Object.assign({
3666
- "aria-label": label,
3667
- maxMenuHeight: maxMenuHeight,
3668
- "data-testid": dataTestId,
3669
- styles: customStyles,
3670
- components: customComponents
3671
- }, props)) : jsx(ReactCreatableSelect, Object.assign({
4176
+ children: async ? jsx(ReactAsyncCreatableSelect, Object.assign({
3672
4177
  "aria-label": label,
3673
4178
  maxMenuHeight: maxMenuHeight,
3674
4179
  "data-testid": dataTestId,
3675
- styles: customStyles,
3676
4180
  components: customComponents
3677
- }, 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
+ }))
3678
4202
  }));
3679
4203
  };
3680
4204
 
3681
4205
  /**
3682
- * The Select component.
4206
+ * Selects are input components used to choose a value from a set.
3683
4207
  *
3684
- * @param {ISelectProps} props - The props for the Select component
4208
+ * @param {SelectProps} props - The props for the Select component
3685
4209
  * @returns {JSX.Element} Select component
3686
4210
  */
3687
4211
 
3688
- const Select = _a => {
3689
- var {
3690
- dataTestId,
3691
- size = "default",
3692
- id,
3693
- label,
3694
- hideLabel,
3695
- description,
3696
- error,
3697
- info,
3698
- isInvalid,
3699
- maxMenuHeight = 308,
3700
- styles,
3701
- components
3702
- } = _a,
3703
- props = __rest(_a, ["dataTestId", "size", "id", "label", "hideLabel", "description", "error", "info", "isInvalid", "maxMenuHeight", "styles", "components"]);
3704
-
3705
- const hasError = !!error;
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);
3706
4242
  const {
3707
4243
  customStyles
3708
- } = useCustomStyles(styles, hasError, isInvalid, size);
3709
- const {
3710
- customComponents
3711
- } = useCustomComponents(components);
3712
- return jsx(SelectContainer, Object.assign({
3713
- label: label,
3714
- hideLabel: hideLabel,
3715
- id: id,
3716
- hasError: hasError,
3717
- error: error,
3718
- description: description,
3719
- info: info,
3720
- dataTestId: dataTestId
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
3721
4313
  }, {
3722
- children: props.isAsync ? jsx(ReactAsyncSelect, Object.assign({
3723
- "aria-label": label,
3724
- maxMenuHeight: maxMenuHeight,
3725
- "data-testid": dataTestId,
3726
- styles: customStyles,
3727
- menuPortalTarget: document.body,
3728
- components: customComponents,
3729
- menuPlacement: "auto",
3730
- menuShouldBlockScroll //Temp fix. See https://github.com/JedWatson/react-select/issues/4088
3731
- : true
3732
- }, props)) : jsx(ReactSelect, Object.assign({
3733
- "aria-label": label,
3734
- maxMenuHeight: maxMenuHeight,
3735
- "data-testid": dataTestId,
3736
- styles: customStyles,
3737
- menuPortalTarget: document.body,
3738
- components: customComponents,
3739
- menuPlacement: "auto",
3740
- menuShouldBlockScroll // Temp fix.
3741
- : true
3742
- }, props))
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
+ }))]
3743
4337
  }));
3744
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";
3745
4352
 
3746
4353
  /**
3747
4354
  * Display placeholder lines before the data gets loaded to reduce load-time frustration.
@@ -4097,7 +4704,7 @@ const Toggle = React.forwardRef(({
4097
4704
  toggled = false,
4098
4705
  onChange,
4099
4706
  disabled,
4100
- size = "default",
4707
+ size = "medium",
4101
4708
  id,
4102
4709
  tabIndex,
4103
4710
  required,
@@ -4180,7 +4787,7 @@ tu-toggle__switch-container
4180
4787
  }) => $disabled && tws`tu-toggle--disabled`};
4181
4788
  ${({
4182
4789
  $size
4183
- }) => $size === "small" ? tws`tu-toggle--small` : tws`tu-toggle--default`};
4790
+ }) => $size === "small" ? tws`tu-toggle--small` : tws`tu-toggle--medium`};
4184
4791
  ${({
4185
4792
  $toggled
4186
4793
  }) => $toggled && tws`tu-toggle--toggled`}`;
@@ -4562,4 +5169,4 @@ const Layout = tw.div`
4562
5169
  tu-layout-TwoColumnLayout
4563
5170
  `;
4564
5171
 
4565
- 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, useCustomStyles, useDebounce, useLocalStorage, useModal, usePopover, usePrompt, useTimeout };
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 };