@transferwise/components 46.5.0 → 46.7.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 (173) hide show
  1. package/build/i18n/th.json +3 -3
  2. package/build/index.esm.js +252 -464
  3. package/build/index.esm.js.map +1 -1
  4. package/build/index.js +253 -465
  5. package/build/index.js.map +1 -1
  6. package/build/main.css +6 -17
  7. package/build/styles/inputs/Input.css +0 -4
  8. package/build/styles/inputs/SelectInput.css +6 -1
  9. package/build/styles/inputs/TextArea.css +0 -4
  10. package/build/styles/main.css +6 -17
  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/common/textFormat/formatWithPattern/formatWithPattern.d.ts +1 -1
  15. package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts.map +1 -1
  16. package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts +2 -2
  17. package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts.map +1 -1
  18. package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts +5 -1
  19. package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts.map +1 -1
  20. package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts +1 -1
  21. package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts.map +1 -1
  22. package/build/types/index.d.ts +3 -0
  23. package/build/types/index.d.ts.map +1 -1
  24. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +7 -11
  25. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
  26. package/build/types/inputWithDisplayFormat/index.d.ts +2 -1
  27. package/build/types/inputWithDisplayFormat/index.d.ts.map +1 -1
  28. package/build/types/inputs/SelectInput.d.ts +6 -5
  29. package/build/types/inputs/SelectInput.d.ts.map +1 -1
  30. package/build/types/phoneNumberInput/PhoneNumberInput.d.ts +22 -27
  31. package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
  32. package/build/types/phoneNumberInput/data/countries.d.ts +5 -10
  33. package/build/types/phoneNumberInput/data/countries.d.ts.map +1 -1
  34. package/build/types/phoneNumberInput/index.d.ts +1 -1
  35. package/build/types/phoneNumberInput/index.d.ts.map +1 -1
  36. package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts +1 -1
  37. package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts.map +1 -1
  38. package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts +1 -1
  39. package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts.map +1 -1
  40. package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts +8 -1
  41. package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts.map +1 -1
  42. package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts +1 -1
  43. package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts.map +1 -1
  44. package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts +8 -4
  45. package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts.map +1 -1
  46. package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts +1 -1
  47. package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts.map +1 -1
  48. package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts +1 -1
  49. package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts.map +1 -1
  50. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts +2 -1
  51. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts.map +1 -1
  52. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts +1 -1
  53. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts.map +1 -1
  54. package/build/types/phoneNumberInput/utils/index.d.ts +11 -13
  55. package/build/types/phoneNumberInput/utils/index.d.ts.map +1 -1
  56. package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts +1 -1
  57. package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts.map +1 -1
  58. package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts +1 -1
  59. package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts.map +1 -1
  60. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts +1 -1
  61. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts.map +1 -1
  62. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts +6 -1
  63. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts.map +1 -1
  64. package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts +2 -1
  65. package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts.map +1 -1
  66. package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts +7 -1
  67. package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts.map +1 -1
  68. package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts +1 -1
  69. package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts.map +1 -1
  70. package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts +1 -1
  71. package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts.map +1 -1
  72. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +7 -11
  73. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
  74. package/build/types/textareaWithDisplayFormat/index.d.ts +2 -1
  75. package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
  76. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +55 -83
  77. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
  78. package/build/types/withDisplayFormat/index.d.ts +2 -1
  79. package/build/types/withDisplayFormat/index.d.ts.map +1 -1
  80. package/package.json +3 -4
  81. package/src/common/locale/{index.spec.js → index.spec.ts} +4 -4
  82. package/src/common/locale/index.ts +96 -0
  83. package/src/common/textFormat/formatWithPattern/{formatWithPattern.js → formatWithPattern.ts} +8 -4
  84. package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.js → getCursorPositionAfterKeystroke.ts} +8 -8
  85. package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.js → getSymbolsInPatternWithPosition.ts} +7 -2
  86. package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.js → unformatWithPattern.ts} +3 -2
  87. package/src/i18n/th.json +3 -3
  88. package/src/index.ts +3 -0
  89. package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +10 -0
  90. package/src/inputWithDisplayFormat/index.ts +2 -0
  91. package/src/inputs/Input.css +0 -4
  92. package/src/inputs/SelectInput.css +6 -1
  93. package/src/inputs/SelectInput.less +8 -1
  94. package/src/inputs/SelectInput.spec.tsx +26 -0
  95. package/src/inputs/SelectInput.story.tsx +73 -1
  96. package/src/inputs/SelectInput.tsx +104 -85
  97. package/src/inputs/TextArea.css +0 -4
  98. package/src/main.css +6 -17
  99. package/src/phoneNumberInput/PhoneNumberInput.spec.js +18 -22
  100. package/src/phoneNumberInput/PhoneNumberInput.tsx +193 -0
  101. package/src/phoneNumberInput/data/{countries.js → countries.ts} +9 -1
  102. package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.ts +3 -0
  103. package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.spec.js → excludeCountries.spec.ts} +1 -1
  104. package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.js → excludeCountries.ts} +6 -5
  105. package/src/phoneNumberInput/utils/explodeNumberModel/{explodeNumberModel.spec.js → explodeNumberModel.spec.ts} +1 -1
  106. package/src/phoneNumberInput/utils/explodeNumberModel/index.ts +24 -0
  107. package/src/phoneNumberInput/utils/findCountryByCode/{findCountryByCode.spec.js → findCountryByCode.spec.ts} +0 -1
  108. package/src/phoneNumberInput/utils/findCountryByCode/index.ts +12 -0
  109. package/src/phoneNumberInput/utils/findCountryByPrefix/index.ts +12 -0
  110. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.ts +102 -0
  111. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.ts +12 -0
  112. package/src/phoneNumberInput/utils/{index.js → index.ts} +0 -2
  113. package/src/phoneNumberInput/utils/isStringNumeric/{isStringNumeric.spec.js → isStringNumeric.spec.ts} +0 -1
  114. package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.ts +1 -0
  115. package/src/phoneNumberInput/utils/isValidPhoneNumber/{isValidPhoneNumber.spec.js → isValidPhoneNumber.spec.ts} +1 -1
  116. package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.ts +7 -0
  117. package/src/phoneNumberInput/utils/longestMatchingPrefix/index.ts +4 -0
  118. package/src/phoneNumberInput/utils/setDefaultPrefix/index.ts +20 -0
  119. package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.ts +6 -0
  120. package/src/select/Select.css +0 -4
  121. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +3 -1
  122. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +32 -0
  123. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +13 -0
  124. package/src/textareaWithDisplayFormat/index.ts +2 -0
  125. package/src/withDisplayFormat/WithDisplayFormat.spec.js +1 -1
  126. package/src/withDisplayFormat/{WithDisplayFormat.js → WithDisplayFormat.tsx} +127 -107
  127. package/src/withDisplayFormat/index.ts +2 -0
  128. package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts +0 -2
  129. package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts.map +0 -1
  130. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts +0 -2
  131. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts.map +0 -1
  132. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts +0 -3
  133. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts.map +0 -1
  134. package/build/types/utilities/wrapInFragment.d.ts +0 -3
  135. package/build/types/utilities/wrapInFragment.d.ts.map +0 -1
  136. package/src/common/locale/index.js +0 -139
  137. package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +0 -14
  138. package/src/inputWithDisplayFormat/index.js +0 -1
  139. package/src/phoneNumberInput/PhoneNumberInput.js +0 -210
  140. package/src/phoneNumberInput/data/countries.spec.js +0 -12
  141. package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.js +0 -4
  142. package/src/phoneNumberInput/utils/explodeNumberModel/index.js +0 -27
  143. package/src/phoneNumberInput/utils/filterOptionsForQuery/filterOptionsForQuery.spec.js +0 -36
  144. package/src/phoneNumberInput/utils/filterOptionsForQuery/index.js +0 -11
  145. package/src/phoneNumberInput/utils/findCountryByCode/index.js +0 -10
  146. package/src/phoneNumberInput/utils/findCountryByPrefix/index.js +0 -11
  147. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.js +0 -26
  148. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.js +0 -67
  149. package/src/phoneNumberInput/utils/isOptionAndFitsQuery/index.js +0 -1
  150. package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.js +0 -25
  151. package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.spec.js +0 -66
  152. package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.js +0 -1
  153. package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.js +0 -10
  154. package/src/phoneNumberInput/utils/longestMatchingPrefix/index.js +0 -2
  155. package/src/phoneNumberInput/utils/setDefaultPrefix/index.js +0 -25
  156. package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.js +0 -3
  157. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +0 -14
  158. package/src/textareaWithDisplayFormat/index.js +0 -1
  159. package/src/utilities/wrapInFragment.tsx +0 -3
  160. package/src/withDisplayFormat/index.js +0 -1
  161. /package/src/phoneNumberInput/{PhoneNumberInput.story.js → PhoneNumberInput.story.tsx} +0 -0
  162. /package/src/phoneNumberInput/{index.js → index.ts} +0 -0
  163. /package/src/phoneNumberInput/utils/cleanNumber/{cleanNumber.spec.js → cleanNumber.spec.ts} +0 -0
  164. /package/src/phoneNumberInput/utils/cleanNumber/{index.js → index.ts} +0 -0
  165. /package/src/phoneNumberInput/utils/excludeCountries/{index.js → index.ts} +0 -0
  166. /package/src/phoneNumberInput/utils/findCountryByPrefix/{findCountryByPrefix.spec.js → findCountryByPrefix.spec.ts} +0 -0
  167. /package/src/phoneNumberInput/utils/groupCountriesByPrefix/{index.js → index.ts} +0 -0
  168. /package/src/phoneNumberInput/utils/isStringNumeric/{index.js → index.ts} +0 -0
  169. /package/src/phoneNumberInput/utils/isValidPhoneNumber/{index.js → index.ts} +0 -0
  170. /package/src/phoneNumberInput/utils/longestMatchingPrefix/{longestMatchingPrefix.spec.js → longestMatchingPrefix.spec.ts} +0 -0
  171. /package/src/phoneNumberInput/utils/setDefaultPrefix/{setDefaultPrefix.spec.js → setDefaultPrefix.spec.ts} +0 -0
  172. /package/src/phoneNumberInput/utils/sortArrayByProperty/{index.js → index.ts} +0 -0
  173. /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,
@@ -7263,10 +7209,13 @@ const formatWithPattern = (value, pattern) => {
7263
7209
  let patternSymbol = [];
7264
7210
  // valueArray.length increments during the cycle cause we are adding new elements.
7265
7211
  for (let index = 0; index < valueArray.length; index += 1) {
7266
- patternSymbol = patternWithSymbolsPosition.filter(symbol => symbol.index === index);
7212
+ patternSymbol = patternWithSymbolsPosition.filter(pattern => pattern.index === index);
7267
7213
  // Add pattern's symbol at n position
7268
7214
  if (patternSymbol.length === 1) {
7269
- valueArray.splice(index, 0, patternSymbol.pop().symbol);
7215
+ const last = patternSymbol.pop();
7216
+ if (last) {
7217
+ valueArray.splice(index, 0, last.symbol);
7218
+ }
7270
7219
  }
7271
7220
  }
7272
7221
  return valueArray.join('');
@@ -7312,7 +7261,7 @@ const countConsecutiveSymbols = (selectionStart, applicablePattern, direction) =
7312
7261
  return groupSize;
7313
7262
  };
7314
7263
 
7315
- const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
7264
+ const getCursorPositionAfterActionStroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
7316
7265
  let cursorPosition = selectionStart;
7317
7266
  switch (action) {
7318
7267
  case 'Backspace':
@@ -7334,36 +7283,36 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
7334
7283
  }
7335
7284
  return cursorPosition;
7336
7285
  };
7337
- var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
7286
+ var getCursorPositionAfterKeystroke = getCursorPositionAfterActionStroke;
7338
7287
 
7339
7288
  class WithDisplayFormat extends Component {
7289
+ static defaultProps = {
7290
+ autoComplete: 'off',
7291
+ displayPattern: '',
7292
+ value: ''
7293
+ };
7340
7294
  constructor(props) {
7341
7295
  super(props);
7342
- const {
7343
- value,
7344
- displayPattern
7345
- } = props;
7346
- const unformattedValue = unformatWithPattern$1(value, displayPattern);
7296
+ const unformattedValue = unformatWithPattern$1(props.value ?? '', props.displayPattern);
7347
7297
  this.state = {
7348
- value: formatWithPattern$1(unformattedValue, displayPattern),
7298
+ value: formatWithPattern$1(unformattedValue, props.displayPattern),
7349
7299
  historyNavigator: new HistoryNavigator$1(),
7350
7300
  prevDisplayPattern: props.displayPattern,
7351
- triggerType: null,
7352
- triggerEvent: null
7301
+ triggerType: 'Initial',
7302
+ triggerEvent: null,
7303
+ selectionStart: 0,
7304
+ selectionEnd: 0,
7305
+ pastedLength: 0
7353
7306
  };
7354
7307
  }
7355
- static getDerivedStateFromProps(nextProps, previousState) {
7356
- const {
7357
- displayPattern
7358
- } = nextProps;
7359
- const {
7360
- prevDisplayPattern
7361
- } = previousState;
7362
- if (previousState.prevDisplayPattern !== displayPattern) {
7363
- const {
7364
- value,
7365
- historyNavigator
7366
- } = previousState;
7308
+ static getDerivedStateFromProps({
7309
+ displayPattern
7310
+ }, {
7311
+ prevDisplayPattern = displayPattern,
7312
+ value,
7313
+ historyNavigator
7314
+ }) {
7315
+ if (prevDisplayPattern !== displayPattern) {
7367
7316
  const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
7368
7317
  historyNavigator.reset();
7369
7318
  return {
@@ -7385,29 +7334,31 @@ class WithDisplayFormat extends Component {
7385
7334
  const {
7386
7335
  displayPattern
7387
7336
  } = this.props;
7388
- const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7389
- if (triggerType === 'Paste' || triggerType === 'Cut') {
7390
- return triggerType;
7391
- }
7392
- if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7393
- return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7394
- }
7395
- // Detect mouse event redo
7396
- if (triggerEvent.ctrlKey && charCode === 'd') {
7397
- return 'Delete';
7398
- }
7399
-
7400
- // Android Fix.
7401
- if (typeof triggerEvent.key === 'undefined') {
7402
- if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7337
+ if (triggerEvent) {
7338
+ const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7339
+ if (triggerType === 'Paste' || triggerType === 'Cut') {
7340
+ return triggerType;
7341
+ }
7342
+ if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7343
+ return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7344
+ }
7345
+ // Detect mouse event redo
7346
+ if (triggerEvent.ctrlKey && charCode === 'd') {
7347
+ return 'Delete';
7348
+ }
7349
+ // Android Fix.
7350
+ if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7403
7351
  return 'Backspace';
7404
7352
  }
7353
+ return triggerEvent.key;
7354
+ } else {
7355
+ // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7356
+ return 'Paste';
7405
7357
  }
7406
- return triggerEvent.key;
7407
7358
  };
7408
7359
  resetEvent = () => {
7409
7360
  this.setState({
7410
- triggerType: null,
7361
+ triggerType: 'Initial',
7411
7362
  triggerEvent: null,
7412
7363
  pastedLength: 0
7413
7364
  });
@@ -7424,14 +7375,13 @@ class WithDisplayFormat extends Component {
7424
7375
  const {
7425
7376
  selectionStart,
7426
7377
  selectionEnd
7427
- } = event.target;
7378
+ } = event.currentTarget;
7428
7379
  const {
7429
7380
  historyNavigator
7430
7381
  } = this.state;
7431
7382
  const {
7432
7383
  displayPattern
7433
7384
  } = this.props;
7434
-
7435
7385
  // Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
7436
7386
  let newFormattedValue = '';
7437
7387
  if (this.detectUndoRedo(event) === 'Undo') {
@@ -7450,8 +7400,8 @@ class WithDisplayFormat extends Component {
7450
7400
  this.setState({
7451
7401
  triggerEvent: event,
7452
7402
  triggerType: 'KeyDown',
7453
- selectionStart,
7454
- selectionEnd
7403
+ selectionStart: selectionStart ?? 0,
7404
+ selectionEnd: selectionEnd ?? 0
7455
7405
  });
7456
7406
  }
7457
7407
  };
@@ -7480,7 +7430,6 @@ class WithDisplayFormat extends Component {
7480
7430
  handleOnChange = event => {
7481
7431
  const {
7482
7432
  historyNavigator,
7483
- triggerEvent,
7484
7433
  triggerType
7485
7434
  } = this.state;
7486
7435
  const {
@@ -7491,9 +7440,7 @@ class WithDisplayFormat extends Component {
7491
7440
  value
7492
7441
  } = event.target;
7493
7442
  let unformattedValue = unformatWithPattern$1(value, displayPattern);
7494
- const action = triggerEvent === null ?
7495
- // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7496
- 'Paste' : this.getUserAction(unformattedValue);
7443
+ const action = this.getUserAction(unformattedValue);
7497
7444
  if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
7498
7445
  return;
7499
7446
  }
@@ -7503,19 +7450,18 @@ class WithDisplayFormat extends Component {
7503
7450
  const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
7504
7451
  historyNavigator.add(unformattedValue);
7505
7452
  this.handleCursorPositioning(action);
7506
- const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7507
7453
  this.setState({
7508
7454
  value: newFormattedValue
7509
- }, this.resetEvent(), onChange(broadcastValue));
7455
+ }, () => {
7456
+ this.resetEvent();
7457
+ if (onChange) {
7458
+ const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7459
+ onChange(broadcastValue);
7460
+ }
7461
+ });
7510
7462
  };
7511
7463
  handleOnBlur = event => {
7512
- const {
7513
- displayPattern,
7514
- onBlur
7515
- } = this.props;
7516
- if (onBlur) {
7517
- onBlur(unformatWithPattern$1(event.target.value, displayPattern));
7518
- }
7464
+ this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
7519
7465
  };
7520
7466
  handleOnFocus = event => {
7521
7467
  const {
@@ -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.target.setSelectionRange(cursorPosition, cursorPosition);
7513
+ triggerEvent.currentTarget.setSelectionRange(cursorPosition, cursorPosition);
7568
7514
  }
7569
7515
  this.setState({
7570
7516
  selectionStart: cursorPosition,
@@ -7574,7 +7520,6 @@ class WithDisplayFormat extends Component {
7574
7520
  };
7575
7521
  render() {
7576
7522
  const {
7577
- type,
7578
7523
  inputMode,
7579
7524
  className,
7580
7525
  id,
@@ -7591,7 +7536,6 @@ class WithDisplayFormat extends Component {
7591
7536
  value
7592
7537
  } = this.state;
7593
7538
  const renderProps = {
7594
- type,
7595
7539
  inputMode,
7596
7540
  className,
7597
7541
  id,
@@ -7614,62 +7558,13 @@ class WithDisplayFormat extends Component {
7614
7558
  return this.props.render(renderProps);
7615
7559
  }
7616
7560
  }
7617
- WithDisplayFormat.propTypes = {
7618
- /**
7619
- * autocomplete hides our form help so we need to disable it when help text
7620
- * is present. Chrome ignores autocomplete=off, the only way to disable it is
7621
- * to provide an 'invalid' value, for which 'disabled' serves.
7622
- */
7623
- autoComplete: PropTypes.oneOf(['on', 'off', 'disabled']),
7624
- className: PropTypes.string,
7625
- disabled: PropTypes.bool,
7626
- id: PropTypes.string,
7627
- maxLength: PropTypes.number,
7628
- minLength: PropTypes.number,
7629
- name: PropTypes.string,
7630
- onFocus: PropTypes.func,
7631
- onBlur: PropTypes.func,
7632
- onChange: PropTypes.func.isRequired,
7633
- placeholder: PropTypes.string,
7634
- readOnly: PropTypes.bool,
7635
- render: PropTypes.func.isRequired,
7636
- required: PropTypes.bool,
7637
- displayPattern: PropTypes.string,
7638
- type: PropTypes.string,
7639
- inputMode: PropTypes.string,
7640
- value: PropTypes.string
7641
- };
7642
- WithDisplayFormat.defaultProps = {
7643
- autoComplete: 'off',
7644
- className: null,
7645
- disabled: false,
7646
- id: null,
7647
- maxLength: null,
7648
- minLength: null,
7649
- name: null,
7650
- placeholder: null,
7651
- readOnly: false,
7652
- required: false,
7653
- displayPattern: '',
7654
- type: 'text',
7655
- inputMode: null,
7656
- value: '',
7657
- onFocus: null,
7658
- onBlur: null
7659
- };
7660
- var WithDisplayFormat$1 = WithDisplayFormat;
7661
7561
 
7662
- const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat$1, {
7562
+ const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
7663
7563
  ...props,
7664
- render: renderProps => /*#__PURE__*/jsx("input", {
7564
+ render: renderProps => /*#__PURE__*/jsx(Input, {
7665
7565
  ...renderProps
7666
7566
  })
7667
7567
  });
7668
- InputWithDisplayFormat.propTypes = {
7669
- displayPattern: PropTypes.string.isRequired,
7670
- onChange: PropTypes.func.isRequired
7671
- };
7672
- var InputWithDisplayFormat$1 = InputWithDisplayFormat;
7673
7568
 
7674
7569
  const InstructionsList = ({
7675
7570
  dos,
@@ -9618,111 +9513,79 @@ const countries = [{
9618
9513
  iso3: 'ZWE',
9619
9514
  phone: '+263'
9620
9515
  }];
9621
- var countries$1 = countries;
9622
9516
 
9623
9517
  const longestMatchingPrefix = matchingCodes => matchingCodes.reduce((a, b) => a.phone.length > b.phone.length ? a : b);
9624
9518
 
9625
9519
  const findCountryByCode = code => {
9626
- let matchingCodes;
9627
- if (code && code.length === 2) {
9628
- 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
+ }
9629
9525
  }
9630
- return matchingCodes && matchingCodes.length > 0 ? longestMatchingPrefix(matchingCodes) : null;
9526
+ return null;
9631
9527
  };
9632
9528
 
9633
9529
  /**
9634
9530
  * Default phone code, the UK one `+44`
9635
9531
  */
9636
9532
  const DEFAULT_PHONE_CODE = '+44';
9637
-
9638
9533
  /**
9639
9534
  * Given a valid locale it returns the correspondent prefix if found or +44 otherwise.
9640
9535
  *
9641
- * @param {string} locale - a string that represent the locale ex:'es-ES'
9642
- * @param countryCode
9643
- * @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).
9644
9538
  */
9645
9539
  const setDefaultPrefix = (locale, countryCode) => {
9646
- const country = findCountryByCode(countryCode) ||
9647
- // when `locale` code has explicit region: `en-GB`, `en-US`, `ar-AE`
9648
- findCountryByCode(getCountryFromLocale(locale)) ||
9649
- // when `locale` code is only two chars value: `fr`, `es`
9650
- findCountryByCode(locale);
9651
- 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;
9652
9542
  };
9653
9543
 
9654
9544
  /**
9655
9545
  *
9656
9546
  * @param phoneNumber
9657
- * @returns {boolean} - returns true for number that starts with '+' and contains a mix of digits and spaces with
9658
- * 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.
9659
9548
  */
9660
- 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;
9661
9550
 
9662
9551
  const findCountryByPrefix = number => {
9663
- let matchingCodes = null;
9664
- if (number && number.length > 1) {
9665
- 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
+ }
9666
9557
  }
9667
- return matchingCodes && matchingCodes.length > 0 ? longestMatchingPrefix(matchingCodes) : null;
9558
+ return null;
9668
9559
  };
9669
9560
 
9670
9561
  /**
9671
- * Given a sting in a valid format ex:'+447573135343' it returns an object of shape
9672
- * {prefix=+44 ,suffix=7573135343}
9673
- *
9674
- * @param {string} number - a string that defines a phone number.
9675
- * @returns {{prefix: (string|*), suffix: string, format: string}}
9562
+ * @param number Phone number in a format like "+447573135343"
9676
9563
  */
9677
9564
  const explodeNumberModel = number => {
9678
- let prefix = '';
9679
- let suffix = '';
9680
- let format = '';
9681
9565
  const country = findCountryByPrefix(number);
9682
- if (country) {
9683
- prefix = country.phone;
9684
- suffix = number.slice(country.phone.length);
9685
- format = country.phoneFormat || '';
9686
- } else {
9687
- prefix = '';
9688
- suffix = number.slice(1);
9689
- format = '';
9690
- }
9691
- return {
9692
- prefix,
9693
- suffix,
9694
- 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)
9695
9573
  };
9696
9574
  };
9697
9575
 
9698
9576
  const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
9699
- const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
9577
+ const cleanNumber = number => number.match(DIGITS_MATCH)?.join('') ?? '';
9700
9578
 
9701
- // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
9702
- 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
+ }
9703
9582
 
9704
9583
  const groupCountriesByPrefix = countries => {
9705
- const groupedArray = countries.reduce((accumulator, country) => {
9706
- const {
9707
- name,
9708
- iso2,
9709
- iso3,
9710
- phone
9711
- } = country;
9712
- if (accumulator[phone]) {
9713
- const previousValue = accumulator[phone];
9714
- accumulator[phone] = {
9715
- ...previousValue,
9716
- name: isArray(previousValue.name) ? [...previousValue.name, name] : [previousValue.name, name],
9717
- iso2: isArray(previousValue.iso2) ? [...previousValue.iso2, iso2] : [previousValue.iso2, iso2],
9718
- iso3: isArray(previousValue.iso3) ? [...previousValue.iso3, iso3] : [previousValue.iso3, iso3]
9719
- };
9720
- } else {
9721
- accumulator[phone] = country;
9722
- }
9723
- return accumulator;
9724
- }, {});
9725
- 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;
9726
9589
  };
9727
9590
 
9728
9591
  // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
@@ -9730,41 +9593,38 @@ const filterCountriesByIso3 = (countries, iso3Codes) => {
9730
9593
  const iso3CodesSet = new Set(iso3Codes);
9731
9594
  return countries.filter(country => !iso3CodesSet.has(country.iso3));
9732
9595
  };
9733
-
9734
9596
  /**
9735
9597
  * Removes the countries sepecified in the second param
9736
9598
  *
9737
- * @param {Array} countries: list of country metadata objects
9738
- * @param {Array} disabledCountries: list of iso3 country codes to remove from the list
9739
- * @returns
9599
+ * @param countries list of country metadata objects
9600
+ * @param disabledCountries list of iso3 country codes to remove from the list
9740
9601
  */
9741
9602
  const excludeCountries = (countries, disabledCountries) => {
9742
9603
  return disabledCountries.length > 0 ? filterCountriesByIso3(countries, disabledCountries) : countries;
9743
9604
  };
9744
9605
 
9745
9606
  const ALLOWED_PHONE_CHARS = /^$|^[\d-\s]+$/;
9746
- const PhoneNumberInput = props => {
9747
- const {
9748
- id,
9749
- onChange,
9750
- searchPlaceholder,
9751
- disabled,
9752
- required,
9753
- size,
9754
- placeholder,
9755
- onFocus,
9756
- onBlur,
9757
- countryCode,
9758
- selectProps,
9759
- disabledCountries
9760
- } = 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
+ }) => {
9761
9624
  const {
9762
9625
  locale
9763
9626
  } = useIntl();
9764
- const getInitialValue = () => {
9765
- const {
9766
- initialValue
9767
- } = props;
9627
+ const [internalValue, setInternalValue] = useState(() => {
9768
9628
  const cleanValue = initialValue ? cleanNumber(initialValue) : null;
9769
9629
  if (!cleanValue || !isValidPhoneNumber(cleanValue)) {
9770
9630
  return {
@@ -9773,54 +9633,16 @@ const PhoneNumberInput = props => {
9773
9633
  };
9774
9634
  }
9775
9635
  return explodeNumberModel(cleanValue);
9776
- };
9777
- const [internalValue, setInternalValue] = useState(getInitialValue());
9636
+ });
9778
9637
  const [broadcastedValue, setBroadcastedValue] = useState(null);
9779
- const getSelectOptions = () => {
9780
- const countriesList = excludeCountries(countries$1, disabledCountries);
9781
- const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
9782
- return listSortedByISO3.map(option => {
9783
- const {
9784
- phone,
9785
- iso3,
9786
- iso2,
9787
- name
9788
- } = option;
9789
- let note = '';
9790
- if (iso3) {
9791
- note = isArray(iso3) ? iso3.join(', ') : iso3;
9792
- } else if (iso2) {
9793
- note = isArray(iso2) ? iso2.join(', ') : iso2;
9794
- }
9795
- return {
9796
- type: 'option',
9797
- value: {
9798
- value: phone,
9799
- label: phone,
9800
- note: note
9801
- },
9802
- filterMatchers: [phone, note, name]
9803
- };
9804
- });
9805
- };
9806
- const options = getSelectOptions();
9807
- const onPrefixChange = ({
9808
- value
9809
- }) => {
9810
- setInternalValue({
9811
- prefix: value,
9812
- suffix: internalValue.suffix
9813
- });
9814
- };
9638
+ const countriesByPrefix = useMemo(() => groupCountriesByPrefix(sortArrayByProperty(excludeCountries(countries, disabledCountries), 'iso3')), [disabledCountries]);
9815
9639
  const onSuffixChange = event => {
9816
- const {
9817
- value = ''
9818
- } = event.target;
9819
- if (ALLOWED_PHONE_CHARS.test(value)) {
9820
- setInternalValue({
9821
- prefix: internalValue.prefix,
9822
- suffix: value
9823
- });
9640
+ const suffix = event.target.value;
9641
+ if (ALLOWED_PHONE_CHARS.test(suffix)) {
9642
+ setInternalValue(prev => ({
9643
+ ...prev,
9644
+ suffix
9645
+ }));
9824
9646
  }
9825
9647
  };
9826
9648
  const onPaste = event => {
@@ -9828,31 +9650,22 @@ const PhoneNumberInput = props => {
9828
9650
  return;
9829
9651
  }
9830
9652
  const pastedValue = (event.nativeEvent.clipboardData.getData('text/plain') || '').replace(/(\s|-)+/g, '');
9831
- const {
9832
- prefix: pastedPrefix,
9833
- suffix: pastedSuffix
9834
- } = explodeNumberModel(pastedValue);
9835
- const selectedPrefix = options.find(({
9836
- value
9837
- }) => value.value === pastedPrefix);
9838
- if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
9839
- setInternalValue({
9840
- prefix: pastedPrefix,
9841
- suffix: pastedSuffix
9842
- });
9653
+ const pastedNumber = explodeNumberModel(pastedValue);
9654
+ if (pastedNumber.prefix != null && countriesByPrefix.has(pastedNumber.prefix) && ALLOWED_PHONE_CHARS.test(pastedNumber.suffix)) {
9655
+ setInternalValue(pastedNumber);
9843
9656
  }
9844
9657
  };
9845
9658
  useEffect(() => {
9846
9659
  if (broadcastedValue === null) {
9847
9660
  return setBroadcastedValue(internalValue);
9848
9661
  }
9849
- const internalPhoneNumber = internalValue.prefix + internalValue.suffix;
9850
- const broadcastedPhoneNumber = broadcastedValue.prefix + broadcastedValue.suffix;
9662
+ const internalPhoneNumber = `${internalValue.prefix ?? ''}${internalValue.suffix}`;
9663
+ const broadcastedPhoneNumber = `${broadcastedValue.prefix ?? ''}${broadcastedValue.suffix}`;
9851
9664
  if (internalPhoneNumber === broadcastedPhoneNumber) {
9852
9665
  return;
9853
9666
  }
9854
9667
  const newValue = isValidPhoneNumber(internalPhoneNumber) ? cleanNumber(internalPhoneNumber) : null;
9855
- onChange(newValue, internalValue.prefix);
9668
+ onChange(newValue, internalValue.prefix ?? '');
9856
9669
  setBroadcastedValue(internalValue);
9857
9670
  }, [onChange, broadcastedValue, internalValue]);
9858
9671
  return /*#__PURE__*/jsxs("div", {
@@ -9860,18 +9673,29 @@ const PhoneNumberInput = props => {
9860
9673
  children: [/*#__PURE__*/jsx("div", {
9861
9674
  className: "tw-telephone__country-select",
9862
9675
  children: /*#__PURE__*/jsx(SelectInput, {
9863
- placeholder: "Select an option...",
9864
- items: options,
9865
- value: options.find(item => item.value.value === internalValue.prefix)?.value,
9866
- renderValue: (option, withinTrigger) => /*#__PURE__*/jsx(SelectInputOptionContent, {
9867
- title: option.label,
9868
- 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(', ')
9869
9686
  }),
9870
9687
  filterable: true,
9871
9688
  filterPlaceholder: searchPlaceholder,
9872
9689
  disabled: disabled,
9873
9690
  size: size,
9874
- 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
+ },
9875
9699
  ...selectProps
9876
9700
  })
9877
9701
  }), /*#__PURE__*/jsx("div", {
@@ -9897,37 +9721,6 @@ const PhoneNumberInput = props => {
9897
9721
  })]
9898
9722
  });
9899
9723
  };
9900
- PhoneNumberInput.propTypes = {
9901
- id: PropTypes.string,
9902
- required: PropTypes.bool,
9903
- disabled: PropTypes.bool,
9904
- initialValue: PropTypes.string,
9905
- onChange: PropTypes.func.isRequired,
9906
- onFocus: PropTypes.func,
9907
- onBlur: PropTypes.func,
9908
- countryCode: PropTypes.string,
9909
- searchPlaceholder: PropTypes.string,
9910
- size: PropTypes.oneOf(['sm', 'md', 'lg']),
9911
- placeholder: PropTypes.string,
9912
- selectProps: PropTypes.object,
9913
- /** List of iso3 codes of countries to remove from the list */
9914
- disabledCountries: PropTypes.arrayOf(PropTypes.string)
9915
- };
9916
- PhoneNumberInput.defaultProps = {
9917
- id: null,
9918
- required: false,
9919
- disabled: false,
9920
- initialValue: null,
9921
- onFocus() {},
9922
- onBlur() {},
9923
- countryCode: null,
9924
- searchPlaceholder: 'Prefix',
9925
- size: Size.MEDIUM,
9926
- placeholder: '',
9927
- selectProps: {},
9928
- disabledCountries: []
9929
- };
9930
- var PhoneNumberInput$1 = PhoneNumberInput;
9931
9724
 
9932
9725
  const Progress = ({
9933
9726
  className,
@@ -12346,17 +12139,12 @@ Tabs.defaultProps = {
12346
12139
  };
12347
12140
  var Tabs$1 = Tabs;
12348
12141
 
12349
- const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat$1, {
12142
+ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
12350
12143
  ...props,
12351
- render: renderProps => /*#__PURE__*/jsx("textarea", {
12144
+ render: renderProps => /*#__PURE__*/jsx(TextArea, {
12352
12145
  ...renderProps
12353
12146
  })
12354
12147
  });
12355
- TextareaWithDisplayFormat.propTypes = {
12356
- displayPattern: PropTypes.string.isRequired,
12357
- onChange: PropTypes.func.isRequired
12358
- };
12359
- var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
12360
12148
 
12361
12149
  /* eslint-disable jsx-a11y/no-autofocus */
12362
12150
  /* eslint-disable jsx-a11y/click-events-have-key-events */
@@ -15358,16 +15146,16 @@ var th = {
15358
15146
  "neptune.DateInput.year.label": "ปี",
15359
15147
  "neptune.DateInput.year.placeholder": "YYYY",
15360
15148
  "neptune.DateLookup.day": "วัน",
15361
- "neptune.DateLookup.goTo20YearView": "Go to 20 year view",
15149
+ "neptune.DateLookup.goTo20YearView": "ไปที่มุมมอง 20 ปี",
15362
15150
  "neptune.DateLookup.month": "เดือน",
15363
15151
  "neptune.DateLookup.next": "ถัดไป",
15364
15152
  "neptune.DateLookup.previous": "ก่อนหน้า",
15365
15153
  "neptune.DateLookup.selected": "เลือกแล้ว",
15366
15154
  "neptune.DateLookup.twentyYears": "20 ปี",
15367
15155
  "neptune.DateLookup.year": "ปี",
15368
- "neptune.FlowNavigation.back": "back to previous step",
15156
+ "neptune.FlowNavigation.back": "กลับไปที่ขั้นก่อนหน้า",
15369
15157
  "neptune.Info.ariaLabel": "ข้อมูลเพิ่มเติม",
15370
- "neptune.Link.opensInNewTab": "(opens in new tab)",
15158
+ "neptune.Link.opensInNewTab": "(เปิดในแท็บใหม่)",
15371
15159
  "neptune.MoneyInput.Select.placeholder": "เลือกตัวเลือก...",
15372
15160
  "neptune.Select.searchPlaceholder": "ค้นหา...",
15373
15161
  "neptune.SelectInput.noResultsFound": "ไม่พบผลลัพธ์",
@@ -15653,5 +15441,5 @@ const translations = {
15653
15441
  'zh-HK': zhHK
15654
15442
  };
15655
15443
 
15656
- 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$1 as 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$1 as 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 };
15444
+ 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, 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 };
15657
15445
  //# sourceMappingURL=index.esm.js.map