@transferwise/components 46.6.0 → 46.8.0

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 (148) hide show
  1. package/build/index.esm.js +290 -346
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +290 -345
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +107 -17
  6. package/build/styles/inputs/Input.css +0 -4
  7. package/build/styles/inputs/SelectInput.css +6 -1
  8. package/build/styles/inputs/TextArea.css +0 -4
  9. package/build/styles/main.css +107 -17
  10. package/build/styles/segmentedControl/SegmentedControl.css +101 -0
  11. package/build/styles/select/Select.css +0 -4
  12. package/build/types/common/locale/index.d.ts +26 -43
  13. package/build/types/common/locale/index.d.ts.map +1 -1
  14. package/build/types/index.d.ts +3 -0
  15. package/build/types/index.d.ts.map +1 -1
  16. package/build/types/inputs/SelectInput.d.ts +6 -5
  17. package/build/types/inputs/SelectInput.d.ts.map +1 -1
  18. package/build/types/phoneNumberInput/PhoneNumberInput.d.ts +22 -27
  19. package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
  20. package/build/types/phoneNumberInput/data/countries.d.ts +5 -10
  21. package/build/types/phoneNumberInput/data/countries.d.ts.map +1 -1
  22. package/build/types/phoneNumberInput/index.d.ts +1 -1
  23. package/build/types/phoneNumberInput/index.d.ts.map +1 -1
  24. package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts +1 -1
  25. package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts.map +1 -1
  26. package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts +1 -1
  27. package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts.map +1 -1
  28. package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts +8 -1
  29. package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts.map +1 -1
  30. package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts +1 -1
  31. package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts.map +1 -1
  32. package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts +8 -4
  33. package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts.map +1 -1
  34. package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts +1 -1
  35. package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts.map +1 -1
  36. package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts +1 -1
  37. package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts.map +1 -1
  38. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts +2 -1
  39. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts.map +1 -1
  40. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts +1 -1
  41. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts.map +1 -1
  42. package/build/types/phoneNumberInput/utils/index.d.ts +11 -13
  43. package/build/types/phoneNumberInput/utils/index.d.ts.map +1 -1
  44. package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts +1 -1
  45. package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts.map +1 -1
  46. package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts +1 -1
  47. package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts.map +1 -1
  48. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts +1 -1
  49. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts.map +1 -1
  50. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts +6 -1
  51. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts.map +1 -1
  52. package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts +2 -1
  53. package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts.map +1 -1
  54. package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts +7 -1
  55. package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts.map +1 -1
  56. package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts +1 -1
  57. package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts.map +1 -1
  58. package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts +1 -1
  59. package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts.map +1 -1
  60. package/build/types/segmentedControl/SegmentedControl.d.ts +31 -0
  61. package/build/types/segmentedControl/SegmentedControl.d.ts.map +1 -0
  62. package/build/types/segmentedControl/index.d.ts +3 -0
  63. package/build/types/segmentedControl/index.d.ts.map +1 -0
  64. package/package.json +7 -17
  65. package/src/common/locale/{index.spec.js → index.spec.ts} +4 -4
  66. package/src/common/locale/index.ts +96 -0
  67. package/src/index.ts +3 -0
  68. package/src/inputs/Input.css +0 -4
  69. package/src/inputs/SelectInput.css +6 -1
  70. package/src/inputs/SelectInput.less +8 -1
  71. package/src/inputs/SelectInput.spec.tsx +26 -0
  72. package/src/inputs/SelectInput.story.tsx +73 -1
  73. package/src/inputs/SelectInput.tsx +104 -85
  74. package/src/inputs/TextArea.css +0 -4
  75. package/src/main.css +107 -17
  76. package/src/main.less +1 -0
  77. package/src/phoneNumberInput/PhoneNumberInput.spec.js +18 -22
  78. package/src/phoneNumberInput/PhoneNumberInput.tsx +193 -0
  79. package/src/phoneNumberInput/data/{countries.js → countries.ts} +9 -1
  80. package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.ts +3 -0
  81. package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.spec.js → excludeCountries.spec.ts} +1 -1
  82. package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.js → excludeCountries.ts} +6 -5
  83. package/src/phoneNumberInput/utils/explodeNumberModel/{explodeNumberModel.spec.js → explodeNumberModel.spec.ts} +1 -1
  84. package/src/phoneNumberInput/utils/explodeNumberModel/index.ts +24 -0
  85. package/src/phoneNumberInput/utils/findCountryByCode/{findCountryByCode.spec.js → findCountryByCode.spec.ts} +0 -1
  86. package/src/phoneNumberInput/utils/findCountryByCode/index.ts +12 -0
  87. package/src/phoneNumberInput/utils/findCountryByPrefix/index.ts +12 -0
  88. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.ts +102 -0
  89. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.ts +12 -0
  90. package/src/phoneNumberInput/utils/{index.js → index.ts} +0 -2
  91. package/src/phoneNumberInput/utils/isStringNumeric/{isStringNumeric.spec.js → isStringNumeric.spec.ts} +0 -1
  92. package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.ts +1 -0
  93. package/src/phoneNumberInput/utils/isValidPhoneNumber/{isValidPhoneNumber.spec.js → isValidPhoneNumber.spec.ts} +1 -1
  94. package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.ts +7 -0
  95. package/src/phoneNumberInput/utils/longestMatchingPrefix/index.ts +4 -0
  96. package/src/phoneNumberInput/utils/setDefaultPrefix/index.ts +20 -0
  97. package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.ts +6 -0
  98. package/src/segmentedControl/SegmentedControl.css +101 -0
  99. package/src/segmentedControl/SegmentedControl.less +101 -0
  100. package/src/segmentedControl/SegmentedControl.spec.tsx +106 -0
  101. package/src/segmentedControl/SegmentedControl.story.tsx +55 -0
  102. package/src/segmentedControl/SegmentedControl.tsx +175 -0
  103. package/src/segmentedControl/index.ts +2 -0
  104. package/src/select/Select.css +0 -4
  105. package/src/ssr.spec.js +17 -0
  106. package/src/withDisplayFormat/WithDisplayFormat.spec.js +1 -1
  107. package/src/withDisplayFormat/WithDisplayFormat.tsx +1 -1
  108. package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts +0 -2
  109. package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts.map +0 -1
  110. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts +0 -2
  111. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts.map +0 -1
  112. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts +0 -3
  113. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts.map +0 -1
  114. package/build/types/utilities/wrapInFragment.d.ts +0 -3
  115. package/build/types/utilities/wrapInFragment.d.ts.map +0 -1
  116. package/src/common/locale/index.js +0 -139
  117. package/src/phoneNumberInput/PhoneNumberInput.js +0 -210
  118. package/src/phoneNumberInput/data/countries.spec.js +0 -12
  119. package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.js +0 -4
  120. package/src/phoneNumberInput/utils/explodeNumberModel/index.js +0 -27
  121. package/src/phoneNumberInput/utils/filterOptionsForQuery/filterOptionsForQuery.spec.js +0 -36
  122. package/src/phoneNumberInput/utils/filterOptionsForQuery/index.js +0 -11
  123. package/src/phoneNumberInput/utils/findCountryByCode/index.js +0 -10
  124. package/src/phoneNumberInput/utils/findCountryByPrefix/index.js +0 -11
  125. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.js +0 -26
  126. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.js +0 -67
  127. package/src/phoneNumberInput/utils/isOptionAndFitsQuery/index.js +0 -1
  128. package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.js +0 -25
  129. package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.spec.js +0 -66
  130. package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.js +0 -1
  131. package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.js +0 -10
  132. package/src/phoneNumberInput/utils/longestMatchingPrefix/index.js +0 -2
  133. package/src/phoneNumberInput/utils/setDefaultPrefix/index.js +0 -25
  134. package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.js +0 -3
  135. package/src/utilities/wrapInFragment.tsx +0 -3
  136. /package/src/phoneNumberInput/{PhoneNumberInput.story.js → PhoneNumberInput.story.tsx} +0 -0
  137. /package/src/phoneNumberInput/{index.js → index.ts} +0 -0
  138. /package/src/phoneNumberInput/utils/cleanNumber/{cleanNumber.spec.js → cleanNumber.spec.ts} +0 -0
  139. /package/src/phoneNumberInput/utils/cleanNumber/{index.js → index.ts} +0 -0
  140. /package/src/phoneNumberInput/utils/excludeCountries/{index.js → index.ts} +0 -0
  141. /package/src/phoneNumberInput/utils/findCountryByPrefix/{findCountryByPrefix.spec.js → findCountryByPrefix.spec.ts} +0 -0
  142. /package/src/phoneNumberInput/utils/groupCountriesByPrefix/{index.js → index.ts} +0 -0
  143. /package/src/phoneNumberInput/utils/isStringNumeric/{index.js → index.ts} +0 -0
  144. /package/src/phoneNumberInput/utils/isValidPhoneNumber/{index.js → index.ts} +0 -0
  145. /package/src/phoneNumberInput/utils/longestMatchingPrefix/{longestMatchingPrefix.spec.js → longestMatchingPrefix.spec.ts} +0 -0
  146. /package/src/phoneNumberInput/utils/setDefaultPrefix/{setDefaultPrefix.spec.js → setDefaultPrefix.spec.ts} +0 -0
  147. /package/src/phoneNumberInput/utils/sortArrayByProperty/{index.js → index.ts} +0 -0
  148. /package/src/phoneNumberInput/utils/sortArrayByProperty/{sortArrayByProperty.spec.js → sortArrayByProperty.spec.ts} +0 -0
@@ -19,7 +19,7 @@ import { CSSTransition } from 'react-transition-group';
19
19
  import { usePopper } from 'react-popper';
20
20
  import throttle from 'lodash.throttle';
21
21
  import { createPortal } from 'react-dom';
22
- import { isUndefined, isKey, isNumber, isEmpty, isNull, isArray } from '@transferwise/neptune-validation';
22
+ import { isUndefined, isKey, isNumber, isEmpty, isNull } from '@transferwise/neptune-validation';
23
23
  import { Flag, Illustration } from '@wise/art';
24
24
  import clamp$2 from 'lodash.clamp';
25
25
  import debounce from 'lodash.debounce';
@@ -342,131 +342,76 @@ const Key = {
342
342
  COMMA: ','
343
343
  };
344
344
 
345
- /**
346
- * Default language
347
- *
348
- * @type {string}
349
- */
350
345
  const DEFAULT_LANG = 'en';
351
-
352
- /**
353
- * Default locale
354
- *
355
- * @type {string}
356
- */
357
346
  const DEFAULT_LOCALE = 'en-GB';
358
-
359
347
  /**
360
- * Array of languages that are written from the right to the left
361
- *
362
- * @type {string[]}
348
+ * Languages written right-to-left.
363
349
  */
364
350
  const RTL_LANGUAGES = ['ar', 'he'];
365
-
366
351
  /**
367
352
  * @deprecated The source of truth for supported languages lives in Crab.
368
- * @type {string[]}
369
353
  */
370
354
  const SUPPORTED_LANGUAGES = [DEFAULT_LANG, 'de', 'es', 'fr', 'hu', 'id', 'it', 'ja', 'pl', 'pt', 'ro', 'ru', 'th', 'tr', 'uk', 'zh'];
371
-
372
355
  /**
373
- * Verifies and adjusts locale (replace `_` with `-`)
374
- * Returns null if locale is unrecognized by {Intl.Locale}
356
+ * Verifies and adjusts locale, replacing `_` with `-`.
375
357
  *
376
- * @param {string} locale (`es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
377
- * @returns {string|null}
358
+ * @param locale `es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP`, etc.
359
+ * @returns `null` if locale is unrecognized by `Intl.Locale`.
378
360
  */
379
361
  function adjustLocale(locale) {
380
- if (!locale || locale.trim().length === 0) {
381
- return null;
382
- }
383
- try {
384
- const {
385
- baseName
386
- } = new Intl.Locale(locale.trim().replace('_', '-'));
387
- return baseName;
388
- } catch (error) {
389
- // eslint-disable-next-line no-console
390
- console.error(error);
391
- return null;
362
+ const localeTrimmed = locale?.trim();
363
+ if (localeTrimmed) {
364
+ try {
365
+ return new Intl.Locale(localeTrimmed.replace('_', '-')).baseName;
366
+ } catch (error) {
367
+ // eslint-disable-next-line no-console
368
+ console.error(error);
369
+ }
392
370
  }
371
+ return null;
393
372
  }
394
-
395
373
  /**
396
- * Provides corresponding lang (iso2) for provided locale
397
- * if locale is invalid or language is unsupported returns null
374
+ * Provides corresponding lang (iso2) for provided locale.
398
375
  *
399
376
  * @deprecated The use of this function almost always breaks language variants
400
377
  * e.g. Simplified and Traditional Chinese.
401
378
  * There should be no use case for this function.
402
379
  * To select the correct translations from a translations object, pass the
403
380
  * locale directly into Crab's getLocalisedMessages.
404
- * @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
405
- * @returns {string|null} two-letter ISO639-1 language
381
+ * @param locale `es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP`, etc.
382
+ * @returns Two-letter ISO 639-1 language code, falling back to `null` if locale is invalid or language is unsupported.
406
383
  */
407
384
  function getLangFromLocale(locale) {
408
385
  const adjustedLocale = adjustLocale(locale);
409
- if (adjustedLocale === null) {
410
- return null;
411
- }
412
- try {
386
+ if (adjustedLocale != null) {
413
387
  const {
414
388
  language
415
389
  } = new Intl.Locale(adjustedLocale);
416
390
  if (SUPPORTED_LANGUAGES.includes(language)) {
417
391
  return language;
418
392
  }
419
- return null;
420
- } catch (error) {
421
- // eslint-disable-next-line no-console
422
- console.error(error);
423
- return null;
424
393
  }
394
+ return null;
425
395
  }
426
-
427
396
  /**
428
- * Provides corresponding country code (iso2) for locales code with explicit region value (`es-ES`, `en-GB`, `ja-JP` etc.)
429
- * if the value is invalid or missing region it returns null
397
+ * Provides corresponding country code (iso2) for locales code with explicit region value.
430
398
  *
431
- * @param {string} locale
432
- * @returns {string|null}
399
+ * @param locale `es-ES`, `en-GB`, `ja-JP`, etc.
400
+ * @returns `null` if the locale is invalid or the region can‘t be identified.
433
401
  */
434
402
  function getCountryFromLocale(locale) {
435
403
  const adjustedLocale = adjustLocale(locale);
436
- if (adjustedLocale === null) {
437
- return null;
438
- }
439
- try {
440
- const {
441
- region
442
- } = new Intl.Locale(adjustedLocale);
443
- return region ?? null;
444
- } catch (error) {
445
- // eslint-disable-next-line no-console
446
- console.error(error);
447
- return null;
448
- }
404
+ return adjustedLocale != null ? new Intl.Locale(adjustedLocale).region ?? null : null;
449
405
  }
450
-
451
406
  /**
452
407
  * Provides the layout direction for a given locale.
453
- * If locale is invalid or language is unsupported returns Direction.LTR
454
408
  *
455
- * @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
456
- * @returns {Direction} The layout direction based on the locale
409
+ * @param locale `es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP`, etc.
410
+ * @returns The layout direction based on the locale, falling back to `Direction.LTR` if the locale is invalid or unsupported.
457
411
  */
458
412
  function getDirectionFromLocale(locale) {
459
- try {
460
- const adjustedLocale = adjustLocale(locale);
461
- const {
462
- language
463
- } = new Intl.Locale(adjustedLocale);
464
- return RTL_LANGUAGES.includes(language) ? Direction.RTL : Direction.LTR;
465
- } catch (error) {
466
- // eslint-disable-next-line no-console
467
- console.error(error);
468
- return Direction.LTR;
469
- }
413
+ const adjustedLocale = adjustLocale(locale);
414
+ return adjustedLocale != null && RTL_LANGUAGES.includes(new Intl.Locale(adjustedLocale).language) ? Direction.RTL : Direction.LTR;
470
415
  }
471
416
 
472
417
  /**
@@ -6454,12 +6399,6 @@ const PolymorphicWithOverrides = /*#__PURE__*/forwardRef(function PolymorphicWit
6454
6399
  });
6455
6400
  });
6456
6401
 
6457
- function wrapInFragment(value) {
6458
- return /*#__PURE__*/jsx(Fragment, {
6459
- children: value
6460
- });
6461
- }
6462
-
6463
6402
  var messages$4 = defineMessages({
6464
6403
  noResultsFound: {
6465
6404
  id: "neptune.SelectInput.noResultsFound"
@@ -6800,10 +6739,10 @@ const defaultRenderTrigger = ({
6800
6739
  children: /*#__PURE__*/jsx(SelectInputTriggerButton, {
6801
6740
  as: ButtonInput,
6802
6741
  size: size,
6803
- children: placeholderShown ? /*#__PURE__*/jsxs("span", {
6804
- className: "np-select-input-placeholder",
6805
- children: [" ", content]
6806
- }) : content
6742
+ children: /*#__PURE__*/jsx("span", {
6743
+ className: classNames('np-select-input-content', placeholderShown && 'np-select-input-placeholder'),
6744
+ children: content
6745
+ })
6807
6746
  })
6808
6747
  });
6809
6748
  function SelectInputClearButton({
@@ -6824,12 +6763,13 @@ function SelectInputClearButton({
6824
6763
  const noop = () => {};
6825
6764
  function SelectInput({
6826
6765
  name,
6766
+ multiple,
6827
6767
  placeholder,
6828
6768
  items,
6829
6769
  defaultValue,
6830
6770
  value: controlledValue,
6831
6771
  compareValues,
6832
- renderValue = wrapInFragment,
6772
+ renderValue = String,
6833
6773
  renderFooter,
6834
6774
  renderTrigger = defaultRenderTrigger,
6835
6775
  filterable,
@@ -6858,6 +6798,7 @@ function SelectInput({
6858
6798
  const controllerRef = filterable ? searchInputRef : listboxRef;
6859
6799
  return /*#__PURE__*/jsx(Listbox, {
6860
6800
  name: name,
6801
+ multiple: multiple,
6861
6802
  defaultValue: defaultValue,
6862
6803
  value: controlledValue
6863
6804
  // TODO: Remove assertion when upgrading TypeScript to v5
@@ -6866,73 +6807,78 @@ function SelectInput({
6866
6807
  by: compareValues,
6867
6808
  disabled: disabled,
6868
6809
  onChange: value => {
6869
- setOpen(false);
6810
+ if (!multiple) {
6811
+ setOpen(false);
6812
+ }
6870
6813
  onChange?.(value);
6871
6814
  },
6872
6815
  children: ({
6873
6816
  disabled: uiDisabled,
6874
6817
  value
6875
- }) => /*#__PURE__*/jsx(OptionsOverlay, {
6876
- placement: "bottom-start",
6877
- open: open,
6878
- renderTrigger: ({
6879
- ref,
6880
- getInteractionProps
6881
- }) => /*#__PURE__*/jsx(SelectInputTriggerButtonPropsContext.Provider, {
6882
- // eslint-disable-next-line react/jsx-no-constructed-context-values
6883
- value: {
6884
- ref: mergeRefs([ref, triggerRef]),
6885
- ...mergeProps({
6886
- onClick: () => {
6887
- setOpen(prev => !prev);
6888
- },
6889
- onKeyDown: event => {
6890
- if (event.key === ' ' || event.key === 'Enter' || event.key === 'ArrowDown' || event.key === 'ArrowUp') {
6818
+ }) => {
6819
+ const placeholderShown = multiple && Array.isArray(value) ? value.length === 0 : value == null;
6820
+ return /*#__PURE__*/jsx(OptionsOverlay, {
6821
+ placement: "bottom-start",
6822
+ open: open,
6823
+ renderTrigger: ({
6824
+ ref,
6825
+ getInteractionProps
6826
+ }) => /*#__PURE__*/jsx(SelectInputTriggerButtonPropsContext.Provider, {
6827
+ // eslint-disable-next-line react/jsx-no-constructed-context-values
6828
+ value: {
6829
+ ref: mergeRefs([ref, triggerRef]),
6830
+ ...mergeProps({
6831
+ onClick: () => {
6891
6832
  setOpen(prev => !prev);
6833
+ },
6834
+ onKeyDown: event => {
6835
+ if (event.key === ' ' || event.key === 'Enter' || event.key === 'ArrowDown' || event.key === 'ArrowUp') {
6836
+ setOpen(prev => !prev);
6837
+ }
6892
6838
  }
6893
- }
6894
- }, getInteractionProps())
6839
+ }, getInteractionProps())
6840
+ },
6841
+ children: renderTrigger({
6842
+ content: !placeholderShown ? /*#__PURE__*/jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
6843
+ value: true,
6844
+ children: multiple && Array.isArray(value) ? value.map(option => renderValue(option, true)).join(', ') : renderValue(value, true)
6845
+ }) : placeholder,
6846
+ placeholderShown,
6847
+ clear: onClear != null ? () => {
6848
+ onClear();
6849
+ triggerRef.current?.focus({
6850
+ preventScroll: true
6851
+ });
6852
+ } : undefined,
6853
+ disabled: uiDisabled,
6854
+ size,
6855
+ className
6856
+ })
6857
+ }),
6858
+ initialFocusRef: controllerRef,
6859
+ size: filterable ? 'lg' : 'md',
6860
+ padding: "none",
6861
+ onClose: () => {
6862
+ setOpen(false);
6895
6863
  },
6896
- children: renderTrigger({
6897
- content: value != null ? /*#__PURE__*/jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
6898
- value: true,
6899
- children: renderValue(value, true)
6900
- }) : placeholder,
6901
- placeholderShown: value == null,
6902
- clear: onClear != null ? () => {
6903
- onClear();
6904
- triggerRef.current?.focus({
6905
- preventScroll: true
6906
- });
6907
- } : undefined,
6908
- disabled: uiDisabled,
6909
- size,
6910
- className
6864
+ onCloseEnd: () => {
6865
+ if (filterQuery !== '') {
6866
+ setFilterQuery('');
6867
+ }
6868
+ },
6869
+ children: /*#__PURE__*/jsx(SelectInputOptions, {
6870
+ items: items,
6871
+ renderValue: renderValue,
6872
+ renderFooter: renderFooter,
6873
+ filterable: filterable,
6874
+ filterPlaceholder: filterPlaceholder,
6875
+ searchInputRef: searchInputRef,
6876
+ listboxRef: listboxRef,
6877
+ filterQuery: filterQuery,
6878
+ onFilterChange: setFilterQuery
6911
6879
  })
6912
- }),
6913
- initialFocusRef: controllerRef,
6914
- size: filterable ? 'lg' : 'md',
6915
- padding: "none",
6916
- onClose: () => {
6917
- setOpen(false);
6918
- },
6919
- onCloseEnd: () => {
6920
- if (filterQuery !== '') {
6921
- setFilterQuery('');
6922
- }
6923
- },
6924
- children: /*#__PURE__*/jsx(SelectInputOptions, {
6925
- items: items,
6926
- renderValue: renderValue,
6927
- renderFooter: renderFooter,
6928
- filterable: filterable,
6929
- filterPlaceholder: filterPlaceholder,
6930
- searchInputRef: searchInputRef,
6931
- listboxRef: listboxRef,
6932
- filterQuery: filterQuery,
6933
- onFilterChange: setFilterQuery
6934
- })
6935
- })
6880
+ });
6881
+ }
6936
6882
  });
6937
6883
  }
6938
6884
  function SelectInputTriggerButton({
@@ -6995,7 +6941,7 @@ const SelectInputOptionsContainer = /*#__PURE__*/forwardRef(function SelectInput
6995
6941
  });
6996
6942
  function SelectInputOptions({
6997
6943
  items,
6998
- renderValue = wrapInFragment,
6944
+ renderValue = String,
6999
6945
  renderFooter,
7000
6946
  filterable = false,
7001
6947
  filterPlaceholder,
@@ -7564,7 +7510,7 @@ class WithDisplayFormat extends Component {
7564
7510
  const cursorPosition = getCursorPositionAfterKeystroke(action, selectionStart, selectionEnd, displayPattern, pastedLength);
7565
7511
  setTimeout(() => {
7566
7512
  if (triggerEvent) {
7567
- triggerEvent.currentTarget.setSelectionRange(cursorPosition, cursorPosition);
7513
+ triggerEvent.target.setSelectionRange(cursorPosition, cursorPosition);
7568
7514
  }
7569
7515
  this.setState({
7570
7516
  selectionStart: cursorPosition,
@@ -9567,111 +9513,79 @@ const countries = [{
9567
9513
  iso3: 'ZWE',
9568
9514
  phone: '+263'
9569
9515
  }];
9570
- var countries$1 = countries;
9571
9516
 
9572
9517
  const longestMatchingPrefix = matchingCodes => matchingCodes.reduce((a, b) => a.phone.length > b.phone.length ? a : b);
9573
9518
 
9574
9519
  const findCountryByCode = code => {
9575
- let matchingCodes;
9576
- if (code && code.length === 2) {
9577
- matchingCodes = countries$1.filter(country => code.toUpperCase() === country.iso2);
9520
+ if (code.length === 2) {
9521
+ const matchingCodes = countries.filter(country => code.toUpperCase() === country.iso2);
9522
+ if (matchingCodes.length > 0) {
9523
+ return longestMatchingPrefix(matchingCodes);
9524
+ }
9578
9525
  }
9579
- return matchingCodes && matchingCodes.length > 0 ? longestMatchingPrefix(matchingCodes) : null;
9526
+ return null;
9580
9527
  };
9581
9528
 
9582
9529
  /**
9583
9530
  * Default phone code, the UK one `+44`
9584
9531
  */
9585
9532
  const DEFAULT_PHONE_CODE = '+44';
9586
-
9587
9533
  /**
9588
9534
  * Given a valid locale it returns the correspondent prefix if found or +44 otherwise.
9589
9535
  *
9590
- * @param {string} locale - a string that represent the locale ex:'es-ES'
9591
- * @param countryCode
9592
- * @returns {string}
9536
+ * @param locale BCP 47 language tag of locale, e.g. `"es-ES"`.
9537
+ * @param countryCode Two-letter country code (ISO 3166-1 alpha-2).
9593
9538
  */
9594
9539
  const setDefaultPrefix = (locale, countryCode) => {
9595
- const country = findCountryByCode(countryCode) ||
9596
- // when `locale` code has explicit region: `en-GB`, `en-US`, `ar-AE`
9597
- findCountryByCode(getCountryFromLocale(locale)) ||
9598
- // when `locale` code is only two chars value: `fr`, `es`
9599
- findCountryByCode(locale);
9600
- return country?.phone || DEFAULT_PHONE_CODE;
9540
+ const country = (countryCode != null ? findCountryByCode(countryCode) : null) ?? findCountryByCode(getCountryFromLocale(locale) ?? locale);
9541
+ return country?.phone ?? DEFAULT_PHONE_CODE;
9601
9542
  };
9602
9543
 
9603
9544
  /**
9604
9545
  *
9605
9546
  * @param phoneNumber
9606
- * @returns {boolean} - returns true for number that starts with '+' and contains a mix of digits and spaces with
9607
- * at least 4 digits.
9547
+ * @returns True if number that starts with "+" and contains a mix of digits and spaces with at least 4 digits.
9608
9548
  */
9609
- const isValidPhoneNumber = phoneNumber => /^\+[\d-\s]+$/.test(phoneNumber) && phoneNumber.match(/\d+/g) && phoneNumber.match(/\d+/g).join('').length >= 4;
9549
+ const isValidPhoneNumber = phoneNumber => /^\+[\d-\s]+$/.test(phoneNumber) && (phoneNumber.match(/\d+/g)?.join('').length ?? 0) >= 4;
9610
9550
 
9611
9551
  const findCountryByPrefix = number => {
9612
- let matchingCodes = null;
9613
- if (number && number.length > 1) {
9614
- matchingCodes = countries$1.filter(country => number.indexOf(country.phone) === 0);
9552
+ if (number.length > 1) {
9553
+ const matchingCodes = countries.filter(country => number.startsWith(country.phone));
9554
+ if (matchingCodes.length > 0) {
9555
+ return longestMatchingPrefix(matchingCodes);
9556
+ }
9615
9557
  }
9616
- return matchingCodes && matchingCodes.length > 0 ? longestMatchingPrefix(matchingCodes) : null;
9558
+ return null;
9617
9559
  };
9618
9560
 
9619
9561
  /**
9620
- * Given a sting in a valid format ex:'+447573135343' it returns an object of shape
9621
- * {prefix=+44 ,suffix=7573135343}
9622
- *
9623
- * @param {string} number - a string that defines a phone number.
9624
- * @returns {{prefix: (string|*), suffix: string, format: string}}
9562
+ * @param number Phone number in a format like "+447573135343"
9625
9563
  */
9626
9564
  const explodeNumberModel = number => {
9627
- let prefix = '';
9628
- let suffix = '';
9629
- let format = '';
9630
9565
  const country = findCountryByPrefix(number);
9631
- if (country) {
9632
- prefix = country.phone;
9633
- suffix = number.slice(country.phone.length);
9634
- format = country.phoneFormat || '';
9635
- } else {
9636
- prefix = '';
9637
- suffix = number.slice(1);
9638
- format = '';
9639
- }
9640
- return {
9641
- prefix,
9642
- suffix,
9643
- format
9566
+ return country ? {
9567
+ prefix: country.phone,
9568
+ suffix: number.slice(country.phone.length),
9569
+ format: country.phoneFormat
9570
+ } : {
9571
+ prefix: null,
9572
+ suffix: number.slice(1)
9644
9573
  };
9645
9574
  };
9646
9575
 
9647
9576
  const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
9648
- const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
9577
+ const cleanNumber = number => number.match(DIGITS_MATCH)?.join('') ?? '';
9649
9578
 
9650
- // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
9651
- const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
9579
+ function sortArrayByProperty(arrayToSort, property) {
9580
+ return [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
9581
+ }
9652
9582
 
9653
9583
  const groupCountriesByPrefix = countries => {
9654
- const groupedArray = countries.reduce((accumulator, country) => {
9655
- const {
9656
- name,
9657
- iso2,
9658
- iso3,
9659
- phone
9660
- } = country;
9661
- if (accumulator[phone]) {
9662
- const previousValue = accumulator[phone];
9663
- accumulator[phone] = {
9664
- ...previousValue,
9665
- name: isArray(previousValue.name) ? [...previousValue.name, name] : [previousValue.name, name],
9666
- iso2: isArray(previousValue.iso2) ? [...previousValue.iso2, iso2] : [previousValue.iso2, iso2],
9667
- iso3: isArray(previousValue.iso3) ? [...previousValue.iso3, iso3] : [previousValue.iso3, iso3]
9668
- };
9669
- } else {
9670
- accumulator[phone] = country;
9671
- }
9672
- return accumulator;
9673
- }, {});
9674
- return Object.values(groupedArray);
9584
+ const countriesByPrefix = new Map();
9585
+ countries.forEach(country => {
9586
+ countriesByPrefix.set(country.phone, [...(countriesByPrefix.get(country.phone) ?? []), country]);
9587
+ });
9588
+ return countriesByPrefix;
9675
9589
  };
9676
9590
 
9677
9591
  // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
@@ -9679,41 +9593,38 @@ const filterCountriesByIso3 = (countries, iso3Codes) => {
9679
9593
  const iso3CodesSet = new Set(iso3Codes);
9680
9594
  return countries.filter(country => !iso3CodesSet.has(country.iso3));
9681
9595
  };
9682
-
9683
9596
  /**
9684
9597
  * Removes the countries sepecified in the second param
9685
9598
  *
9686
- * @param {Array} countries: list of country metadata objects
9687
- * @param {Array} disabledCountries: list of iso3 country codes to remove from the list
9688
- * @returns
9599
+ * @param countries list of country metadata objects
9600
+ * @param disabledCountries list of iso3 country codes to remove from the list
9689
9601
  */
9690
9602
  const excludeCountries = (countries, disabledCountries) => {
9691
9603
  return disabledCountries.length > 0 ? filterCountriesByIso3(countries, disabledCountries) : countries;
9692
9604
  };
9693
9605
 
9694
9606
  const ALLOWED_PHONE_CHARS = /^$|^[\d-\s]+$/;
9695
- const PhoneNumberInput = props => {
9696
- const {
9697
- id,
9698
- onChange,
9699
- searchPlaceholder,
9700
- disabled,
9701
- required,
9702
- size,
9703
- placeholder,
9704
- onFocus,
9705
- onBlur,
9706
- countryCode,
9707
- selectProps,
9708
- disabledCountries
9709
- } = props;
9607
+ const defaultSelectProps = {};
9608
+ const defaultDisabledCountries = [];
9609
+ const PhoneNumberInput = ({
9610
+ id,
9611
+ required,
9612
+ disabled,
9613
+ initialValue,
9614
+ onChange,
9615
+ onFocus,
9616
+ onBlur,
9617
+ countryCode,
9618
+ searchPlaceholder = 'Prefix',
9619
+ size = Size.MEDIUM,
9620
+ placeholder,
9621
+ selectProps = defaultSelectProps,
9622
+ disabledCountries = defaultDisabledCountries
9623
+ }) => {
9710
9624
  const {
9711
9625
  locale
9712
9626
  } = useIntl();
9713
- const getInitialValue = () => {
9714
- const {
9715
- initialValue
9716
- } = props;
9627
+ const [internalValue, setInternalValue] = useState(() => {
9717
9628
  const cleanValue = initialValue ? cleanNumber(initialValue) : null;
9718
9629
  if (!cleanValue || !isValidPhoneNumber(cleanValue)) {
9719
9630
  return {
@@ -9722,54 +9633,16 @@ const PhoneNumberInput = props => {
9722
9633
  };
9723
9634
  }
9724
9635
  return explodeNumberModel(cleanValue);
9725
- };
9726
- const [internalValue, setInternalValue] = useState(getInitialValue());
9636
+ });
9727
9637
  const [broadcastedValue, setBroadcastedValue] = useState(null);
9728
- const getSelectOptions = () => {
9729
- const countriesList = excludeCountries(countries$1, disabledCountries);
9730
- const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
9731
- return listSortedByISO3.map(option => {
9732
- const {
9733
- phone,
9734
- iso3,
9735
- iso2,
9736
- name
9737
- } = option;
9738
- let note = '';
9739
- if (iso3) {
9740
- note = isArray(iso3) ? iso3.join(', ') : iso3;
9741
- } else if (iso2) {
9742
- note = isArray(iso2) ? iso2.join(', ') : iso2;
9743
- }
9744
- return {
9745
- type: 'option',
9746
- value: {
9747
- value: phone,
9748
- label: phone,
9749
- note: note
9750
- },
9751
- filterMatchers: [phone, note, name]
9752
- };
9753
- });
9754
- };
9755
- const options = getSelectOptions();
9756
- const onPrefixChange = ({
9757
- value
9758
- }) => {
9759
- setInternalValue({
9760
- prefix: value,
9761
- suffix: internalValue.suffix
9762
- });
9763
- };
9638
+ const countriesByPrefix = useMemo(() => groupCountriesByPrefix(sortArrayByProperty(excludeCountries(countries, disabledCountries), 'iso3')), [disabledCountries]);
9764
9639
  const onSuffixChange = event => {
9765
- const {
9766
- value = ''
9767
- } = event.target;
9768
- if (ALLOWED_PHONE_CHARS.test(value)) {
9769
- setInternalValue({
9770
- prefix: internalValue.prefix,
9771
- suffix: value
9772
- });
9640
+ const suffix = event.target.value;
9641
+ if (ALLOWED_PHONE_CHARS.test(suffix)) {
9642
+ setInternalValue(prev => ({
9643
+ ...prev,
9644
+ suffix
9645
+ }));
9773
9646
  }
9774
9647
  };
9775
9648
  const onPaste = event => {
@@ -9777,31 +9650,22 @@ const PhoneNumberInput = props => {
9777
9650
  return;
9778
9651
  }
9779
9652
  const pastedValue = (event.nativeEvent.clipboardData.getData('text/plain') || '').replace(/(\s|-)+/g, '');
9780
- const {
9781
- prefix: pastedPrefix,
9782
- suffix: pastedSuffix
9783
- } = explodeNumberModel(pastedValue);
9784
- const selectedPrefix = options.find(({
9785
- value
9786
- }) => value.value === pastedPrefix);
9787
- if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
9788
- setInternalValue({
9789
- prefix: pastedPrefix,
9790
- suffix: pastedSuffix
9791
- });
9653
+ const pastedNumber = explodeNumberModel(pastedValue);
9654
+ if (pastedNumber.prefix != null && countriesByPrefix.has(pastedNumber.prefix) && ALLOWED_PHONE_CHARS.test(pastedNumber.suffix)) {
9655
+ setInternalValue(pastedNumber);
9792
9656
  }
9793
9657
  };
9794
9658
  useEffect(() => {
9795
9659
  if (broadcastedValue === null) {
9796
9660
  return setBroadcastedValue(internalValue);
9797
9661
  }
9798
- const internalPhoneNumber = internalValue.prefix + internalValue.suffix;
9799
- const broadcastedPhoneNumber = broadcastedValue.prefix + broadcastedValue.suffix;
9662
+ const internalPhoneNumber = `${internalValue.prefix ?? ''}${internalValue.suffix}`;
9663
+ const broadcastedPhoneNumber = `${broadcastedValue.prefix ?? ''}${broadcastedValue.suffix}`;
9800
9664
  if (internalPhoneNumber === broadcastedPhoneNumber) {
9801
9665
  return;
9802
9666
  }
9803
9667
  const newValue = isValidPhoneNumber(internalPhoneNumber) ? cleanNumber(internalPhoneNumber) : null;
9804
- onChange(newValue, internalValue.prefix);
9668
+ onChange(newValue, internalValue.prefix ?? '');
9805
9669
  setBroadcastedValue(internalValue);
9806
9670
  }, [onChange, broadcastedValue, internalValue]);
9807
9671
  return /*#__PURE__*/jsxs("div", {
@@ -9809,18 +9673,29 @@ const PhoneNumberInput = props => {
9809
9673
  children: [/*#__PURE__*/jsx("div", {
9810
9674
  className: "tw-telephone__country-select",
9811
9675
  children: /*#__PURE__*/jsx(SelectInput, {
9812
- placeholder: "Select an option...",
9813
- items: options,
9814
- value: options.find(item => item.value.value === internalValue.prefix)?.value,
9815
- renderValue: (option, withinTrigger) => /*#__PURE__*/jsx(SelectInputOptionContent, {
9816
- title: option.label,
9817
- note: withinTrigger ? undefined : option.note
9676
+ placeholder: "Select an option\u2026",
9677
+ items: [...countriesByPrefix].map(([prefix, countries]) => ({
9678
+ type: 'option',
9679
+ value: prefix,
9680
+ filterMatchers: [prefix, ...countries.map(country => country.name), ...countries.map(country => country.iso3)]
9681
+ })),
9682
+ value: internalValue.prefix,
9683
+ renderValue: (prefix, withinTrigger) => /*#__PURE__*/jsx(SelectInputOptionContent, {
9684
+ title: prefix,
9685
+ note: withinTrigger ? undefined : countriesByPrefix.get(prefix)?.map(country => country.iso3).join(', ')
9818
9686
  }),
9819
9687
  filterable: true,
9820
9688
  filterPlaceholder: searchPlaceholder,
9821
9689
  disabled: disabled,
9822
9690
  size: size,
9823
- onChange: onPrefixChange,
9691
+ onChange: prefix => {
9692
+ const country = prefix != null ? findCountryByPrefix(prefix) : null;
9693
+ setInternalValue(prev => ({
9694
+ ...prev,
9695
+ prefix,
9696
+ format: country?.phoneFormat
9697
+ }));
9698
+ },
9824
9699
  ...selectProps
9825
9700
  })
9826
9701
  }), /*#__PURE__*/jsx("div", {
@@ -9846,37 +9721,6 @@ const PhoneNumberInput = props => {
9846
9721
  })]
9847
9722
  });
9848
9723
  };
9849
- PhoneNumberInput.propTypes = {
9850
- id: PropTypes.string,
9851
- required: PropTypes.bool,
9852
- disabled: PropTypes.bool,
9853
- initialValue: PropTypes.string,
9854
- onChange: PropTypes.func.isRequired,
9855
- onFocus: PropTypes.func,
9856
- onBlur: PropTypes.func,
9857
- countryCode: PropTypes.string,
9858
- searchPlaceholder: PropTypes.string,
9859
- size: PropTypes.oneOf(['sm', 'md', 'lg']),
9860
- placeholder: PropTypes.string,
9861
- selectProps: PropTypes.object,
9862
- /** List of iso3 codes of countries to remove from the list */
9863
- disabledCountries: PropTypes.arrayOf(PropTypes.string)
9864
- };
9865
- PhoneNumberInput.defaultProps = {
9866
- id: null,
9867
- required: false,
9868
- disabled: false,
9869
- initialValue: null,
9870
- onFocus() {},
9871
- onBlur() {},
9872
- countryCode: null,
9873
- searchPlaceholder: 'Prefix',
9874
- size: Size.MEDIUM,
9875
- placeholder: '',
9876
- selectProps: {},
9877
- disabledCountries: []
9878
- };
9879
- var PhoneNumberInput$1 = PhoneNumberInput;
9880
9724
 
9881
9725
  const Progress = ({
9882
9726
  className,
@@ -10035,7 +9879,6 @@ const PromoCard = /*#__PURE__*/forwardRef(({
10035
9879
  setChecked(!checked); // Update local state for checkbox
10036
9880
  }
10037
9881
  };
10038
-
10039
9882
  const componentId = `${id || generateRandomId()}`;
10040
9883
  // Set the icon to `'arrow'` if `href` is truthy and `type` is falsy, or
10041
9884
  // `'download'` if `download` is truthy. If neither condition is true, set
@@ -11199,6 +11042,109 @@ Select.defaultProps = {
11199
11042
  dropdownProps: {}
11200
11043
  };
11201
11044
 
11045
+ const SegmentedControl = ({
11046
+ name,
11047
+ defaultValue,
11048
+ mode = 'input',
11049
+ segments,
11050
+ onChange
11051
+ }) => {
11052
+ const [selectedValue, setSelectedValue] = useState(defaultValue || segments[0].value);
11053
+ const [animate, setAnimate] = useState(false);
11054
+ const segmentsRef = useRef(null);
11055
+ if (segments.length > 3) {
11056
+ throw new Error('SegmentedControl only supports up to 3 segments. Please refer to: https://wise.design/components/segmented-control');
11057
+ }
11058
+ const segmentsWithRefs = segments.map(segment => ({
11059
+ ...segment,
11060
+ ref: /*#__PURE__*/createRef()
11061
+ }));
11062
+ const updateSegmentPosition = () => {
11063
+ const selectedSegmentRef = segmentsWithRefs.find(segment => segment.value === selectedValue)?.ref;
11064
+ // We grab the active segments style object from the ref
11065
+ // and set the css variables to the selected segments width and x position.
11066
+ // This is so we can animate the highlight to the selected segment
11067
+ if (selectedSegmentRef?.current && segmentsRef.current) {
11068
+ const {
11069
+ style
11070
+ } = segmentsRef.current;
11071
+ style.setProperty('--segment-highlight-width', `${selectedSegmentRef.current.offsetWidth}px`);
11072
+ style.setProperty('--segment-highlight-x', `${selectedSegmentRef.current.offsetLeft}px`);
11073
+ }
11074
+ };
11075
+ useEffect(() => {
11076
+ updateSegmentPosition();
11077
+ const handleWindowSizeChange = () => {
11078
+ setAnimate(false);
11079
+ updateSegmentPosition();
11080
+ };
11081
+ window.addEventListener('resize', handleWindowSizeChange);
11082
+ return () => {
11083
+ window.removeEventListener('resize', handleWindowSizeChange);
11084
+ };
11085
+ // eslint-disable-next-line react-hooks/exhaustive-deps
11086
+ }, [segmentsWithRefs, selectedValue]);
11087
+ useEffect(() => {
11088
+ onChange(selectedValue);
11089
+ }, [onChange, selectedValue]);
11090
+ return /*#__PURE__*/jsx("div", {
11091
+ ref: segmentsRef,
11092
+ "data-testid": "segmented-control",
11093
+ className: classNames('segmented-control', {
11094
+ 'segmented-control--input': mode === 'input'
11095
+ }),
11096
+ children: /*#__PURE__*/jsx("div", {
11097
+ className: classNames('segmented-control__segments', {
11098
+ 'segmented-control__segments--no-animate': !animate
11099
+ }),
11100
+ children: segmentsWithRefs.map(segment => mode === 'input' ? /*#__PURE__*/jsxs("label", {
11101
+ ref: segment.ref,
11102
+ htmlFor: segment.id,
11103
+ className: classNames('segmented-control__segment', {
11104
+ 'segmented-control__selected-segment': selectedValue === segment.value
11105
+ }),
11106
+ children: [/*#__PURE__*/jsx("input", {
11107
+ type: "radio",
11108
+ className: "segmented-control__radio-input",
11109
+ id: segment.id,
11110
+ name: name,
11111
+ value: segment.value,
11112
+ checked: selectedValue === segment.value,
11113
+ onChange: () => {
11114
+ setAnimate(true);
11115
+ setSelectedValue(segment.value);
11116
+ }
11117
+ }), /*#__PURE__*/jsx(Body, {
11118
+ className: "segmented-control__text",
11119
+ as: "span",
11120
+ type: selectedValue === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
11121
+ children: segment.label
11122
+ })]
11123
+ }, segment.id) : /*#__PURE__*/jsx("button", {
11124
+ ref: segment.ref,
11125
+ type: "button",
11126
+ role: "tab",
11127
+ id: segment.id,
11128
+ "aria-controls": segment.controls,
11129
+ "aria-selected": selectedValue === segment.value,
11130
+ className: classNames('segmented-control__segment', 'segmented-control__button', {
11131
+ 'segmented-control__selected-segment': selectedValue === segment.value
11132
+ }),
11133
+ onClick: () => {
11134
+ setAnimate(true);
11135
+ setSelectedValue(segment.value);
11136
+ },
11137
+ children: /*#__PURE__*/jsx(Body, {
11138
+ as: "span",
11139
+ className: "segmented-control__text",
11140
+ type: selectedValue === segment.value ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_DEFAULT,
11141
+ children: segment.label
11142
+ })
11143
+ }, segment.id))
11144
+ })
11145
+ });
11146
+ };
11147
+
11202
11148
  const CSS_TRANSITION_DURATION = 400;
11203
11149
  class Snackbar extends Component {
11204
11150
  /** @type {RefObject<HTMLSpanElement>} */
@@ -13983,7 +13929,6 @@ const UploadButton = ({
13983
13929
  if (areAllFilesAllowed) {
13984
13930
  return null; //file input by default allows all files
13985
13931
  }
13986
-
13987
13932
  if (Array.isArray(fileTypes)) {
13988
13933
  return {
13989
13934
  accept: fileTypes.join(',')
@@ -14181,7 +14126,6 @@ const UploadItem = ({
14181
14126
  children: processIndicator
14182
14127
  }); // Scale down ProcessIndicator to be 20px*20px to match `icons`
14183
14128
  };
14184
-
14185
14129
  const getErrorMessage = () => typeof error === 'object' && error.message || error || formatMessage(MESSAGES.uploadingFailed);
14186
14130
  const getDescription = () => {
14187
14131
  if (error || status === Status.FAILED) {
@@ -15597,5 +15541,5 @@ const translations = {
15597
15541
  'zh-HK': zhHK
15598
15542
  };
15599
15543
 
15600
- export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$2 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList$1 as InstructionsList, LanguageProvider, Layout$1 as Layout, Link, ListItem$1 as ListItem, Loader$1 as Loader, Logo$1 as Logo, LogoType, Markdown$1 as Markdown, MarkdownNodeType, Modal, Money$1 as Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList$1 as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput$1 as PhoneNumberInput, Popover$2 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCard$1 as PromoCardGroup, Provider$1 as Provider, RTL_LANGUAGES, Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioOption$1 as RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel$1 as SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider$1 as SnackbarProvider, Status, StatusIcon, Stepper, Sticky$1 as Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip$1 as Tooltip, Type$1 as Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
15544
+ export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$2 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList$1 as InstructionsList, LanguageProvider, Layout$1 as Layout, Link, ListItem$1 as ListItem, Loader$1 as Loader, Logo$1 as Logo, LogoType, Markdown$1 as Markdown, MarkdownNodeType, Modal, Money$1 as Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList$1 as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput, Popover$2 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCard$1 as PromoCardGroup, Provider$1 as Provider, RTL_LANGUAGES, Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioOption$1 as RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, SegmentedControl, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel$1 as SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider$1 as SnackbarProvider, Status, StatusIcon, Stepper, Sticky$1 as Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip$1 as Tooltip, Type$1 as Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
15601
15545
  //# sourceMappingURL=index.esm.js.map