@transferwise/components 0.0.0-experimental-85b9dd1 → 0.0.0-experimental-0db2ae7

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 (151) hide show
  1. package/build/index.esm.js +335 -234
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +336 -235
  4. package/build/index.js.map +1 -1
  5. package/build/types/common/locale/index.d.ts +43 -26
  6. package/build/types/common/locale/index.d.ts.map +1 -1
  7. package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts +1 -1
  8. package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts.map +1 -1
  9. package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts +2 -2
  10. package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts.map +1 -1
  11. package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts +5 -1
  12. package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts.map +1 -1
  13. package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts +1 -1
  14. package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts.map +1 -1
  15. package/build/types/index.d.ts +2 -0
  16. package/build/types/index.d.ts.map +1 -1
  17. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +7 -11
  18. package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
  19. package/build/types/inputWithDisplayFormat/index.d.ts +2 -1
  20. package/build/types/inputWithDisplayFormat/index.d.ts.map +1 -1
  21. package/build/types/phoneNumberInput/PhoneNumberInput.d.ts +27 -22
  22. package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
  23. package/build/types/phoneNumberInput/data/countries.d.ts +10 -5
  24. package/build/types/phoneNumberInput/data/countries.d.ts.map +1 -1
  25. package/build/types/phoneNumberInput/index.d.ts +1 -1
  26. package/build/types/phoneNumberInput/index.d.ts.map +1 -1
  27. package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts +1 -1
  28. package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts.map +1 -1
  29. package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts +1 -1
  30. package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts.map +1 -1
  31. package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts +1 -8
  32. package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts.map +1 -1
  33. package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts +1 -1
  34. package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts.map +1 -1
  35. package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts +4 -8
  36. package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts.map +1 -1
  37. package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts +2 -0
  38. package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts.map +1 -0
  39. package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts +1 -1
  40. package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts.map +1 -1
  41. package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts +1 -1
  42. package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts.map +1 -1
  43. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts +1 -2
  44. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts.map +1 -1
  45. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts +1 -1
  46. package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts.map +1 -1
  47. package/build/types/phoneNumberInput/utils/index.d.ts +13 -11
  48. package/build/types/phoneNumberInput/utils/index.d.ts.map +1 -1
  49. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts +2 -0
  50. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts.map +1 -0
  51. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts +3 -0
  52. package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts.map +1 -0
  53. package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts +1 -1
  54. package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts.map +1 -1
  55. package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts +1 -1
  56. package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts.map +1 -1
  57. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts +1 -1
  58. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts.map +1 -1
  59. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts +1 -6
  60. package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts.map +1 -1
  61. package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts +1 -2
  62. package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts.map +1 -1
  63. package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts +1 -7
  64. package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts.map +1 -1
  65. package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts +1 -1
  66. package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts.map +1 -1
  67. package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts +1 -1
  68. package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts.map +1 -1
  69. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +7 -11
  70. package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
  71. package/build/types/textareaWithDisplayFormat/index.d.ts +2 -1
  72. package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
  73. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +54 -82
  74. package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
  75. package/build/types/withDisplayFormat/index.d.ts +2 -1
  76. package/build/types/withDisplayFormat/index.d.ts.map +1 -1
  77. package/package.json +1 -1
  78. package/src/common/locale/index.js +139 -0
  79. package/src/common/locale/{index.spec.ts → index.spec.js} +4 -4
  80. package/src/common/textFormat/formatWithPattern/{formatWithPattern.js → formatWithPattern.ts} +8 -4
  81. package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.js → getCursorPositionAfterKeystroke.ts} +8 -8
  82. package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.js → getSymbolsInPatternWithPosition.ts} +7 -2
  83. package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.js → unformatWithPattern.ts} +3 -2
  84. package/src/index.ts +2 -0
  85. package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +10 -0
  86. package/src/inputWithDisplayFormat/index.ts +2 -0
  87. package/src/phoneNumberInput/PhoneNumberInput.js +210 -0
  88. package/src/phoneNumberInput/PhoneNumberInput.spec.js +22 -18
  89. package/src/phoneNumberInput/data/{countries.ts → countries.js} +1 -9
  90. package/src/phoneNumberInput/data/countries.spec.js +12 -0
  91. package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.js +4 -0
  92. package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.ts → excludeCountries.js} +5 -6
  93. package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.spec.ts → excludeCountries.spec.js} +1 -1
  94. package/src/phoneNumberInput/utils/explodeNumberModel/{explodeNumberModel.spec.ts → explodeNumberModel.spec.js} +1 -1
  95. package/src/phoneNumberInput/utils/explodeNumberModel/index.js +27 -0
  96. package/src/phoneNumberInput/utils/filterOptionsForQuery/filterOptionsForQuery.spec.js +36 -0
  97. package/src/phoneNumberInput/utils/filterOptionsForQuery/index.js +11 -0
  98. package/src/phoneNumberInput/utils/findCountryByCode/{findCountryByCode.spec.ts → findCountryByCode.spec.js} +1 -0
  99. package/src/phoneNumberInput/utils/findCountryByCode/index.js +10 -0
  100. package/src/phoneNumberInput/utils/findCountryByPrefix/index.js +11 -0
  101. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.js +26 -0
  102. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.js +67 -0
  103. package/src/phoneNumberInput/utils/{index.ts → index.js} +2 -0
  104. package/src/phoneNumberInput/utils/isOptionAndFitsQuery/index.js +1 -0
  105. package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.js +25 -0
  106. package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.spec.js +66 -0
  107. package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.js +1 -0
  108. package/src/phoneNumberInput/utils/isStringNumeric/{isStringNumeric.spec.ts → isStringNumeric.spec.js} +1 -0
  109. package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.js +10 -0
  110. package/src/phoneNumberInput/utils/isValidPhoneNumber/{isValidPhoneNumber.spec.ts → isValidPhoneNumber.spec.js} +1 -1
  111. package/src/phoneNumberInput/utils/longestMatchingPrefix/index.js +2 -0
  112. package/src/phoneNumberInput/utils/setDefaultPrefix/index.js +25 -0
  113. package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.js +3 -0
  114. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +3 -1
  115. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +32 -0
  116. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +13 -0
  117. package/src/textareaWithDisplayFormat/index.ts +2 -0
  118. package/src/withDisplayFormat/WithDisplayFormat.spec.js +1 -1
  119. package/src/withDisplayFormat/{WithDisplayFormat.js → WithDisplayFormat.tsx} +127 -107
  120. package/src/withDisplayFormat/index.ts +2 -0
  121. package/src/common/locale/index.ts +0 -96
  122. package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +0 -14
  123. package/src/inputWithDisplayFormat/index.js +0 -1
  124. package/src/phoneNumberInput/PhoneNumberInput.tsx +0 -193
  125. package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.ts +0 -3
  126. package/src/phoneNumberInput/utils/explodeNumberModel/index.ts +0 -24
  127. package/src/phoneNumberInput/utils/findCountryByCode/index.ts +0 -12
  128. package/src/phoneNumberInput/utils/findCountryByPrefix/index.ts +0 -12
  129. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.ts +0 -102
  130. package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.ts +0 -12
  131. package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.ts +0 -1
  132. package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.ts +0 -7
  133. package/src/phoneNumberInput/utils/longestMatchingPrefix/index.ts +0 -4
  134. package/src/phoneNumberInput/utils/setDefaultPrefix/index.ts +0 -20
  135. package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.ts +0 -6
  136. package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +0 -14
  137. package/src/textareaWithDisplayFormat/index.js +0 -1
  138. package/src/withDisplayFormat/index.js +0 -1
  139. /package/src/phoneNumberInput/{PhoneNumberInput.story.tsx → PhoneNumberInput.story.js} +0 -0
  140. /package/src/phoneNumberInput/{index.ts → index.js} +0 -0
  141. /package/src/phoneNumberInput/utils/cleanNumber/{cleanNumber.spec.ts → cleanNumber.spec.js} +0 -0
  142. /package/src/phoneNumberInput/utils/cleanNumber/{index.ts → index.js} +0 -0
  143. /package/src/phoneNumberInput/utils/excludeCountries/{index.ts → index.js} +0 -0
  144. /package/src/phoneNumberInput/utils/findCountryByPrefix/{findCountryByPrefix.spec.ts → findCountryByPrefix.spec.js} +0 -0
  145. /package/src/phoneNumberInput/utils/groupCountriesByPrefix/{index.ts → index.js} +0 -0
  146. /package/src/phoneNumberInput/utils/isStringNumeric/{index.ts → index.js} +0 -0
  147. /package/src/phoneNumberInput/utils/isValidPhoneNumber/{index.ts → index.js} +0 -0
  148. /package/src/phoneNumberInput/utils/longestMatchingPrefix/{longestMatchingPrefix.spec.ts → longestMatchingPrefix.spec.js} +0 -0
  149. /package/src/phoneNumberInput/utils/setDefaultPrefix/{setDefaultPrefix.spec.ts → setDefaultPrefix.spec.js} +0 -0
  150. /package/src/phoneNumberInput/utils/sortArrayByProperty/{index.ts → index.js} +0 -0
  151. /package/src/phoneNumberInput/utils/sortArrayByProperty/{sortArrayByProperty.spec.ts → sortArrayByProperty.spec.js} +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 } from '@transferwise/neptune-validation';
22
+ import { isUndefined, isKey, isNumber, isEmpty, isNull, isArray } 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,76 +342,131 @@ const Key = {
342
342
  COMMA: ','
343
343
  };
344
344
 
345
+ /**
346
+ * Default language
347
+ *
348
+ * @type {string}
349
+ */
345
350
  const DEFAULT_LANG = 'en';
351
+
352
+ /**
353
+ * Default locale
354
+ *
355
+ * @type {string}
356
+ */
346
357
  const DEFAULT_LOCALE = 'en-GB';
358
+
347
359
  /**
348
- * Languages written right-to-left.
360
+ * Array of languages that are written from the right to the left
361
+ *
362
+ * @type {string[]}
349
363
  */
350
364
  const RTL_LANGUAGES = ['ar', 'he'];
365
+
351
366
  /**
352
367
  * @deprecated The source of truth for supported languages lives in Crab.
368
+ * @type {string[]}
353
369
  */
354
370
  const SUPPORTED_LANGUAGES = [DEFAULT_LANG, 'de', 'es', 'fr', 'hu', 'id', 'it', 'ja', 'pl', 'pt', 'ro', 'ru', 'th', 'tr', 'uk', 'zh'];
371
+
355
372
  /**
356
- * Verifies and adjusts locale, replacing `_` with `-`.
373
+ * Verifies and adjusts locale (replace `_` with `-`)
374
+ * Returns null if locale is unrecognized by {Intl.Locale}
357
375
  *
358
- * @param locale `es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP`, etc.
359
- * @returns `null` if locale is unrecognized by `Intl.Locale`.
376
+ * @param {string} locale (`es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
377
+ * @returns {string|null}
360
378
  */
361
379
  function adjustLocale(locale) {
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
- }
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;
370
392
  }
371
- return null;
372
393
  }
394
+
373
395
  /**
374
- * Provides corresponding lang (iso2) for provided locale.
396
+ * Provides corresponding lang (iso2) for provided locale
397
+ * if locale is invalid or language is unsupported returns null
375
398
  *
376
399
  * @deprecated The use of this function almost always breaks language variants
377
400
  * e.g. Simplified and Traditional Chinese.
378
401
  * There should be no use case for this function.
379
402
  * To select the correct translations from a translations object, pass the
380
403
  * locale directly into Crab's getLocalisedMessages.
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.
404
+ * @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
405
+ * @returns {string|null} two-letter ISO639-1 language
383
406
  */
384
407
  function getLangFromLocale(locale) {
385
408
  const adjustedLocale = adjustLocale(locale);
386
- if (adjustedLocale != null) {
409
+ if (adjustedLocale === null) {
410
+ return null;
411
+ }
412
+ try {
387
413
  const {
388
414
  language
389
415
  } = new Intl.Locale(adjustedLocale);
390
416
  if (SUPPORTED_LANGUAGES.includes(language)) {
391
417
  return language;
392
418
  }
419
+ return null;
420
+ } catch (error) {
421
+ // eslint-disable-next-line no-console
422
+ console.error(error);
423
+ return null;
393
424
  }
394
- return null;
395
425
  }
426
+
396
427
  /**
397
- * Provides corresponding country code (iso2) for locales code with explicit region value.
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
398
430
  *
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.
431
+ * @param {string} locale
432
+ * @returns {string|null}
401
433
  */
402
434
  function getCountryFromLocale(locale) {
403
435
  const adjustedLocale = adjustLocale(locale);
404
- return adjustedLocale != null ? new Intl.Locale(adjustedLocale).region ?? null : null;
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
+ }
405
449
  }
450
+
406
451
  /**
407
452
  * Provides the layout direction for a given locale.
453
+ * If locale is invalid or language is unsupported returns Direction.LTR
408
454
  *
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.
455
+ * @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
456
+ * @returns {Direction} The layout direction based on the locale
411
457
  */
412
458
  function getDirectionFromLocale(locale) {
413
- const adjustedLocale = adjustLocale(locale);
414
- return adjustedLocale != null && RTL_LANGUAGES.includes(new Intl.Locale(adjustedLocale).language) ? Direction.RTL : Direction.LTR;
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
+ }
415
470
  }
416
471
 
417
472
  /**
@@ -7208,10 +7263,13 @@ const formatWithPattern = (value, pattern) => {
7208
7263
  let patternSymbol = [];
7209
7264
  // valueArray.length increments during the cycle cause we are adding new elements.
7210
7265
  for (let index = 0; index < valueArray.length; index += 1) {
7211
- patternSymbol = patternWithSymbolsPosition.filter(symbol => symbol.index === index);
7266
+ patternSymbol = patternWithSymbolsPosition.filter(pattern => pattern.index === index);
7212
7267
  // Add pattern's symbol at n position
7213
7268
  if (patternSymbol.length === 1) {
7214
- valueArray.splice(index, 0, patternSymbol.pop().symbol);
7269
+ const last = patternSymbol.pop();
7270
+ if (last) {
7271
+ valueArray.splice(index, 0, last.symbol);
7272
+ }
7215
7273
  }
7216
7274
  }
7217
7275
  return valueArray.join('');
@@ -7257,7 +7315,7 @@ const countConsecutiveSymbols = (selectionStart, applicablePattern, direction) =
7257
7315
  return groupSize;
7258
7316
  };
7259
7317
 
7260
- const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
7318
+ const getCursorPositionAfterActionStroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
7261
7319
  let cursorPosition = selectionStart;
7262
7320
  switch (action) {
7263
7321
  case 'Backspace':
@@ -7279,36 +7337,36 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
7279
7337
  }
7280
7338
  return cursorPosition;
7281
7339
  };
7282
- var getCursorPositionAfterKeystroke = getCursorPositionAfteractionstroke;
7340
+ var getCursorPositionAfterKeystroke = getCursorPositionAfterActionStroke;
7283
7341
 
7284
7342
  class WithDisplayFormat extends Component {
7343
+ static defaultProps = {
7344
+ autoComplete: 'off',
7345
+ displayPattern: '',
7346
+ value: ''
7347
+ };
7285
7348
  constructor(props) {
7286
7349
  super(props);
7287
- const {
7288
- value,
7289
- displayPattern
7290
- } = props;
7291
- const unformattedValue = unformatWithPattern$1(value, displayPattern);
7350
+ const unformattedValue = unformatWithPattern$1(props.value ?? '', props.displayPattern);
7292
7351
  this.state = {
7293
- value: formatWithPattern$1(unformattedValue, displayPattern),
7352
+ value: formatWithPattern$1(unformattedValue, props.displayPattern),
7294
7353
  historyNavigator: new HistoryNavigator$1(),
7295
7354
  prevDisplayPattern: props.displayPattern,
7296
- triggerType: null,
7297
- triggerEvent: null
7355
+ triggerType: 'Initial',
7356
+ triggerEvent: null,
7357
+ selectionStart: 0,
7358
+ selectionEnd: 0,
7359
+ pastedLength: 0
7298
7360
  };
7299
7361
  }
7300
- static getDerivedStateFromProps(nextProps, previousState) {
7301
- const {
7302
- displayPattern
7303
- } = nextProps;
7304
- const {
7305
- prevDisplayPattern
7306
- } = previousState;
7307
- if (previousState.prevDisplayPattern !== displayPattern) {
7308
- const {
7309
- value,
7310
- historyNavigator
7311
- } = previousState;
7362
+ static getDerivedStateFromProps({
7363
+ displayPattern
7364
+ }, {
7365
+ prevDisplayPattern = displayPattern,
7366
+ value,
7367
+ historyNavigator
7368
+ }) {
7369
+ if (prevDisplayPattern !== displayPattern) {
7312
7370
  const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
7313
7371
  historyNavigator.reset();
7314
7372
  return {
@@ -7330,29 +7388,31 @@ class WithDisplayFormat extends Component {
7330
7388
  const {
7331
7389
  displayPattern
7332
7390
  } = this.props;
7333
- const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7334
- if (triggerType === 'Paste' || triggerType === 'Cut') {
7335
- return triggerType;
7336
- }
7337
- if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7338
- return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7339
- }
7340
- // Detect mouse event redo
7341
- if (triggerEvent.ctrlKey && charCode === 'd') {
7342
- return 'Delete';
7343
- }
7344
-
7345
- // Android Fix.
7346
- if (typeof triggerEvent.key === 'undefined') {
7347
- if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7391
+ if (triggerEvent) {
7392
+ const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
7393
+ if (triggerType === 'Paste' || triggerType === 'Cut') {
7394
+ return triggerType;
7395
+ }
7396
+ if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
7397
+ return triggerEvent.shiftKey ? 'Redo' : 'Undo';
7398
+ }
7399
+ // Detect mouse event redo
7400
+ if (triggerEvent.ctrlKey && charCode === 'd') {
7401
+ return 'Delete';
7402
+ }
7403
+ // Android Fix.
7404
+ if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
7348
7405
  return 'Backspace';
7349
7406
  }
7407
+ return triggerEvent.key;
7408
+ } else {
7409
+ // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7410
+ return 'Paste';
7350
7411
  }
7351
- return triggerEvent.key;
7352
7412
  };
7353
7413
  resetEvent = () => {
7354
7414
  this.setState({
7355
- triggerType: null,
7415
+ triggerType: 'Initial',
7356
7416
  triggerEvent: null,
7357
7417
  pastedLength: 0
7358
7418
  });
@@ -7369,14 +7429,13 @@ class WithDisplayFormat extends Component {
7369
7429
  const {
7370
7430
  selectionStart,
7371
7431
  selectionEnd
7372
- } = event.target;
7432
+ } = event.currentTarget;
7373
7433
  const {
7374
7434
  historyNavigator
7375
7435
  } = this.state;
7376
7436
  const {
7377
7437
  displayPattern
7378
7438
  } = this.props;
7379
-
7380
7439
  // Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
7381
7440
  let newFormattedValue = '';
7382
7441
  if (this.detectUndoRedo(event) === 'Undo') {
@@ -7395,8 +7454,8 @@ class WithDisplayFormat extends Component {
7395
7454
  this.setState({
7396
7455
  triggerEvent: event,
7397
7456
  triggerType: 'KeyDown',
7398
- selectionStart,
7399
- selectionEnd
7457
+ selectionStart: selectionStart ?? 0,
7458
+ selectionEnd: selectionEnd ?? 0
7400
7459
  });
7401
7460
  }
7402
7461
  };
@@ -7425,7 +7484,6 @@ class WithDisplayFormat extends Component {
7425
7484
  handleOnChange = event => {
7426
7485
  const {
7427
7486
  historyNavigator,
7428
- triggerEvent,
7429
7487
  triggerType
7430
7488
  } = this.state;
7431
7489
  const {
@@ -7436,9 +7494,7 @@ class WithDisplayFormat extends Component {
7436
7494
  value
7437
7495
  } = event.target;
7438
7496
  let unformattedValue = unformatWithPattern$1(value, displayPattern);
7439
- const action = triggerEvent === null ?
7440
- // triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
7441
- 'Paste' : this.getUserAction(unformattedValue);
7497
+ const action = this.getUserAction(unformattedValue);
7442
7498
  if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
7443
7499
  return;
7444
7500
  }
@@ -7448,19 +7504,18 @@ class WithDisplayFormat extends Component {
7448
7504
  const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
7449
7505
  historyNavigator.add(unformattedValue);
7450
7506
  this.handleCursorPositioning(action);
7451
- const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7452
7507
  this.setState({
7453
7508
  value: newFormattedValue
7454
- }, this.resetEvent(), onChange(broadcastValue));
7509
+ }, () => {
7510
+ this.resetEvent();
7511
+ if (onChange) {
7512
+ const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
7513
+ onChange(broadcastValue);
7514
+ }
7515
+ });
7455
7516
  };
7456
7517
  handleOnBlur = event => {
7457
- const {
7458
- displayPattern,
7459
- onBlur
7460
- } = this.props;
7461
- if (onBlur) {
7462
- onBlur(unformatWithPattern$1(event.target.value, displayPattern));
7463
- }
7518
+ this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
7464
7519
  };
7465
7520
  handleOnFocus = event => {
7466
7521
  const {
@@ -7509,7 +7564,7 @@ class WithDisplayFormat extends Component {
7509
7564
  const cursorPosition = getCursorPositionAfterKeystroke(action, selectionStart, selectionEnd, displayPattern, pastedLength);
7510
7565
  setTimeout(() => {
7511
7566
  if (triggerEvent) {
7512
- triggerEvent.target.setSelectionRange(cursorPosition, cursorPosition);
7567
+ triggerEvent.currentTarget.setSelectionRange(cursorPosition, cursorPosition);
7513
7568
  }
7514
7569
  this.setState({
7515
7570
  selectionStart: cursorPosition,
@@ -7519,7 +7574,6 @@ class WithDisplayFormat extends Component {
7519
7574
  };
7520
7575
  render() {
7521
7576
  const {
7522
- type,
7523
7577
  inputMode,
7524
7578
  className,
7525
7579
  id,
@@ -7536,7 +7590,6 @@ class WithDisplayFormat extends Component {
7536
7590
  value
7537
7591
  } = this.state;
7538
7592
  const renderProps = {
7539
- type,
7540
7593
  inputMode,
7541
7594
  className,
7542
7595
  id,
@@ -7559,62 +7612,13 @@ class WithDisplayFormat extends Component {
7559
7612
  return this.props.render(renderProps);
7560
7613
  }
7561
7614
  }
7562
- WithDisplayFormat.propTypes = {
7563
- /**
7564
- * autocomplete hides our form help so we need to disable it when help text
7565
- * is present. Chrome ignores autocomplete=off, the only way to disable it is
7566
- * to provide an 'invalid' value, for which 'disabled' serves.
7567
- */
7568
- autoComplete: PropTypes.oneOf(['on', 'off', 'disabled']),
7569
- className: PropTypes.string,
7570
- disabled: PropTypes.bool,
7571
- id: PropTypes.string,
7572
- maxLength: PropTypes.number,
7573
- minLength: PropTypes.number,
7574
- name: PropTypes.string,
7575
- onFocus: PropTypes.func,
7576
- onBlur: PropTypes.func,
7577
- onChange: PropTypes.func.isRequired,
7578
- placeholder: PropTypes.string,
7579
- readOnly: PropTypes.bool,
7580
- render: PropTypes.func.isRequired,
7581
- required: PropTypes.bool,
7582
- displayPattern: PropTypes.string,
7583
- type: PropTypes.string,
7584
- inputMode: PropTypes.string,
7585
- value: PropTypes.string
7586
- };
7587
- WithDisplayFormat.defaultProps = {
7588
- autoComplete: 'off',
7589
- className: null,
7590
- disabled: false,
7591
- id: null,
7592
- maxLength: null,
7593
- minLength: null,
7594
- name: null,
7595
- placeholder: null,
7596
- readOnly: false,
7597
- required: false,
7598
- displayPattern: '',
7599
- type: 'text',
7600
- inputMode: null,
7601
- value: '',
7602
- onFocus: null,
7603
- onBlur: null
7604
- };
7605
- var WithDisplayFormat$1 = WithDisplayFormat;
7606
7615
 
7607
- const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat$1, {
7616
+ const InputWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
7608
7617
  ...props,
7609
- render: renderProps => /*#__PURE__*/jsx("input", {
7618
+ render: renderProps => /*#__PURE__*/jsx(Input, {
7610
7619
  ...renderProps
7611
7620
  })
7612
7621
  });
7613
- InputWithDisplayFormat.propTypes = {
7614
- displayPattern: PropTypes.string.isRequired,
7615
- onChange: PropTypes.func.isRequired
7616
- };
7617
- var InputWithDisplayFormat$1 = InputWithDisplayFormat;
7618
7622
 
7619
7623
  const InstructionsList = ({
7620
7624
  dos,
@@ -9563,79 +9567,111 @@ const countries = [{
9563
9567
  iso3: 'ZWE',
9564
9568
  phone: '+263'
9565
9569
  }];
9570
+ var countries$1 = countries;
9566
9571
 
9567
9572
  const longestMatchingPrefix = matchingCodes => matchingCodes.reduce((a, b) => a.phone.length > b.phone.length ? a : b);
9568
9573
 
9569
9574
  const findCountryByCode = code => {
9570
- if (code.length === 2) {
9571
- const matchingCodes = countries.filter(country => code.toUpperCase() === country.iso2);
9572
- if (matchingCodes.length > 0) {
9573
- return longestMatchingPrefix(matchingCodes);
9574
- }
9575
+ let matchingCodes;
9576
+ if (code && code.length === 2) {
9577
+ matchingCodes = countries$1.filter(country => code.toUpperCase() === country.iso2);
9575
9578
  }
9576
- return null;
9579
+ return matchingCodes && matchingCodes.length > 0 ? longestMatchingPrefix(matchingCodes) : null;
9577
9580
  };
9578
9581
 
9579
9582
  /**
9580
9583
  * Default phone code, the UK one `+44`
9581
9584
  */
9582
9585
  const DEFAULT_PHONE_CODE = '+44';
9586
+
9583
9587
  /**
9584
9588
  * Given a valid locale it returns the correspondent prefix if found or +44 otherwise.
9585
9589
  *
9586
- * @param locale BCP 47 language tag of locale, e.g. `"es-ES"`.
9587
- * @param countryCode Two-letter country code (ISO 3166-1 alpha-2).
9590
+ * @param {string} locale - a string that represent the locale ex:'es-ES'
9591
+ * @param countryCode
9592
+ * @returns {string}
9588
9593
  */
9589
9594
  const setDefaultPrefix = (locale, countryCode) => {
9590
- const country = (countryCode != null ? findCountryByCode(countryCode) : null) ?? findCountryByCode(getCountryFromLocale(locale) ?? locale);
9591
- return country?.phone ?? DEFAULT_PHONE_CODE;
9595
+ const country = findCountryByCode(countryCode) ||
9596
+ // when `locale` code has explicit region: `en-GB`, `en-US`, `ar-AE`
9597
+ findCountryByCode(getCountryFromLocale(locale)) ||
9598
+ // when `locale` code is only two chars value: `fr`, `es`
9599
+ findCountryByCode(locale);
9600
+ return country?.phone || DEFAULT_PHONE_CODE;
9592
9601
  };
9593
9602
 
9594
9603
  /**
9595
9604
  *
9596
9605
  * @param phoneNumber
9597
- * @returns True if number that starts with "+" and contains a mix of digits and spaces with at least 4 digits.
9606
+ * @returns {boolean} - returns true for number that starts with '+' and contains a mix of digits and spaces with
9607
+ * at least 4 digits.
9598
9608
  */
9599
- const isValidPhoneNumber = phoneNumber => /^\+[\d-\s]+$/.test(phoneNumber) && (phoneNumber.match(/\d+/g)?.join('').length ?? 0) >= 4;
9609
+ const isValidPhoneNumber = phoneNumber => /^\+[\d-\s]+$/.test(phoneNumber) && phoneNumber.match(/\d+/g) && phoneNumber.match(/\d+/g).join('').length >= 4;
9600
9610
 
9601
9611
  const findCountryByPrefix = number => {
9602
- if (number.length > 1) {
9603
- const matchingCodes = countries.filter(country => number.startsWith(country.phone));
9604
- if (matchingCodes.length > 0) {
9605
- return longestMatchingPrefix(matchingCodes);
9606
- }
9612
+ let matchingCodes = null;
9613
+ if (number && number.length > 1) {
9614
+ matchingCodes = countries$1.filter(country => number.indexOf(country.phone) === 0);
9607
9615
  }
9608
- return null;
9616
+ return matchingCodes && matchingCodes.length > 0 ? longestMatchingPrefix(matchingCodes) : null;
9609
9617
  };
9610
9618
 
9611
9619
  /**
9612
- * @param number Phone number in a format like "+447573135343"
9620
+ * Given a sting in a valid format ex:'+447573135343' it returns an object of shape
9621
+ * {prefix=+44 ,suffix=7573135343}
9622
+ *
9623
+ * @param {string} number - a string that defines a phone number.
9624
+ * @returns {{prefix: (string|*), suffix: string, format: string}}
9613
9625
  */
9614
9626
  const explodeNumberModel = number => {
9627
+ let prefix = '';
9628
+ let suffix = '';
9629
+ let format = '';
9615
9630
  const country = findCountryByPrefix(number);
9616
- return country ? {
9617
- prefix: country.phone,
9618
- suffix: number.slice(country.phone.length),
9619
- format: country.phoneFormat
9620
- } : {
9621
- prefix: null,
9622
- suffix: number.slice(1)
9631
+ if (country) {
9632
+ prefix = country.phone;
9633
+ suffix = number.slice(country.phone.length);
9634
+ format = country.phoneFormat || '';
9635
+ } else {
9636
+ prefix = '';
9637
+ suffix = number.slice(1);
9638
+ format = '';
9639
+ }
9640
+ return {
9641
+ prefix,
9642
+ suffix,
9643
+ format
9623
9644
  };
9624
9645
  };
9625
9646
 
9626
9647
  const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
9627
- const cleanNumber = number => number.match(DIGITS_MATCH)?.join('') ?? '';
9648
+ const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
9628
9649
 
9629
- function sortArrayByProperty(arrayToSort, property) {
9630
- return [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
9631
- }
9650
+ // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
9651
+ const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
9632
9652
 
9633
9653
  const groupCountriesByPrefix = countries => {
9634
- const countriesByPrefix = new Map();
9635
- countries.forEach(country => {
9636
- countriesByPrefix.set(country.phone, [...(countriesByPrefix.get(country.phone) ?? []), country]);
9637
- });
9638
- return countriesByPrefix;
9654
+ const groupedArray = countries.reduce((accumulator, country) => {
9655
+ const {
9656
+ name,
9657
+ iso2,
9658
+ iso3,
9659
+ phone
9660
+ } = country;
9661
+ if (accumulator[phone]) {
9662
+ const previousValue = accumulator[phone];
9663
+ accumulator[phone] = {
9664
+ ...previousValue,
9665
+ name: isArray(previousValue.name) ? [...previousValue.name, name] : [previousValue.name, name],
9666
+ iso2: isArray(previousValue.iso2) ? [...previousValue.iso2, iso2] : [previousValue.iso2, iso2],
9667
+ iso3: isArray(previousValue.iso3) ? [...previousValue.iso3, iso3] : [previousValue.iso3, iso3]
9668
+ };
9669
+ } else {
9670
+ accumulator[phone] = country;
9671
+ }
9672
+ return accumulator;
9673
+ }, {});
9674
+ return Object.values(groupedArray);
9639
9675
  };
9640
9676
 
9641
9677
  // Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
@@ -9643,38 +9679,41 @@ const filterCountriesByIso3 = (countries, iso3Codes) => {
9643
9679
  const iso3CodesSet = new Set(iso3Codes);
9644
9680
  return countries.filter(country => !iso3CodesSet.has(country.iso3));
9645
9681
  };
9682
+
9646
9683
  /**
9647
9684
  * Removes the countries sepecified in the second param
9648
9685
  *
9649
- * @param countries list of country metadata objects
9650
- * @param disabledCountries list of iso3 country codes to remove from the list
9686
+ * @param {Array} countries: list of country metadata objects
9687
+ * @param {Array} disabledCountries: list of iso3 country codes to remove from the list
9688
+ * @returns
9651
9689
  */
9652
9690
  const excludeCountries = (countries, disabledCountries) => {
9653
9691
  return disabledCountries.length > 0 ? filterCountriesByIso3(countries, disabledCountries) : countries;
9654
9692
  };
9655
9693
 
9656
9694
  const ALLOWED_PHONE_CHARS = /^$|^[\d-\s]+$/;
9657
- const defaultSelectProps = {};
9658
- const defaultDisabledCountries = [];
9659
- const PhoneNumberInput = ({
9660
- id,
9661
- required,
9662
- disabled,
9663
- initialValue,
9664
- onChange,
9665
- onFocus,
9666
- onBlur,
9667
- countryCode,
9668
- searchPlaceholder = 'Prefix',
9669
- size = Size.MEDIUM,
9670
- placeholder,
9671
- selectProps = defaultSelectProps,
9672
- disabledCountries = defaultDisabledCountries
9673
- }) => {
9695
+ const PhoneNumberInput = props => {
9696
+ const {
9697
+ id,
9698
+ onChange,
9699
+ searchPlaceholder,
9700
+ disabled,
9701
+ required,
9702
+ size,
9703
+ placeholder,
9704
+ onFocus,
9705
+ onBlur,
9706
+ countryCode,
9707
+ selectProps,
9708
+ disabledCountries
9709
+ } = props;
9674
9710
  const {
9675
9711
  locale
9676
9712
  } = useIntl();
9677
- const [internalValue, setInternalValue] = useState(() => {
9713
+ const getInitialValue = () => {
9714
+ const {
9715
+ initialValue
9716
+ } = props;
9678
9717
  const cleanValue = initialValue ? cleanNumber(initialValue) : null;
9679
9718
  if (!cleanValue || !isValidPhoneNumber(cleanValue)) {
9680
9719
  return {
@@ -9683,16 +9722,54 @@ const PhoneNumberInput = ({
9683
9722
  };
9684
9723
  }
9685
9724
  return explodeNumberModel(cleanValue);
9686
- });
9725
+ };
9726
+ const [internalValue, setInternalValue] = useState(getInitialValue());
9687
9727
  const [broadcastedValue, setBroadcastedValue] = useState(null);
9688
- const countriesByPrefix = useMemo(() => groupCountriesByPrefix(sortArrayByProperty(excludeCountries(countries, disabledCountries), 'iso3')), [disabledCountries]);
9728
+ const getSelectOptions = () => {
9729
+ const countriesList = excludeCountries(countries$1, disabledCountries);
9730
+ const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
9731
+ return listSortedByISO3.map(option => {
9732
+ const {
9733
+ phone,
9734
+ iso3,
9735
+ iso2,
9736
+ name
9737
+ } = option;
9738
+ let note = '';
9739
+ if (iso3) {
9740
+ note = isArray(iso3) ? iso3.join(', ') : iso3;
9741
+ } else if (iso2) {
9742
+ note = isArray(iso2) ? iso2.join(', ') : iso2;
9743
+ }
9744
+ return {
9745
+ type: 'option',
9746
+ value: {
9747
+ value: phone,
9748
+ label: phone,
9749
+ note: note
9750
+ },
9751
+ filterMatchers: [phone, note, name]
9752
+ };
9753
+ });
9754
+ };
9755
+ const options = getSelectOptions();
9756
+ const onPrefixChange = ({
9757
+ value
9758
+ }) => {
9759
+ setInternalValue({
9760
+ prefix: value,
9761
+ suffix: internalValue.suffix
9762
+ });
9763
+ };
9689
9764
  const onSuffixChange = event => {
9690
- const suffix = event.target.value;
9691
- if (ALLOWED_PHONE_CHARS.test(suffix)) {
9692
- setInternalValue(prev => ({
9693
- ...prev,
9694
- suffix
9695
- }));
9765
+ const {
9766
+ value = ''
9767
+ } = event.target;
9768
+ if (ALLOWED_PHONE_CHARS.test(value)) {
9769
+ setInternalValue({
9770
+ prefix: internalValue.prefix,
9771
+ suffix: value
9772
+ });
9696
9773
  }
9697
9774
  };
9698
9775
  const onPaste = event => {
@@ -9700,22 +9777,31 @@ const PhoneNumberInput = ({
9700
9777
  return;
9701
9778
  }
9702
9779
  const pastedValue = (event.nativeEvent.clipboardData.getData('text/plain') || '').replace(/(\s|-)+/g, '');
9703
- const pastedNumber = explodeNumberModel(pastedValue);
9704
- if (pastedNumber.prefix != null && countriesByPrefix.has(pastedNumber.prefix) && ALLOWED_PHONE_CHARS.test(pastedNumber.suffix)) {
9705
- setInternalValue(pastedNumber);
9780
+ const {
9781
+ prefix: pastedPrefix,
9782
+ suffix: pastedSuffix
9783
+ } = explodeNumberModel(pastedValue);
9784
+ const selectedPrefix = options.find(({
9785
+ value
9786
+ }) => value.value === pastedPrefix);
9787
+ if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
9788
+ setInternalValue({
9789
+ prefix: pastedPrefix,
9790
+ suffix: pastedSuffix
9791
+ });
9706
9792
  }
9707
9793
  };
9708
9794
  useEffect(() => {
9709
9795
  if (broadcastedValue === null) {
9710
9796
  return setBroadcastedValue(internalValue);
9711
9797
  }
9712
- const internalPhoneNumber = `${internalValue.prefix ?? ''}${internalValue.suffix}`;
9713
- const broadcastedPhoneNumber = `${broadcastedValue.prefix ?? ''}${broadcastedValue.suffix}`;
9798
+ const internalPhoneNumber = internalValue.prefix + internalValue.suffix;
9799
+ const broadcastedPhoneNumber = broadcastedValue.prefix + broadcastedValue.suffix;
9714
9800
  if (internalPhoneNumber === broadcastedPhoneNumber) {
9715
9801
  return;
9716
9802
  }
9717
9803
  const newValue = isValidPhoneNumber(internalPhoneNumber) ? cleanNumber(internalPhoneNumber) : null;
9718
- onChange(newValue, internalValue.prefix ?? '');
9804
+ onChange(newValue, internalValue.prefix);
9719
9805
  setBroadcastedValue(internalValue);
9720
9806
  }, [onChange, broadcastedValue, internalValue]);
9721
9807
  return /*#__PURE__*/jsxs("div", {
@@ -9723,29 +9809,18 @@ const PhoneNumberInput = ({
9723
9809
  children: [/*#__PURE__*/jsx("div", {
9724
9810
  className: "tw-telephone__country-select",
9725
9811
  children: /*#__PURE__*/jsx(SelectInput, {
9726
- placeholder: "Select an option\u2026",
9727
- items: [...countriesByPrefix].map(([prefix, countries]) => ({
9728
- type: 'option',
9729
- value: prefix,
9730
- filterMatchers: [prefix, ...countries.map(country => country.name), ...countries.map(country => country.iso3)]
9731
- })),
9732
- value: internalValue.prefix,
9733
- renderValue: (prefix, withinTrigger) => /*#__PURE__*/jsx(SelectInputOptionContent, {
9734
- title: prefix,
9735
- note: withinTrigger ? undefined : countriesByPrefix.get(prefix)?.map(country => country.iso3).join(', ')
9812
+ placeholder: "Select an option...",
9813
+ items: options,
9814
+ value: options.find(item => item.value.value === internalValue.prefix)?.value,
9815
+ renderValue: (option, withinTrigger) => /*#__PURE__*/jsx(SelectInputOptionContent, {
9816
+ title: option.label,
9817
+ note: withinTrigger ? undefined : option.note
9736
9818
  }),
9737
9819
  filterable: true,
9738
9820
  filterPlaceholder: searchPlaceholder,
9739
9821
  disabled: disabled,
9740
9822
  size: size,
9741
- onChange: prefix => {
9742
- const country = prefix != null ? findCountryByPrefix(prefix) : null;
9743
- setInternalValue(prev => ({
9744
- ...prev,
9745
- prefix,
9746
- format: country?.phoneFormat
9747
- }));
9748
- },
9823
+ onChange: onPrefixChange,
9749
9824
  ...selectProps
9750
9825
  })
9751
9826
  }), /*#__PURE__*/jsx("div", {
@@ -9771,6 +9846,37 @@ const PhoneNumberInput = ({
9771
9846
  })]
9772
9847
  });
9773
9848
  };
9849
+ PhoneNumberInput.propTypes = {
9850
+ id: PropTypes.string,
9851
+ required: PropTypes.bool,
9852
+ disabled: PropTypes.bool,
9853
+ initialValue: PropTypes.string,
9854
+ onChange: PropTypes.func.isRequired,
9855
+ onFocus: PropTypes.func,
9856
+ onBlur: PropTypes.func,
9857
+ countryCode: PropTypes.string,
9858
+ searchPlaceholder: PropTypes.string,
9859
+ size: PropTypes.oneOf(['sm', 'md', 'lg']),
9860
+ placeholder: PropTypes.string,
9861
+ selectProps: PropTypes.object,
9862
+ /** List of iso3 codes of countries to remove from the list */
9863
+ disabledCountries: PropTypes.arrayOf(PropTypes.string)
9864
+ };
9865
+ PhoneNumberInput.defaultProps = {
9866
+ id: null,
9867
+ required: false,
9868
+ disabled: false,
9869
+ initialValue: null,
9870
+ onFocus() {},
9871
+ onBlur() {},
9872
+ countryCode: null,
9873
+ searchPlaceholder: 'Prefix',
9874
+ size: Size.MEDIUM,
9875
+ placeholder: '',
9876
+ selectProps: {},
9877
+ disabledCountries: []
9878
+ };
9879
+ var PhoneNumberInput$1 = PhoneNumberInput;
9774
9880
 
9775
9881
  const Progress = ({
9776
9882
  className,
@@ -12189,17 +12295,12 @@ Tabs.defaultProps = {
12189
12295
  };
12190
12296
  var Tabs$1 = Tabs;
12191
12297
 
12192
- const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat$1, {
12298
+ const TextareaWithDisplayFormat = props => /*#__PURE__*/jsx(WithDisplayFormat, {
12193
12299
  ...props,
12194
- render: renderProps => /*#__PURE__*/jsx("textarea", {
12300
+ render: renderProps => /*#__PURE__*/jsx(TextArea, {
12195
12301
  ...renderProps
12196
12302
  })
12197
12303
  });
12198
- TextareaWithDisplayFormat.propTypes = {
12199
- displayPattern: PropTypes.string.isRequired,
12200
- onChange: PropTypes.func.isRequired
12201
- };
12202
- var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
12203
12304
 
12204
12305
  /* eslint-disable jsx-a11y/no-autofocus */
12205
12306
  /* eslint-disable jsx-a11y/click-events-have-key-events */
@@ -15496,5 +15597,5 @@ const translations = {
15496
15597
  'zh-HK': zhHK
15497
15598
  };
15498
15599
 
15499
- 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, 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 };
15600
+ export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$2 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList$1 as InstructionsList, LanguageProvider, Layout$1 as Layout, Link, ListItem$1 as ListItem, Loader$1 as Loader, Logo$1 as Logo, LogoType, Markdown$1 as Markdown, MarkdownNodeType, Modal, Money$1 as Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList$1 as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput$1 as PhoneNumberInput, Popover$2 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCard$1 as PromoCardGroup, Provider$1 as Provider, RTL_LANGUAGES, Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioOption$1 as RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel$1 as SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider$1 as SnackbarProvider, Status, StatusIcon, Stepper, Sticky$1 as Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip$1 as Tooltip, Type$1 as Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
15500
15601
  //# sourceMappingURL=index.esm.js.map