@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
package/build/index.js CHANGED
@@ -376,131 +376,76 @@ const Key = {
376
376
  COMMA: ','
377
377
  };
378
378
 
379
- /**
380
- * Default language
381
- *
382
- * @type {string}
383
- */
384
379
  const DEFAULT_LANG = 'en';
385
-
386
- /**
387
- * Default locale
388
- *
389
- * @type {string}
390
- */
391
380
  const DEFAULT_LOCALE = 'en-GB';
392
-
393
381
  /**
394
- * Array of languages that are written from the right to the left
395
- *
396
- * @type {string[]}
382
+ * Languages written right-to-left.
397
383
  */
398
384
  const RTL_LANGUAGES = ['ar', 'he'];
399
-
400
385
  /**
401
386
  * @deprecated The source of truth for supported languages lives in Crab.
402
- * @type {string[]}
403
387
  */
404
388
  const SUPPORTED_LANGUAGES = [DEFAULT_LANG, 'de', 'es', 'fr', 'hu', 'id', 'it', 'ja', 'pl', 'pt', 'ro', 'ru', 'th', 'tr', 'uk', 'zh'];
405
-
406
389
  /**
407
- * Verifies and adjusts locale (replace `_` with `-`)
408
- * Returns null if locale is unrecognized by {Intl.Locale}
390
+ * Verifies and adjusts locale, replacing `_` with `-`.
409
391
  *
410
- * @param {string} locale (`es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
411
- * @returns {string|null}
392
+ * @param locale `es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP`, etc.
393
+ * @returns `null` if locale is unrecognized by `Intl.Locale`.
412
394
  */
413
395
  function adjustLocale(locale) {
414
- if (!locale || locale.trim().length === 0) {
415
- return null;
416
- }
417
- try {
418
- const {
419
- baseName
420
- } = new Intl.Locale(locale.trim().replace('_', '-'));
421
- return baseName;
422
- } catch (error) {
423
- // eslint-disable-next-line no-console
424
- console.error(error);
425
- return null;
396
+ const localeTrimmed = locale?.trim();
397
+ if (localeTrimmed) {
398
+ try {
399
+ return new Intl.Locale(localeTrimmed.replace('_', '-')).baseName;
400
+ } catch (error) {
401
+ // eslint-disable-next-line no-console
402
+ console.error(error);
403
+ }
426
404
  }
405
+ return null;
427
406
  }
428
-
429
407
  /**
430
- * Provides corresponding lang (iso2) for provided locale
431
- * if locale is invalid or language is unsupported returns null
408
+ * Provides corresponding lang (iso2) for provided locale.
432
409
  *
433
410
  * @deprecated The use of this function almost always breaks language variants
434
411
  * e.g. Simplified and Traditional Chinese.
435
412
  * There should be no use case for this function.
436
413
  * To select the correct translations from a translations object, pass the
437
414
  * locale directly into Crab's getLocalisedMessages.
438
- * @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
439
- * @returns {string|null} two-letter ISO639-1 language
415
+ * @param locale `es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP`, etc.
416
+ * @returns Two-letter ISO 639-1 language code, falling back to `null` if locale is invalid or language is unsupported.
440
417
  */
441
418
  function getLangFromLocale(locale) {
442
419
  const adjustedLocale = adjustLocale(locale);
443
- if (adjustedLocale === null) {
444
- return null;
445
- }
446
- try {
420
+ if (adjustedLocale != null) {
447
421
  const {
448
422
  language
449
423
  } = new Intl.Locale(adjustedLocale);
450
424
  if (SUPPORTED_LANGUAGES.includes(language)) {
451
425
  return language;
452
426
  }
453
- return null;
454
- } catch (error) {
455
- // eslint-disable-next-line no-console
456
- console.error(error);
457
- return null;
458
427
  }
428
+ return null;
459
429
  }
460
-
461
430
  /**
462
- * Provides corresponding country code (iso2) for locales code with explicit region value (`es-ES`, `en-GB`, `ja-JP` etc.)
463
- * if the value is invalid or missing region it returns null
431
+ * Provides corresponding country code (iso2) for locales code with explicit region value.
464
432
  *
465
- * @param {string} locale
466
- * @returns {string|null}
433
+ * @param locale `es-ES`, `en-GB`, `ja-JP`, etc.
434
+ * @returns `null` if the locale is invalid or the region can‘t be identified.
467
435
  */
468
436
  function getCountryFromLocale(locale) {
469
437
  const adjustedLocale = adjustLocale(locale);
470
- if (adjustedLocale === null) {
471
- return null;
472
- }
473
- try {
474
- const {
475
- region
476
- } = new Intl.Locale(adjustedLocale);
477
- return region ?? null;
478
- } catch (error) {
479
- // eslint-disable-next-line no-console
480
- console.error(error);
481
- return null;
482
- }
438
+ return adjustedLocale != null ? new Intl.Locale(adjustedLocale).region ?? null : null;
483
439
  }
484
-
485
440
  /**
486
441
  * Provides the layout direction for a given locale.
487
- * If locale is invalid or language is unsupported returns Direction.LTR
488
442
  *
489
- * @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
490
- * @returns {Direction} The layout direction based on the locale
443
+ * @param locale `es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP`, etc.
444
+ * @returns The layout direction based on the locale, falling back to `Direction.LTR` if the locale is invalid or unsupported.
491
445
  */
492
446
  function getDirectionFromLocale(locale) {
493
- try {
494
- const adjustedLocale = adjustLocale(locale);
495
- const {
496
- language
497
- } = new Intl.Locale(adjustedLocale);
498
- return RTL_LANGUAGES.includes(language) ? exports.Direction.RTL : exports.Direction.LTR;
499
- } catch (error) {
500
- // eslint-disable-next-line no-console
501
- console.error(error);
502
- return exports.Direction.LTR;
503
- }
447
+ const adjustedLocale = adjustLocale(locale);
448
+ return adjustedLocale != null && RTL_LANGUAGES.includes(new Intl.Locale(adjustedLocale).language) ? exports.Direction.RTL : exports.Direction.LTR;
504
449
  }
505
450
 
506
451
  /**
@@ -6488,12 +6433,6 @@ const PolymorphicWithOverrides = /*#__PURE__*/React.forwardRef(function Polymorp
6488
6433
  });
6489
6434
  });
6490
6435
 
6491
- function wrapInFragment(value) {
6492
- return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
6493
- children: value
6494
- });
6495
- }
6496
-
6497
6436
  var messages$4 = reactIntl.defineMessages({
6498
6437
  noResultsFound: {
6499
6438
  id: "neptune.SelectInput.noResultsFound"
@@ -6834,10 +6773,10 @@ const defaultRenderTrigger = ({
6834
6773
  children: /*#__PURE__*/jsxRuntime.jsx(SelectInputTriggerButton, {
6835
6774
  as: ButtonInput,
6836
6775
  size: size,
6837
- children: placeholderShown ? /*#__PURE__*/jsxRuntime.jsxs("span", {
6838
- className: "np-select-input-placeholder",
6839
- children: [" ", content]
6840
- }) : content
6776
+ children: /*#__PURE__*/jsxRuntime.jsx("span", {
6777
+ className: classNames__default.default('np-select-input-content', placeholderShown && 'np-select-input-placeholder'),
6778
+ children: content
6779
+ })
6841
6780
  })
6842
6781
  });
6843
6782
  function SelectInputClearButton({
@@ -6858,12 +6797,13 @@ function SelectInputClearButton({
6858
6797
  const noop = () => {};
6859
6798
  function SelectInput({
6860
6799
  name,
6800
+ multiple,
6861
6801
  placeholder,
6862
6802
  items,
6863
6803
  defaultValue,
6864
6804
  value: controlledValue,
6865
6805
  compareValues,
6866
- renderValue = wrapInFragment,
6806
+ renderValue = String,
6867
6807
  renderFooter,
6868
6808
  renderTrigger = defaultRenderTrigger,
6869
6809
  filterable,
@@ -6892,6 +6832,7 @@ function SelectInput({
6892
6832
  const controllerRef = filterable ? searchInputRef : listboxRef;
6893
6833
  return /*#__PURE__*/jsxRuntime.jsx(react$1.Listbox, {
6894
6834
  name: name,
6835
+ multiple: multiple,
6895
6836
  defaultValue: defaultValue,
6896
6837
  value: controlledValue
6897
6838
  // TODO: Remove assertion when upgrading TypeScript to v5
@@ -6900,73 +6841,78 @@ function SelectInput({
6900
6841
  by: compareValues,
6901
6842
  disabled: disabled,
6902
6843
  onChange: value => {
6903
- setOpen(false);
6844
+ if (!multiple) {
6845
+ setOpen(false);
6846
+ }
6904
6847
  onChange?.(value);
6905
6848
  },
6906
6849
  children: ({
6907
6850
  disabled: uiDisabled,
6908
6851
  value
6909
- }) => /*#__PURE__*/jsxRuntime.jsx(OptionsOverlay, {
6910
- placement: "bottom-start",
6911
- open: open,
6912
- renderTrigger: ({
6913
- ref,
6914
- getInteractionProps
6915
- }) => /*#__PURE__*/jsxRuntime.jsx(SelectInputTriggerButtonPropsContext.Provider, {
6916
- // eslint-disable-next-line react/jsx-no-constructed-context-values
6917
- value: {
6918
- ref: mergeRefs__default.default([ref, triggerRef]),
6919
- ...mergeProps__default.default({
6920
- onClick: () => {
6921
- setOpen(prev => !prev);
6922
- },
6923
- onKeyDown: event => {
6924
- if (event.key === ' ' || event.key === 'Enter' || event.key === 'ArrowDown' || event.key === 'ArrowUp') {
6852
+ }) => {
6853
+ const placeholderShown = multiple && Array.isArray(value) ? value.length === 0 : value == null;
6854
+ return /*#__PURE__*/jsxRuntime.jsx(OptionsOverlay, {
6855
+ placement: "bottom-start",
6856
+ open: open,
6857
+ renderTrigger: ({
6858
+ ref,
6859
+ getInteractionProps
6860
+ }) => /*#__PURE__*/jsxRuntime.jsx(SelectInputTriggerButtonPropsContext.Provider, {
6861
+ // eslint-disable-next-line react/jsx-no-constructed-context-values
6862
+ value: {
6863
+ ref: mergeRefs__default.default([ref, triggerRef]),
6864
+ ...mergeProps__default.default({
6865
+ onClick: () => {
6925
6866
  setOpen(prev => !prev);
6867
+ },
6868
+ onKeyDown: event => {
6869
+ if (event.key === ' ' || event.key === 'Enter' || event.key === 'ArrowDown' || event.key === 'ArrowUp') {
6870
+ setOpen(prev => !prev);
6871
+ }
6926
6872
  }
6927
- }
6928
- }, getInteractionProps())
6873
+ }, getInteractionProps())
6874
+ },
6875
+ children: renderTrigger({
6876
+ content: !placeholderShown ? /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
6877
+ value: true,
6878
+ children: multiple && Array.isArray(value) ? value.map(option => renderValue(option, true)).join(', ') : renderValue(value, true)
6879
+ }) : placeholder,
6880
+ placeholderShown,
6881
+ clear: onClear != null ? () => {
6882
+ onClear();
6883
+ triggerRef.current?.focus({
6884
+ preventScroll: true
6885
+ });
6886
+ } : undefined,
6887
+ disabled: uiDisabled,
6888
+ size,
6889
+ className
6890
+ })
6891
+ }),
6892
+ initialFocusRef: controllerRef,
6893
+ size: filterable ? 'lg' : 'md',
6894
+ padding: "none",
6895
+ onClose: () => {
6896
+ setOpen(false);
6929
6897
  },
6930
- children: renderTrigger({
6931
- content: value != null ? /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContentWithinTriggerContext.Provider, {
6932
- value: true,
6933
- children: renderValue(value, true)
6934
- }) : placeholder,
6935
- placeholderShown: value == null,
6936
- clear: onClear != null ? () => {
6937
- onClear();
6938
- triggerRef.current?.focus({
6939
- preventScroll: true
6940
- });
6941
- } : undefined,
6942
- disabled: uiDisabled,
6943
- size,
6944
- className
6898
+ onCloseEnd: () => {
6899
+ if (filterQuery !== '') {
6900
+ setFilterQuery('');
6901
+ }
6902
+ },
6903
+ children: /*#__PURE__*/jsxRuntime.jsx(SelectInputOptions, {
6904
+ items: items,
6905
+ renderValue: renderValue,
6906
+ renderFooter: renderFooter,
6907
+ filterable: filterable,
6908
+ filterPlaceholder: filterPlaceholder,
6909
+ searchInputRef: searchInputRef,
6910
+ listboxRef: listboxRef,
6911
+ filterQuery: filterQuery,
6912
+ onFilterChange: setFilterQuery
6945
6913
  })
6946
- }),
6947
- initialFocusRef: controllerRef,
6948
- size: filterable ? 'lg' : 'md',
6949
- padding: "none",
6950
- onClose: () => {
6951
- setOpen(false);
6952
- },
6953
- onCloseEnd: () => {
6954
- if (filterQuery !== '') {
6955
- setFilterQuery('');
6956
- }
6957
- },
6958
- children: /*#__PURE__*/jsxRuntime.jsx(SelectInputOptions, {
6959
- items: items,
6960
- renderValue: renderValue,
6961
- renderFooter: renderFooter,
6962
- filterable: filterable,
6963
- filterPlaceholder: filterPlaceholder,
6964
- searchInputRef: searchInputRef,
6965
- listboxRef: listboxRef,
6966
- filterQuery: filterQuery,
6967
- onFilterChange: setFilterQuery
6968
- })
6969
- })
6914
+ });
6915
+ }
6970
6916
  });
6971
6917
  }
6972
6918
  function SelectInputTriggerButton({
@@ -7029,7 +6975,7 @@ const SelectInputOptionsContainer = /*#__PURE__*/React.forwardRef(function Selec
7029
6975
  });
7030
6976
  function SelectInputOptions({
7031
6977
  items,
7032
- renderValue = wrapInFragment,
6978
+ renderValue = String,
7033
6979
  renderFooter,
7034
6980
  filterable = false,
7035
6981
  filterPlaceholder,
@@ -7297,10 +7243,13 @@ const formatWithPattern = (value, pattern) => {
7297
7243
  let patternSymbol = [];
7298
7244
  // valueArray.length increments during the cycle cause we are adding new elements.
7299
7245
  for (let index = 0; index < valueArray.length; index += 1) {
7300
- patternSymbol = patternWithSymbolsPosition.filter(symbol => symbol.index === index);
7246
+ patternSymbol = patternWithSymbolsPosition.filter(pattern => pattern.index === index);
7301
7247
  // Add pattern's symbol at n position
7302
7248
  if (patternSymbol.length === 1) {
7303
- valueArray.splice(index, 0, patternSymbol.pop().symbol);
7249
+ const last = patternSymbol.pop();
7250
+ if (last) {
7251
+ valueArray.splice(index, 0, last.symbol);
7252
+ }
7304
7253
  }
7305
7254
  }
7306
7255
  return valueArray.join('');
@@ -7346,7 +7295,7 @@ const countConsecutiveSymbols = (selectionStart, applicablePattern, direction) =
7346
7295
  return groupSize;
7347
7296
  };
7348
7297
 
7349
- const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
7298
+ const getCursorPositionAfterActionStroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
7350
7299
  let cursorPosition = selectionStart;
7351
7300
  switch (action) {
7352
7301
  case 'Backspace':
@@ -7368,36 +7317,36 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
7368
7317
  }
7369
7318
  return cursorPosition;
7370
7319
  };
7371
- var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
7320
+ var getCursorPositionAfterKeystroke = getCursorPositionAfterActionStroke;
7372
7321
 
7373
7322
  class WithDisplayFormat extends React.Component {
7323
+ static defaultProps = {
7324
+ autoComplete: 'off',
7325
+ displayPattern: '',
7326
+ value: ''
7327
+ };
7374
7328
  constructor(props) {
7375
7329
  super(props);
7376
- const {
7377
- value,
7378
- displayPattern
7379
- } = props;
7380
- const unformattedValue = unformatWithPattern$1(value, displayPattern);
7330
+ const unformattedValue = unformatWithPattern$1(props.value ?? '', props.displayPattern);
7381
7331
  this.state = {
7382
- value: formatWithPattern$1(unformattedValue, displayPattern),
7332
+ value: formatWithPattern$1(unformattedValue, props.displayPattern),
7383
7333
  historyNavigator: new HistoryNavigator$1(),
7384
7334
  prevDisplayPattern: props.displayPattern,
7385
- triggerType: null,
7386
- triggerEvent: null
7335
+ triggerType: 'Initial',
7336
+ triggerEvent: null,
7337
+ selectionStart: 0,
7338
+ selectionEnd: 0,
7339
+ pastedLength: 0
7387
7340
  };
7388
7341
  }
7389
- static getDerivedStateFromProps(nextProps, previousState) {
7390
- const {
7391
- displayPattern
7392
- } = nextProps;
7393
- const {
7394
- prevDisplayPattern
7395
- } = previousState;
7396
- if (previousState.prevDisplayPattern !== displayPattern) {
7397
- const {
7398
- value,
7399
- historyNavigator
7400
- } = previousState;
7342
+ static getDerivedStateFromProps({
7343
+ displayPattern
7344
+ }, {
7345
+ prevDisplayPattern = displayPattern,
7346
+ value,
7347
+ historyNavigator
7348
+ }) {
7349
+ if (prevDisplayPattern !== displayPattern) {
7401
7350
  const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
7402
7351
  historyNavigator.reset();
7403
7352
  return {
@@ -7419,29 +7368,31 @@ class WithDisplayFormat extends React.Component {
7419
7368
  const {
7420
7369
  displayPattern
7421
7370
  } = this.props;
7422
- const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7423
- if (triggerType === 'Paste' || triggerType === 'Cut') {
7424
- return triggerType;
7425
- }
7426
- if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7427
- return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7428
- }
7429
- // Detect mouse event redo
7430
- if (triggerEvent.ctrlKey && charCode === 'd') {
7431
- return 'Delete';
7432
- }
7433
-
7434
- // Android Fix.
7435
- if (typeof triggerEvent.key === 'undefined') {
7436
- if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7371
+ if (triggerEvent) {
7372
+ const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7373
+ if (triggerType === 'Paste' || triggerType === 'Cut') {
7374
+ return triggerType;
7375
+ }
7376
+ if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7377
+ return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7378
+ }
7379
+ // Detect mouse event redo
7380
+ if (triggerEvent.ctrlKey && charCode === 'd') {
7381
+ return 'Delete';
7382
+ }
7383
+ // Android Fix.
7384
+ if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7437
7385
  return 'Backspace';
7438
7386
  }
7387
+ return triggerEvent.key;
7388
+ } else {
7389
+ // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7390
+ return 'Paste';
7439
7391
  }
7440
- return triggerEvent.key;
7441
7392
  };
7442
7393
  resetEvent = () => {
7443
7394
  this.setState({
7444
- triggerType: null,
7395
+ triggerType: 'Initial',
7445
7396
  triggerEvent: null,
7446
7397
  pastedLength: 0
7447
7398
  });
@@ -7458,14 +7409,13 @@ class WithDisplayFormat extends React.Component {
7458
7409
  const {
7459
7410
  selectionStart,
7460
7411
  selectionEnd
7461
- } = event.target;
7412
+ } = event.currentTarget;
7462
7413
  const {
7463
7414
  historyNavigator
7464
7415
  } = this.state;
7465
7416
  const {
7466
7417
  displayPattern
7467
7418
  } = this.props;
7468
-
7469
7419
  // Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
7470
7420
  let newFormattedValue = '';
7471
7421
  if (this.detectUndoRedo(event) === 'Undo') {
@@ -7484,8 +7434,8 @@ class WithDisplayFormat extends React.Component {
7484
7434
  this.setState({
7485
7435
  triggerEvent: event,
7486
7436
  triggerType: 'KeyDown',
7487
- selectionStart,
7488
- selectionEnd
7437
+ selectionStart: selectionStart ?? 0,
7438
+ selectionEnd: selectionEnd ?? 0
7489
7439
  });
7490
7440
  }
7491
7441
  };
@@ -7514,7 +7464,6 @@ class WithDisplayFormat extends React.Component {
7514
7464
  handleOnChange = event => {
7515
7465
  const {
7516
7466
  historyNavigator,
7517
- triggerEvent,
7518
7467
  triggerType
7519
7468
  } = this.state;
7520
7469
  const {
@@ -7525,9 +7474,7 @@ class WithDisplayFormat extends React.Component {
7525
7474
  value
7526
7475
  } = event.target;
7527
7476
  let unformattedValue = unformatWithPattern$1(value, displayPattern);
7528
- const action = triggerEvent === null ?
7529
- // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7530
- 'Paste' : this.getUserAction(unformattedValue);
7477
+ const action = this.getUserAction(unformattedValue);
7531
7478
  if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
7532
7479
  return;
7533
7480
  }
@@ -7537,19 +7484,18 @@ class WithDisplayFormat extends React.Component {
7537
7484
  const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
7538
7485
  historyNavigator.add(unformattedValue);
7539
7486
  this.handleCursorPositioning(action);
7540
- const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7541
7487
  this.setState({
7542
7488
  value: newFormattedValue
7543
- }, this.resetEvent(), onChange(broadcastValue));
7489
+ }, () => {
7490
+ this.resetEvent();
7491
+ if (onChange) {
7492
+ const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7493
+ onChange(broadcastValue);
7494
+ }
7495
+ });
7544
7496
  };
7545
7497
  handleOnBlur = event => {
7546
- const {
7547
- displayPattern,
7548
- onBlur
7549
- } = this.props;
7550
- if (onBlur) {
7551
- onBlur(unformatWithPattern$1(event.target.value, displayPattern));
7552
- }
7498
+ this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
7553
7499
  };
7554
7500
  handleOnFocus = event => {
7555
7501
  const {
@@ -7598,7 +7544,7 @@ class WithDisplayFormat extends React.Component {
7598
7544
  const cursorPosition = getCursorPositionAfterKeystroke(action, selectionStart, selectionEnd, displayPattern, pastedLength);
7599
7545
  setTimeout(() => {
7600
7546
  if (triggerEvent) {
7601
- triggerEvent.target.setSelectionRange(cursorPosition, cursorPosition);
7547
+ triggerEvent.currentTarget.setSelectionRange(cursorPosition, cursorPosition);
7602
7548
  }
7603
7549
  this.setState({
7604
7550
  selectionStart: cursorPosition,
@@ -7608,7 +7554,6 @@ class WithDisplayFormat extends React.Component {
7608
7554
  };
7609
7555
  render() {
7610
7556
  const {
7611
- type,
7612
7557
  inputMode,
7613
7558
  className,
7614
7559
  id,
@@ -7625,7 +7570,6 @@ class WithDisplayFormat extends React.Component {
7625
7570
  value
7626
7571
  } = this.state;
7627
7572
  const renderProps = {
7628
- type,
7629
7573
  inputMode,
7630
7574
  className,
7631
7575
  id,
@@ -7648,62 +7592,13 @@ class WithDisplayFormat extends React.Component {
7648
7592
  return this.props.render(renderProps);
7649
7593
  }
7650
7594
  }
7651
- WithDisplayFormat.propTypes = {
7652
- /**
7653
- * autocomplete hides our form help so we need to disable it when help text
7654
- * is present. Chrome ignores autocomplete=off, the only way to disable it is
7655
- * to provide an 'invalid' value, for which 'disabled' serves.
7656
- */
7657
- autoComplete: PropTypes__default.default.oneOf(['on', 'off', 'disabled']),
7658
- className: PropTypes__default.default.string,
7659
- disabled: PropTypes__default.default.bool,
7660
- id: PropTypes__default.default.string,
7661
- maxLength: PropTypes__default.default.number,
7662
- minLength: PropTypes__default.default.number,
7663
- name: PropTypes__default.default.string,
7664
- onFocus: PropTypes__default.default.func,
7665
- onBlur: PropTypes__default.default.func,
7666
- onChange: PropTypes__default.default.func.isRequired,
7667
- placeholder: PropTypes__default.default.string,
7668
- readOnly: PropTypes__default.default.bool,
7669
- render: PropTypes__default.default.func.isRequired,
7670
- required: PropTypes__default.default.bool,
7671
- displayPattern: PropTypes__default.default.string,
7672
- type: PropTypes__default.default.string,
7673
- inputMode: PropTypes__default.default.string,
7674
- value: PropTypes__default.default.string
7675
- };
7676
- WithDisplayFormat.defaultProps = {
7677
- autoComplete: 'off',
7678
- className: null,
7679
- disabled: false,
7680
- id: null,
7681
- maxLength: null,
7682
- minLength: null,
7683
- name: null,
7684
- placeholder: null,
7685
- readOnly: false,
7686
- required: false,
7687
- displayPattern: '',
7688
- type: 'text',
7689
- inputMode: null,
7690
- value: '',
7691
- onFocus: null,
7692
- onBlur: null
7693
- };
7694
- var WithDisplayFormat$1 = WithDisplayFormat;
7695
7595
 
7696
- const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat$1, {
7596
+ const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
7697
7597
  ...props,
7698
- render: renderProps => /*#__PURE__*/jsxRuntime.jsx("input", {
7598
+ render: renderProps => /*#__PURE__*/jsxRuntime.jsx(Input, {
7699
7599
  ...renderProps
7700
7600
  })
7701
7601
  });
7702
- InputWithDisplayFormat.propTypes = {
7703
- displayPattern: PropTypes__default.default.string.isRequired,
7704
- onChange: PropTypes__default.default.func.isRequired
7705
- };
7706
- var InputWithDisplayFormat$1 = InputWithDisplayFormat;
7707
7602
 
7708
7603
  const InstructionsList = ({
7709
7604
  dos,
@@ -9652,111 +9547,79 @@ const countries = [{
9652
9547
  iso3: 'ZWE',
9653
9548
  phone: '+263'
9654
9549
  }];
9655
- var countries$1 = countries;
9656
9550
 
9657
9551
  const longestMatchingPrefix = matchingCodes => matchingCodes.reduce((a, b) => a.phone.length > b.phone.length ? a : b);
9658
9552
 
9659
9553
  const findCountryByCode = code => {
9660
- let matchingCodes;
9661
- if (code && code.length === 2) {
9662
- matchingCodes = countries$1.filter(country => code.toUpperCase() === country.iso2);
9554
+ if (code.length === 2) {
9555
+ const matchingCodes = countries.filter(country => code.toUpperCase() === country.iso2);
9556
+ if (matchingCodes.length > 0) {
9557
+ return longestMatchingPrefix(matchingCodes);
9558
+ }
9663
9559
  }
9664
- return matchingCodes && matchingCodes.length > 0 ? longestMatchingPrefix(matchingCodes) : null;
9560
+ return null;
9665
9561
  };
9666
9562
 
9667
9563
  /**
9668
9564
  * Default phone code, the UK one `+44`
9669
9565
  */
9670
9566
  const DEFAULT_PHONE_CODE = '+44';
9671
-
9672
9567
  /**
9673
9568
  * Given a valid locale it returns the correspondent prefix if found or +44 otherwise.
9674
9569
  *
9675
- * @param {string} locale - a string that represent the locale ex:'es-ES'
9676
- * @param countryCode
9677
- * @returns {string}
9570
+ * @param locale BCP 47 language tag of locale, e.g. `"es-ES"`.
9571
+ * @param countryCode Two-letter country code (ISO 3166-1 alpha-2).
9678
9572
  */
9679
9573
  const setDefaultPrefix = (locale, countryCode) => {
9680
- const country = findCountryByCode(countryCode) ||
9681
- // when `locale` code has explicit region: `en-GB`, `en-US`, `ar-AE`
9682
- findCountryByCode(getCountryFromLocale(locale)) ||
9683
- // when `locale` code is only two chars value: `fr`, `es`
9684
- findCountryByCode(locale);
9685
- return country?.phone || DEFAULT_PHONE_CODE;
9574
+ const country = (countryCode != null ? findCountryByCode(countryCode) : null) ?? findCountryByCode(getCountryFromLocale(locale) ?? locale);
9575
+ return country?.phone ?? DEFAULT_PHONE_CODE;
9686
9576
  };
9687
9577
 
9688
9578
  /**
9689
9579
  *
9690
9580
  * @param phoneNumber
9691
- * @returns {boolean} - returns true for number that starts with '+' and contains a mix of digits and spaces with
9692
- * at least 4 digits.
9581
+ * @returns True if number that starts with "+" and contains a mix of digits and spaces with at least 4 digits.
9693
9582
  */
9694
- const isValidPhoneNumber = phoneNumber => /^\+[\d-\s]+$/.test(phoneNumber) && phoneNumber.match(/\d+/g) && phoneNumber.match(/\d+/g).join('').length >= 4;
9583
+ const isValidPhoneNumber = phoneNumber => /^\+[\d-\s]+$/.test(phoneNumber) && (phoneNumber.match(/\d+/g)?.join('').length ?? 0) >= 4;
9695
9584
 
9696
9585
  const findCountryByPrefix = number => {
9697
- let matchingCodes = null;
9698
- if (number && number.length > 1) {
9699
- matchingCodes = countries$1.filter(country => number.indexOf(country.phone) === 0);
9586
+ if (number.length > 1) {
9587
+ const matchingCodes = countries.filter(country => number.startsWith(country.phone));
9588
+ if (matchingCodes.length > 0) {
9589
+ return longestMatchingPrefix(matchingCodes);
9590
+ }
9700
9591
  }
9701
- return matchingCodes && matchingCodes.length > 0 ? longestMatchingPrefix(matchingCodes) : null;
9592
+ return null;
9702
9593
  };
9703
9594
 
9704
9595
  /**
9705
- * Given a sting in a valid format ex:'+447573135343' it returns an object of shape
9706
- * {prefix=+44 ,suffix=7573135343}
9707
- *
9708
- * @param {string} number - a string that defines a phone number.
9709
- * @returns {{prefix: (string|*), suffix: string, format: string}}
9596
+ * @param number Phone number in a format like "+447573135343"
9710
9597
  */
9711
9598
  const explodeNumberModel = number => {
9712
- let prefix = '';
9713
- let suffix = '';
9714
- let format = '';
9715
9599
  const country = findCountryByPrefix(number);
9716
- if (country) {
9717
- prefix = country.phone;
9718
- suffix = number.slice(country.phone.length);
9719
- format = country.phoneFormat || '';
9720
- } else {
9721
- prefix = '';
9722
- suffix = number.slice(1);
9723
- format = '';
9724
- }
9725
- return {
9726
- prefix,
9727
- suffix,
9728
- format
9600
+ return country ? {
9601
+ prefix: country.phone,
9602
+ suffix: number.slice(country.phone.length),
9603
+ format: country.phoneFormat
9604
+ } : {
9605
+ prefix: null,
9606
+ suffix: number.slice(1)
9729
9607
  };
9730
9608
  };
9731
9609
 
9732
9610
  const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
9733
- const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
9611
+ const cleanNumber = number => number.match(DIGITS_MATCH)?.join('') ?? '';
9734
9612
 
9735
- // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
9736
- const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
9613
+ function sortArrayByProperty(arrayToSort, property) {
9614
+ return [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
9615
+ }
9737
9616
 
9738
9617
  const groupCountriesByPrefix = countries => {
9739
- const groupedArray = countries.reduce((accumulator, country) => {
9740
- const {
9741
- name,
9742
- iso2,
9743
- iso3,
9744
- phone
9745
- } = country;
9746
- if (accumulator[phone]) {
9747
- const previousValue = accumulator[phone];
9748
- accumulator[phone] = {
9749
- ...previousValue,
9750
- name: neptuneValidation.isArray(previousValue.name) ? [...previousValue.name, name] : [previousValue.name, name],
9751
- iso2: neptuneValidation.isArray(previousValue.iso2) ? [...previousValue.iso2, iso2] : [previousValue.iso2, iso2],
9752
- iso3: neptuneValidation.isArray(previousValue.iso3) ? [...previousValue.iso3, iso3] : [previousValue.iso3, iso3]
9753
- };
9754
- } else {
9755
- accumulator[phone] = country;
9756
- }
9757
- return accumulator;
9758
- }, {});
9759
- return Object.values(groupedArray);
9618
+ const countriesByPrefix = new Map();
9619
+ countries.forEach(country => {
9620
+ countriesByPrefix.set(country.phone, [...(countriesByPrefix.get(country.phone) ?? []), country]);
9621
+ });
9622
+ return countriesByPrefix;
9760
9623
  };
9761
9624
 
9762
9625
  // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
@@ -9764,41 +9627,38 @@ const filterCountriesByIso3 = (countries, iso3Codes) => {
9764
9627
  const iso3CodesSet = new Set(iso3Codes);
9765
9628
  return countries.filter(country => !iso3CodesSet.has(country.iso3));
9766
9629
  };
9767
-
9768
9630
  /**
9769
9631
  * Removes the countries sepecified in the second param
9770
9632
  *
9771
- * @param {Array} countries: list of country metadata objects
9772
- * @param {Array} disabledCountries: list of iso3 country codes to remove from the list
9773
- * @returns
9633
+ * @param countries list of country metadata objects
9634
+ * @param disabledCountries list of iso3 country codes to remove from the list
9774
9635
  */
9775
9636
  const excludeCountries = (countries, disabledCountries) => {
9776
9637
  return disabledCountries.length > 0 ? filterCountriesByIso3(countries, disabledCountries) : countries;
9777
9638
  };
9778
9639
 
9779
9640
  const ALLOWED_PHONE_CHARS = /^$|^[\d-\s]+$/;
9780
- const PhoneNumberInput = props => {
9781
- const {
9782
- id,
9783
- onChange,
9784
- searchPlaceholder,
9785
- disabled,
9786
- required,
9787
- size,
9788
- placeholder,
9789
- onFocus,
9790
- onBlur,
9791
- countryCode,
9792
- selectProps,
9793
- disabledCountries
9794
- } = props;
9641
+ const defaultSelectProps = {};
9642
+ const defaultDisabledCountries = [];
9643
+ const PhoneNumberInput = ({
9644
+ id,
9645
+ required,
9646
+ disabled,
9647
+ initialValue,
9648
+ onChange,
9649
+ onFocus,
9650
+ onBlur,
9651
+ countryCode,
9652
+ searchPlaceholder = 'Prefix',
9653
+ size = exports.Size.MEDIUM,
9654
+ placeholder,
9655
+ selectProps = defaultSelectProps,
9656
+ disabledCountries = defaultDisabledCountries
9657
+ }) => {
9795
9658
  const {
9796
9659
  locale
9797
9660
  } = reactIntl.useIntl();
9798
- const getInitialValue = () => {
9799
- const {
9800
- initialValue
9801
- } = props;
9661
+ const [internalValue, setInternalValue] = React.useState(() => {
9802
9662
  const cleanValue = initialValue ? cleanNumber(initialValue) : null;
9803
9663
  if (!cleanValue || !isValidPhoneNumber(cleanValue)) {
9804
9664
  return {
@@ -9807,54 +9667,16 @@ const PhoneNumberInput = props => {
9807
9667
  };
9808
9668
  }
9809
9669
  return explodeNumberModel(cleanValue);
9810
- };
9811
- const [internalValue, setInternalValue] = React.useState(getInitialValue());
9670
+ });
9812
9671
  const [broadcastedValue, setBroadcastedValue] = React.useState(null);
9813
- const getSelectOptions = () => {
9814
- const countriesList = excludeCountries(countries$1, disabledCountries);
9815
- const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
9816
- return listSortedByISO3.map(option => {
9817
- const {
9818
- phone,
9819
- iso3,
9820
- iso2,
9821
- name
9822
- } = option;
9823
- let note = '';
9824
- if (iso3) {
9825
- note = neptuneValidation.isArray(iso3) ? iso3.join(', ') : iso3;
9826
- } else if (iso2) {
9827
- note = neptuneValidation.isArray(iso2) ? iso2.join(', ') : iso2;
9828
- }
9829
- return {
9830
- type: 'option',
9831
- value: {
9832
- value: phone,
9833
- label: phone,
9834
- note: note
9835
- },
9836
- filterMatchers: [phone, note, name]
9837
- };
9838
- });
9839
- };
9840
- const options = getSelectOptions();
9841
- const onPrefixChange = ({
9842
- value
9843
- }) => {
9844
- setInternalValue({
9845
- prefix: value,
9846
- suffix: internalValue.suffix
9847
- });
9848
- };
9672
+ const countriesByPrefix = React.useMemo(() => groupCountriesByPrefix(sortArrayByProperty(excludeCountries(countries, disabledCountries), 'iso3')), [disabledCountries]);
9849
9673
  const onSuffixChange = event => {
9850
- const {
9851
- value = ''
9852
- } = event.target;
9853
- if (ALLOWED_PHONE_CHARS.test(value)) {
9854
- setInternalValue({
9855
- prefix: internalValue.prefix,
9856
- suffix: value
9857
- });
9674
+ const suffix = event.target.value;
9675
+ if (ALLOWED_PHONE_CHARS.test(suffix)) {
9676
+ setInternalValue(prev => ({
9677
+ ...prev,
9678
+ suffix
9679
+ }));
9858
9680
  }
9859
9681
  };
9860
9682
  const onPaste = event => {
@@ -9862,31 +9684,22 @@ const PhoneNumberInput = props => {
9862
9684
  return;
9863
9685
  }
9864
9686
  const pastedValue = (event.nativeEvent.clipboardData.getData('text/plain') || '').replace(/(\s|-)+/g, '');
9865
- const {
9866
- prefix: pastedPrefix,
9867
- suffix: pastedSuffix
9868
- } = explodeNumberModel(pastedValue);
9869
- const selectedPrefix = options.find(({
9870
- value
9871
- }) => value.value === pastedPrefix);
9872
- if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
9873
- setInternalValue({
9874
- prefix: pastedPrefix,
9875
- suffix: pastedSuffix
9876
- });
9687
+ const pastedNumber = explodeNumberModel(pastedValue);
9688
+ if (pastedNumber.prefix != null && countriesByPrefix.has(pastedNumber.prefix) && ALLOWED_PHONE_CHARS.test(pastedNumber.suffix)) {
9689
+ setInternalValue(pastedNumber);
9877
9690
  }
9878
9691
  };
9879
9692
  React.useEffect(() => {
9880
9693
  if (broadcastedValue === null) {
9881
9694
  return setBroadcastedValue(internalValue);
9882
9695
  }
9883
- const internalPhoneNumber = internalValue.prefix + internalValue.suffix;
9884
- const broadcastedPhoneNumber = broadcastedValue.prefix + broadcastedValue.suffix;
9696
+ const internalPhoneNumber = `${internalValue.prefix ?? ''}${internalValue.suffix}`;
9697
+ const broadcastedPhoneNumber = `${broadcastedValue.prefix ?? ''}${broadcastedValue.suffix}`;
9885
9698
  if (internalPhoneNumber === broadcastedPhoneNumber) {
9886
9699
  return;
9887
9700
  }
9888
9701
  const newValue = isValidPhoneNumber(internalPhoneNumber) ? cleanNumber(internalPhoneNumber) : null;
9889
- onChange(newValue, internalValue.prefix);
9702
+ onChange(newValue, internalValue.prefix ?? '');
9890
9703
  setBroadcastedValue(internalValue);
9891
9704
  }, [onChange, broadcastedValue, internalValue]);
9892
9705
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
@@ -9894,18 +9707,29 @@ const PhoneNumberInput = props => {
9894
9707
  children: [/*#__PURE__*/jsxRuntime.jsx("div", {
9895
9708
  className: "tw-telephone__country-select",
9896
9709
  children: /*#__PURE__*/jsxRuntime.jsx(SelectInput, {
9897
- placeholder: "Select an option...",
9898
- items: options,
9899
- value: options.find(item => item.value.value === internalValue.prefix)?.value,
9900
- renderValue: (option, withinTrigger) => /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContent, {
9901
- title: option.label,
9902
- note: withinTrigger ? undefined : option.note
9710
+ placeholder: "Select an option\u2026",
9711
+ items: [...countriesByPrefix].map(([prefix, countries]) => ({
9712
+ type: 'option',
9713
+ value: prefix,
9714
+ filterMatchers: [prefix, ...countries.map(country => country.name), ...countries.map(country => country.iso3)]
9715
+ })),
9716
+ value: internalValue.prefix,
9717
+ renderValue: (prefix, withinTrigger) => /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContent, {
9718
+ title: prefix,
9719
+ note: withinTrigger ? undefined : countriesByPrefix.get(prefix)?.map(country => country.iso3).join(', ')
9903
9720
  }),
9904
9721
  filterable: true,
9905
9722
  filterPlaceholder: searchPlaceholder,
9906
9723
  disabled: disabled,
9907
9724
  size: size,
9908
- onChange: onPrefixChange,
9725
+ onChange: prefix => {
9726
+ const country = prefix != null ? findCountryByPrefix(prefix) : null;
9727
+ setInternalValue(prev => ({
9728
+ ...prev,
9729
+ prefix,
9730
+ format: country?.phoneFormat
9731
+ }));
9732
+ },
9909
9733
  ...selectProps
9910
9734
  })
9911
9735
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
@@ -9931,37 +9755,6 @@ const PhoneNumberInput = props => {
9931
9755
  })]
9932
9756
  });
9933
9757
  };
9934
- PhoneNumberInput.propTypes = {
9935
- id: PropTypes__default.default.string,
9936
- required: PropTypes__default.default.bool,
9937
- disabled: PropTypes__default.default.bool,
9938
- initialValue: PropTypes__default.default.string,
9939
- onChange: PropTypes__default.default.func.isRequired,
9940
- onFocus: PropTypes__default.default.func,
9941
- onBlur: PropTypes__default.default.func,
9942
- countryCode: PropTypes__default.default.string,
9943
- searchPlaceholder: PropTypes__default.default.string,
9944
- size: PropTypes__default.default.oneOf(['sm', 'md', 'lg']),
9945
- placeholder: PropTypes__default.default.string,
9946
- selectProps: PropTypes__default.default.object,
9947
- /** List of iso3 codes of countries to remove from the list */
9948
- disabledCountries: PropTypes__default.default.arrayOf(PropTypes__default.default.string)
9949
- };
9950
- PhoneNumberInput.defaultProps = {
9951
- id: null,
9952
- required: false,
9953
- disabled: false,
9954
- initialValue: null,
9955
- onFocus() {},
9956
- onBlur() {},
9957
- countryCode: null,
9958
- searchPlaceholder: 'Prefix',
9959
- size: exports.Size.MEDIUM,
9960
- placeholder: '',
9961
- selectProps: {},
9962
- disabledCountries: []
9963
- };
9964
- var PhoneNumberInput$1 = PhoneNumberInput;
9965
9758
 
9966
9759
  const Progress = ({
9967
9760
  className,
@@ -12380,17 +12173,12 @@ Tabs.defaultProps = {
12380
12173
  };
12381
12174
  var Tabs$1 = Tabs;
12382
12175
 
12383
- const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat$1, {
12176
+ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
12384
12177
  ...props,
12385
- render: renderProps => /*#__PURE__*/jsxRuntime.jsx("textarea", {
12178
+ render: renderProps => /*#__PURE__*/jsxRuntime.jsx(TextArea, {
12386
12179
  ...renderProps
12387
12180
  })
12388
12181
  });
12389
- TextareaWithDisplayFormat.propTypes = {
12390
- displayPattern: PropTypes__default.default.string.isRequired,
12391
- onChange: PropTypes__default.default.func.isRequired
12392
- };
12393
- var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
12394
12182
 
12395
12183
  /* eslint-disable jsx-a11y/no-autofocus */
12396
12184
  /* eslint-disable jsx-a11y/click-events-have-key-events */
@@ -15392,16 +15180,16 @@ var th = {
15392
15180
  "neptune.DateInput.year.label": "ปี",
15393
15181
  "neptune.DateInput.year.placeholder": "YYYY",
15394
15182
  "neptune.DateLookup.day": "วัน",
15395
- "neptune.DateLookup.goTo20YearView": "Go to 20 year view",
15183
+ "neptune.DateLookup.goTo20YearView": "ไปที่มุมมอง 20 ปี",
15396
15184
  "neptune.DateLookup.month": "เดือน",
15397
15185
  "neptune.DateLookup.next": "ถัดไป",
15398
15186
  "neptune.DateLookup.previous": "ก่อนหน้า",
15399
15187
  "neptune.DateLookup.selected": "เลือกแล้ว",
15400
15188
  "neptune.DateLookup.twentyYears": "20 ปี",
15401
15189
  "neptune.DateLookup.year": "ปี",
15402
- "neptune.FlowNavigation.back": "back to previous step",
15190
+ "neptune.FlowNavigation.back": "กลับไปที่ขั้นก่อนหน้า",
15403
15191
  "neptune.Info.ariaLabel": "ข้อมูลเพิ่มเติม",
15404
- "neptune.Link.opensInNewTab": "(opens in new tab)",
15192
+ "neptune.Link.opensInNewTab": "(เปิดในแท็บใหม่)",
15405
15193
  "neptune.MoneyInput.Select.placeholder": "เลือกตัวเลือก...",
15406
15194
  "neptune.Select.searchPlaceholder": "ค้นหา...",
15407
15195
  "neptune.SelectInput.noResultsFound": "ไม่พบผลลัพธ์",
@@ -15727,7 +15515,7 @@ exports.Info = Info;
15727
15515
  exports.InlineAlert = InlineAlert;
15728
15516
  exports.Input = Input;
15729
15517
  exports.InputGroup = InputGroup;
15730
- exports.InputWithDisplayFormat = InputWithDisplayFormat$1;
15518
+ exports.InputWithDisplayFormat = InputWithDisplayFormat;
15731
15519
  exports.InstructionsList = InstructionsList$1;
15732
15520
  exports.LanguageProvider = LanguageProvider;
15733
15521
  exports.Link = Link;
@@ -15743,7 +15531,7 @@ exports.NavigationOptionsList = NavigationOptionList$1;
15743
15531
  exports.Nudge = Nudge;
15744
15532
  exports.Option = Option$2;
15745
15533
  exports.OverlayHeader = OverlayHeader$1;
15746
- exports.PhoneNumberInput = PhoneNumberInput$1;
15534
+ exports.PhoneNumberInput = PhoneNumberInput;
15747
15535
  exports.Popover = Popover$2;
15748
15536
  exports.ProcessIndicator = ProcessIndicator$1;
15749
15537
  exports.Progress = Progress;
@@ -15775,7 +15563,7 @@ exports.Switch = Switch;
15775
15563
  exports.SwitchOption = SwitchOption;
15776
15564
  exports.Tabs = Tabs$1;
15777
15565
  exports.TextArea = TextArea;
15778
- exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat$1;
15566
+ exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat;
15779
15567
  exports.Title = Title;
15780
15568
  exports.Tooltip = Tooltip$1;
15781
15569
  exports.Typeahead = Typeahead;