@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.
- package/build/index.esm.js +335 -234
- package/build/index.esm.js.map +1 -1
- package/build/index.js +336 -235
- package/build/index.js.map +1 -1
- package/build/types/common/locale/index.d.ts +43 -26
- package/build/types/common/locale/index.d.ts.map +1 -1
- package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts +1 -1
- package/build/types/common/textFormat/formatWithPattern/formatWithPattern.d.ts.map +1 -1
- package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts +2 -2
- package/build/types/common/textFormat/getCursorPositionAfterKeystroke/getCursorPositionAfterKeystroke.d.ts.map +1 -1
- package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts +5 -1
- package/build/types/common/textFormat/getSymbolsInPatternWithPosition/getSymbolsInPatternWithPosition.d.ts.map +1 -1
- package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts +1 -1
- package/build/types/common/textFormat/unformatWithPattern/unformatWithPattern.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts +7 -11
- package/build/types/inputWithDisplayFormat/InputWithDisplayFormat.d.ts.map +1 -1
- package/build/types/inputWithDisplayFormat/index.d.ts +2 -1
- package/build/types/inputWithDisplayFormat/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts +27 -22
- package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
- package/build/types/phoneNumberInput/data/countries.d.ts +10 -5
- package/build/types/phoneNumberInput/data/countries.d.ts.map +1 -1
- package/build/types/phoneNumberInput/index.d.ts +1 -1
- package/build/types/phoneNumberInput/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/cleanNumber.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/cleanNumber/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts +1 -8
- package/build/types/phoneNumberInput/utils/excludeCountries/excludeCountries.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/excludeCountries/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts +4 -8
- package/build/types/phoneNumberInput/utils/explodeNumberModel/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts +2 -0
- package/build/types/phoneNumberInput/utils/filterOptionsForQuery/index.d.ts.map +1 -0
- package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByCode/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/findCountryByPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts +1 -2
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/groupCountriesByPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/index.d.ts +13 -11
- package/build/types/phoneNumberInput/utils/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts +2 -0
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/index.d.ts.map +1 -0
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts +3 -0
- package/build/types/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.d.ts.map +1 -0
- package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/isStringNumeric/isStringNumeric.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts +1 -6
- package/build/types/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts +1 -2
- package/build/types/phoneNumberInput/utils/longestMatchingPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts +1 -7
- package/build/types/phoneNumberInput/utils/setDefaultPrefix/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/index.d.ts.map +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts +1 -1
- package/build/types/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.d.ts.map +1 -1
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts +7 -11
- package/build/types/textareaWithDisplayFormat/TextareaWithDisplayFormat.d.ts.map +1 -1
- package/build/types/textareaWithDisplayFormat/index.d.ts +2 -1
- package/build/types/textareaWithDisplayFormat/index.d.ts.map +1 -1
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts +54 -82
- package/build/types/withDisplayFormat/WithDisplayFormat.d.ts.map +1 -1
- package/build/types/withDisplayFormat/index.d.ts +2 -1
- package/build/types/withDisplayFormat/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/locale/index.js +139 -0
- package/src/common/locale/{index.spec.ts → index.spec.js} +4 -4
- package/src/common/textFormat/formatWithPattern/{formatWithPattern.js → formatWithPattern.ts} +8 -4
- package/src/common/textFormat/getCursorPositionAfterKeystroke/{getCursorPositionAfterKeystroke.js → getCursorPositionAfterKeystroke.ts} +8 -8
- package/src/common/textFormat/getSymbolsInPatternWithPosition/{getSymbolsInPatternWithPosition.js → getSymbolsInPatternWithPosition.ts} +7 -2
- package/src/common/textFormat/unformatWithPattern/{unformatWithPattern.js → unformatWithPattern.ts} +3 -2
- package/src/index.ts +2 -0
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.tsx +10 -0
- package/src/inputWithDisplayFormat/index.ts +2 -0
- package/src/phoneNumberInput/PhoneNumberInput.js +210 -0
- package/src/phoneNumberInput/PhoneNumberInput.spec.js +22 -18
- package/src/phoneNumberInput/data/{countries.ts → countries.js} +1 -9
- package/src/phoneNumberInput/data/countries.spec.js +12 -0
- package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.js +4 -0
- package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.ts → excludeCountries.js} +5 -6
- package/src/phoneNumberInput/utils/excludeCountries/{excludeCountries.spec.ts → excludeCountries.spec.js} +1 -1
- package/src/phoneNumberInput/utils/explodeNumberModel/{explodeNumberModel.spec.ts → explodeNumberModel.spec.js} +1 -1
- package/src/phoneNumberInput/utils/explodeNumberModel/index.js +27 -0
- package/src/phoneNumberInput/utils/filterOptionsForQuery/filterOptionsForQuery.spec.js +36 -0
- package/src/phoneNumberInput/utils/filterOptionsForQuery/index.js +11 -0
- package/src/phoneNumberInput/utils/findCountryByCode/{findCountryByCode.spec.ts → findCountryByCode.spec.js} +1 -0
- package/src/phoneNumberInput/utils/findCountryByCode/index.js +10 -0
- package/src/phoneNumberInput/utils/findCountryByPrefix/index.js +11 -0
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.js +26 -0
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.js +67 -0
- package/src/phoneNumberInput/utils/{index.ts → index.js} +2 -0
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/index.js +1 -0
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.js +25 -0
- package/src/phoneNumberInput/utils/isOptionAndFitsQuery/isOptionAndFitsQuery.spec.js +66 -0
- package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.js +1 -0
- package/src/phoneNumberInput/utils/isStringNumeric/{isStringNumeric.spec.ts → isStringNumeric.spec.js} +1 -0
- package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.js +10 -0
- package/src/phoneNumberInput/utils/isValidPhoneNumber/{isValidPhoneNumber.spec.ts → isValidPhoneNumber.spec.js} +1 -1
- package/src/phoneNumberInput/utils/longestMatchingPrefix/index.js +2 -0
- package/src/phoneNumberInput/utils/setDefaultPrefix/index.js +25 -0
- package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.js +3 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.spec.js +3 -1
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.story.tsx +32 -0
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.tsx +13 -0
- package/src/textareaWithDisplayFormat/index.ts +2 -0
- package/src/withDisplayFormat/WithDisplayFormat.spec.js +1 -1
- package/src/withDisplayFormat/{WithDisplayFormat.js → WithDisplayFormat.tsx} +127 -107
- package/src/withDisplayFormat/index.ts +2 -0
- package/src/common/locale/index.ts +0 -96
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.js +0 -14
- package/src/inputWithDisplayFormat/index.js +0 -1
- package/src/phoneNumberInput/PhoneNumberInput.tsx +0 -193
- package/src/phoneNumberInput/utils/cleanNumber/cleanNumber.ts +0 -3
- package/src/phoneNumberInput/utils/explodeNumberModel/index.ts +0 -24
- package/src/phoneNumberInput/utils/findCountryByCode/index.ts +0 -12
- package/src/phoneNumberInput/utils/findCountryByPrefix/index.ts +0 -12
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.spec.ts +0 -102
- package/src/phoneNumberInput/utils/groupCountriesByPrefix/groupCountriesByPrefix.ts +0 -12
- package/src/phoneNumberInput/utils/isStringNumeric/isStringNumeric.ts +0 -1
- package/src/phoneNumberInput/utils/isValidPhoneNumber/isValidPhoneNumber.ts +0 -7
- package/src/phoneNumberInput/utils/longestMatchingPrefix/index.ts +0 -4
- package/src/phoneNumberInput/utils/setDefaultPrefix/index.ts +0 -20
- package/src/phoneNumberInput/utils/sortArrayByProperty/sortArrayByProperty.ts +0 -6
- package/src/textareaWithDisplayFormat/TextareaWithDisplayFormat.js +0 -14
- package/src/textareaWithDisplayFormat/index.js +0 -1
- package/src/withDisplayFormat/index.js +0 -1
- /package/src/phoneNumberInput/{PhoneNumberInput.story.tsx → PhoneNumberInput.story.js} +0 -0
- /package/src/phoneNumberInput/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/cleanNumber/{cleanNumber.spec.ts → cleanNumber.spec.js} +0 -0
- /package/src/phoneNumberInput/utils/cleanNumber/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/excludeCountries/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/findCountryByPrefix/{findCountryByPrefix.spec.ts → findCountryByPrefix.spec.js} +0 -0
- /package/src/phoneNumberInput/utils/groupCountriesByPrefix/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/isStringNumeric/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/isValidPhoneNumber/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/longestMatchingPrefix/{longestMatchingPrefix.spec.ts → longestMatchingPrefix.spec.js} +0 -0
- /package/src/phoneNumberInput/utils/setDefaultPrefix/{setDefaultPrefix.spec.ts → setDefaultPrefix.spec.js} +0 -0
- /package/src/phoneNumberInput/utils/sortArrayByProperty/{index.ts → index.js} +0 -0
- /package/src/phoneNumberInput/utils/sortArrayByProperty/{sortArrayByProperty.spec.ts → sortArrayByProperty.spec.js} +0 -0
package/build/index.js
CHANGED
|
@@ -376,76 +376,131 @@ const Key = {
|
|
|
376
376
|
COMMA: ','
|
|
377
377
|
};
|
|
378
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Default language
|
|
381
|
+
*
|
|
382
|
+
* @type {string}
|
|
383
|
+
*/
|
|
379
384
|
const DEFAULT_LANG = 'en';
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Default locale
|
|
388
|
+
*
|
|
389
|
+
* @type {string}
|
|
390
|
+
*/
|
|
380
391
|
const DEFAULT_LOCALE = 'en-GB';
|
|
392
|
+
|
|
381
393
|
/**
|
|
382
|
-
*
|
|
394
|
+
* Array of languages that are written from the right to the left
|
|
395
|
+
*
|
|
396
|
+
* @type {string[]}
|
|
383
397
|
*/
|
|
384
398
|
const RTL_LANGUAGES = ['ar', 'he'];
|
|
399
|
+
|
|
385
400
|
/**
|
|
386
401
|
* @deprecated The source of truth for supported languages lives in Crab.
|
|
402
|
+
* @type {string[]}
|
|
387
403
|
*/
|
|
388
404
|
const SUPPORTED_LANGUAGES = [DEFAULT_LANG, 'de', 'es', 'fr', 'hu', 'id', 'it', 'ja', 'pl', 'pt', 'ro', 'ru', 'th', 'tr', 'uk', 'zh'];
|
|
405
|
+
|
|
389
406
|
/**
|
|
390
|
-
* Verifies and adjusts locale
|
|
407
|
+
* Verifies and adjusts locale (replace `_` with `-`)
|
|
408
|
+
* Returns null if locale is unrecognized by {Intl.Locale}
|
|
391
409
|
*
|
|
392
|
-
* @param locale `es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP
|
|
393
|
-
* @returns
|
|
410
|
+
* @param {string} locale (`es`, `es_ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
|
|
411
|
+
* @returns {string|null}
|
|
394
412
|
*/
|
|
395
413
|
function adjustLocale(locale) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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;
|
|
404
426
|
}
|
|
405
|
-
return null;
|
|
406
427
|
}
|
|
428
|
+
|
|
407
429
|
/**
|
|
408
|
-
* Provides corresponding lang (iso2) for provided locale
|
|
430
|
+
* Provides corresponding lang (iso2) for provided locale
|
|
431
|
+
* if locale is invalid or language is unsupported returns null
|
|
409
432
|
*
|
|
410
433
|
* @deprecated The use of this function almost always breaks language variants
|
|
411
434
|
* e.g. Simplified and Traditional Chinese.
|
|
412
435
|
* There should be no use case for this function.
|
|
413
436
|
* To select the correct translations from a translations object, pass the
|
|
414
437
|
* locale directly into Crab's getLocalisedMessages.
|
|
415
|
-
* @param locale `es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP
|
|
416
|
-
* @returns
|
|
438
|
+
* @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
|
|
439
|
+
* @returns {string|null} two-letter ISO639-1 language
|
|
417
440
|
*/
|
|
418
441
|
function getLangFromLocale(locale) {
|
|
419
442
|
const adjustedLocale = adjustLocale(locale);
|
|
420
|
-
if (adjustedLocale
|
|
443
|
+
if (adjustedLocale === null) {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
try {
|
|
421
447
|
const {
|
|
422
448
|
language
|
|
423
449
|
} = new Intl.Locale(adjustedLocale);
|
|
424
450
|
if (SUPPORTED_LANGUAGES.includes(language)) {
|
|
425
451
|
return language;
|
|
426
452
|
}
|
|
453
|
+
return null;
|
|
454
|
+
} catch (error) {
|
|
455
|
+
// eslint-disable-next-line no-console
|
|
456
|
+
console.error(error);
|
|
457
|
+
return null;
|
|
427
458
|
}
|
|
428
|
-
return null;
|
|
429
459
|
}
|
|
460
|
+
|
|
430
461
|
/**
|
|
431
|
-
* Provides corresponding country code (iso2) for locales code with explicit region value.
|
|
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
|
|
432
464
|
*
|
|
433
|
-
* @param locale
|
|
434
|
-
* @returns
|
|
465
|
+
* @param {string} locale
|
|
466
|
+
* @returns {string|null}
|
|
435
467
|
*/
|
|
436
468
|
function getCountryFromLocale(locale) {
|
|
437
469
|
const adjustedLocale = adjustLocale(locale);
|
|
438
|
-
|
|
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
|
+
}
|
|
439
483
|
}
|
|
484
|
+
|
|
440
485
|
/**
|
|
441
486
|
* Provides the layout direction for a given locale.
|
|
487
|
+
* If locale is invalid or language is unsupported returns Direction.LTR
|
|
442
488
|
*
|
|
443
|
-
* @param locale `es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP
|
|
444
|
-
* @returns The layout direction based on the locale
|
|
489
|
+
* @param {string} locale (`es`, `es-ES`, `en-GB`, `en`, `ja`, `ja-JP` etc)
|
|
490
|
+
* @returns {Direction} The layout direction based on the locale
|
|
445
491
|
*/
|
|
446
492
|
function getDirectionFromLocale(locale) {
|
|
447
|
-
|
|
448
|
-
|
|
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
|
+
}
|
|
449
504
|
}
|
|
450
505
|
|
|
451
506
|
/**
|
|
@@ -7242,10 +7297,13 @@ const formatWithPattern = (value, pattern) => {
|
|
|
7242
7297
|
let patternSymbol = [];
|
|
7243
7298
|
// valueArray.length increments during the cycle cause we are adding new elements.
|
|
7244
7299
|
for (let index = 0; index < valueArray.length; index += 1) {
|
|
7245
|
-
patternSymbol = patternWithSymbolsPosition.filter(
|
|
7300
|
+
patternSymbol = patternWithSymbolsPosition.filter(pattern => pattern.index === index);
|
|
7246
7301
|
// Add pattern's symbol at n position
|
|
7247
7302
|
if (patternSymbol.length === 1) {
|
|
7248
|
-
|
|
7303
|
+
const last = patternSymbol.pop();
|
|
7304
|
+
if (last) {
|
|
7305
|
+
valueArray.splice(index, 0, last.symbol);
|
|
7306
|
+
}
|
|
7249
7307
|
}
|
|
7250
7308
|
}
|
|
7251
7309
|
return valueArray.join('');
|
|
@@ -7291,7 +7349,7 @@ const countConsecutiveSymbols = (selectionStart, applicablePattern, direction) =
|
|
|
7291
7349
|
return groupSize;
|
|
7292
7350
|
};
|
|
7293
7351
|
|
|
7294
|
-
const
|
|
7352
|
+
const getCursorPositionAfterActionStroke = (action, selectionStart, selectionEnd, pattern, pastedLength) => {
|
|
7295
7353
|
let cursorPosition = selectionStart;
|
|
7296
7354
|
switch (action) {
|
|
7297
7355
|
case 'Backspace':
|
|
@@ -7313,36 +7371,36 @@ const getCursorPositionAfteractionstroke = (action, selectionStart, selectionEnd
|
|
|
7313
7371
|
}
|
|
7314
7372
|
return cursorPosition;
|
|
7315
7373
|
};
|
|
7316
|
-
var getCursorPositionAfterKeystroke =
|
|
7374
|
+
var getCursorPositionAfterKeystroke = getCursorPositionAfterActionStroke;
|
|
7317
7375
|
|
|
7318
7376
|
class WithDisplayFormat extends React.Component {
|
|
7377
|
+
static defaultProps = {
|
|
7378
|
+
autoComplete: 'off',
|
|
7379
|
+
displayPattern: '',
|
|
7380
|
+
value: ''
|
|
7381
|
+
};
|
|
7319
7382
|
constructor(props) {
|
|
7320
7383
|
super(props);
|
|
7321
|
-
const
|
|
7322
|
-
value,
|
|
7323
|
-
displayPattern
|
|
7324
|
-
} = props;
|
|
7325
|
-
const unformattedValue = unformatWithPattern$1(value, displayPattern);
|
|
7384
|
+
const unformattedValue = unformatWithPattern$1(props.value ?? '', props.displayPattern);
|
|
7326
7385
|
this.state = {
|
|
7327
|
-
value: formatWithPattern$1(unformattedValue, displayPattern),
|
|
7386
|
+
value: formatWithPattern$1(unformattedValue, props.displayPattern),
|
|
7328
7387
|
historyNavigator: new HistoryNavigator$1(),
|
|
7329
7388
|
prevDisplayPattern: props.displayPattern,
|
|
7330
|
-
triggerType:
|
|
7331
|
-
triggerEvent: null
|
|
7389
|
+
triggerType: 'Initial',
|
|
7390
|
+
triggerEvent: null,
|
|
7391
|
+
selectionStart: 0,
|
|
7392
|
+
selectionEnd: 0,
|
|
7393
|
+
pastedLength: 0
|
|
7332
7394
|
};
|
|
7333
7395
|
}
|
|
7334
|
-
static getDerivedStateFromProps(
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
if (
|
|
7342
|
-
const {
|
|
7343
|
-
value,
|
|
7344
|
-
historyNavigator
|
|
7345
|
-
} = previousState;
|
|
7396
|
+
static getDerivedStateFromProps({
|
|
7397
|
+
displayPattern
|
|
7398
|
+
}, {
|
|
7399
|
+
prevDisplayPattern = displayPattern,
|
|
7400
|
+
value,
|
|
7401
|
+
historyNavigator
|
|
7402
|
+
}) {
|
|
7403
|
+
if (prevDisplayPattern !== displayPattern) {
|
|
7346
7404
|
const unFormattedValue = unformatWithPattern$1(value, prevDisplayPattern);
|
|
7347
7405
|
historyNavigator.reset();
|
|
7348
7406
|
return {
|
|
@@ -7364,29 +7422,31 @@ class WithDisplayFormat extends React.Component {
|
|
|
7364
7422
|
const {
|
|
7365
7423
|
displayPattern
|
|
7366
7424
|
} = this.props;
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
7381
|
-
if (unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
|
|
7425
|
+
if (triggerEvent) {
|
|
7426
|
+
const charCode = String.fromCharCode(triggerEvent.which).toLowerCase();
|
|
7427
|
+
if (triggerType === 'Paste' || triggerType === 'Cut') {
|
|
7428
|
+
return triggerType;
|
|
7429
|
+
}
|
|
7430
|
+
if ((triggerEvent.ctrlKey || triggerEvent.metaKey) && charCode === 'z') {
|
|
7431
|
+
return triggerEvent.shiftKey ? 'Redo' : 'Undo';
|
|
7432
|
+
}
|
|
7433
|
+
// Detect mouse event redo
|
|
7434
|
+
if (triggerEvent.ctrlKey && charCode === 'd') {
|
|
7435
|
+
return 'Delete';
|
|
7436
|
+
}
|
|
7437
|
+
// Android Fix.
|
|
7438
|
+
if (typeof triggerEvent.key === 'undefined' && unformattedValue.length <= unformatWithPattern$1(value, displayPattern).length) {
|
|
7382
7439
|
return 'Backspace';
|
|
7383
7440
|
}
|
|
7441
|
+
return triggerEvent.key;
|
|
7442
|
+
} else {
|
|
7443
|
+
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
7444
|
+
return 'Paste';
|
|
7384
7445
|
}
|
|
7385
|
-
return triggerEvent.key;
|
|
7386
7446
|
};
|
|
7387
7447
|
resetEvent = () => {
|
|
7388
7448
|
this.setState({
|
|
7389
|
-
triggerType:
|
|
7449
|
+
triggerType: 'Initial',
|
|
7390
7450
|
triggerEvent: null,
|
|
7391
7451
|
pastedLength: 0
|
|
7392
7452
|
});
|
|
@@ -7403,14 +7463,13 @@ class WithDisplayFormat extends React.Component {
|
|
|
7403
7463
|
const {
|
|
7404
7464
|
selectionStart,
|
|
7405
7465
|
selectionEnd
|
|
7406
|
-
} = event.
|
|
7466
|
+
} = event.currentTarget;
|
|
7407
7467
|
const {
|
|
7408
7468
|
historyNavigator
|
|
7409
7469
|
} = this.state;
|
|
7410
7470
|
const {
|
|
7411
7471
|
displayPattern
|
|
7412
7472
|
} = this.props;
|
|
7413
|
-
|
|
7414
7473
|
// Unfortunately Undo and Redo don't trigger OnChange event so we need to handle some value logic here.
|
|
7415
7474
|
let newFormattedValue = '';
|
|
7416
7475
|
if (this.detectUndoRedo(event) === 'Undo') {
|
|
@@ -7429,8 +7488,8 @@ class WithDisplayFormat extends React.Component {
|
|
|
7429
7488
|
this.setState({
|
|
7430
7489
|
triggerEvent: event,
|
|
7431
7490
|
triggerType: 'KeyDown',
|
|
7432
|
-
selectionStart,
|
|
7433
|
-
selectionEnd
|
|
7491
|
+
selectionStart: selectionStart ?? 0,
|
|
7492
|
+
selectionEnd: selectionEnd ?? 0
|
|
7434
7493
|
});
|
|
7435
7494
|
}
|
|
7436
7495
|
};
|
|
@@ -7459,7 +7518,6 @@ class WithDisplayFormat extends React.Component {
|
|
|
7459
7518
|
handleOnChange = event => {
|
|
7460
7519
|
const {
|
|
7461
7520
|
historyNavigator,
|
|
7462
|
-
triggerEvent,
|
|
7463
7521
|
triggerType
|
|
7464
7522
|
} = this.state;
|
|
7465
7523
|
const {
|
|
@@ -7470,9 +7528,7 @@ class WithDisplayFormat extends React.Component {
|
|
|
7470
7528
|
value
|
|
7471
7529
|
} = event.target;
|
|
7472
7530
|
let unformattedValue = unformatWithPattern$1(value, displayPattern);
|
|
7473
|
-
const action =
|
|
7474
|
-
// triggerEvent can be null only in case of "autofilling" (via password manager extension or browser build-in one) events
|
|
7475
|
-
'Paste' : this.getUserAction(unformattedValue);
|
|
7531
|
+
const action = this.getUserAction(unformattedValue);
|
|
7476
7532
|
if (!this.isKeyAllowed(action) || triggerType === 'Undo' || triggerType === 'Redo') {
|
|
7477
7533
|
return;
|
|
7478
7534
|
}
|
|
@@ -7482,19 +7538,18 @@ class WithDisplayFormat extends React.Component {
|
|
|
7482
7538
|
const newFormattedValue = formatWithPattern$1(unformattedValue, displayPattern);
|
|
7483
7539
|
historyNavigator.add(unformattedValue);
|
|
7484
7540
|
this.handleCursorPositioning(action);
|
|
7485
|
-
const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
|
|
7486
7541
|
this.setState({
|
|
7487
7542
|
value: newFormattedValue
|
|
7488
|
-
},
|
|
7543
|
+
}, () => {
|
|
7544
|
+
this.resetEvent();
|
|
7545
|
+
if (onChange) {
|
|
7546
|
+
const broadcastValue = unformatWithPattern$1(newFormattedValue, displayPattern);
|
|
7547
|
+
onChange(broadcastValue);
|
|
7548
|
+
}
|
|
7549
|
+
});
|
|
7489
7550
|
};
|
|
7490
7551
|
handleOnBlur = event => {
|
|
7491
|
-
|
|
7492
|
-
displayPattern,
|
|
7493
|
-
onBlur
|
|
7494
|
-
} = this.props;
|
|
7495
|
-
if (onBlur) {
|
|
7496
|
-
onBlur(unformatWithPattern$1(event.target.value, displayPattern));
|
|
7497
|
-
}
|
|
7552
|
+
this.props.onBlur?.(unformatWithPattern$1(event.target.value, this.props.displayPattern));
|
|
7498
7553
|
};
|
|
7499
7554
|
handleOnFocus = event => {
|
|
7500
7555
|
const {
|
|
@@ -7543,7 +7598,7 @@ class WithDisplayFormat extends React.Component {
|
|
|
7543
7598
|
const cursorPosition = getCursorPositionAfterKeystroke(action, selectionStart, selectionEnd, displayPattern, pastedLength);
|
|
7544
7599
|
setTimeout(() => {
|
|
7545
7600
|
if (triggerEvent) {
|
|
7546
|
-
triggerEvent.
|
|
7601
|
+
triggerEvent.currentTarget.setSelectionRange(cursorPosition, cursorPosition);
|
|
7547
7602
|
}
|
|
7548
7603
|
this.setState({
|
|
7549
7604
|
selectionStart: cursorPosition,
|
|
@@ -7553,7 +7608,6 @@ class WithDisplayFormat extends React.Component {
|
|
|
7553
7608
|
};
|
|
7554
7609
|
render() {
|
|
7555
7610
|
const {
|
|
7556
|
-
type,
|
|
7557
7611
|
inputMode,
|
|
7558
7612
|
className,
|
|
7559
7613
|
id,
|
|
@@ -7570,7 +7624,6 @@ class WithDisplayFormat extends React.Component {
|
|
|
7570
7624
|
value
|
|
7571
7625
|
} = this.state;
|
|
7572
7626
|
const renderProps = {
|
|
7573
|
-
type,
|
|
7574
7627
|
inputMode,
|
|
7575
7628
|
className,
|
|
7576
7629
|
id,
|
|
@@ -7593,62 +7646,13 @@ class WithDisplayFormat extends React.Component {
|
|
|
7593
7646
|
return this.props.render(renderProps);
|
|
7594
7647
|
}
|
|
7595
7648
|
}
|
|
7596
|
-
WithDisplayFormat.propTypes = {
|
|
7597
|
-
/**
|
|
7598
|
-
* autocomplete hides our form help so we need to disable it when help text
|
|
7599
|
-
* is present. Chrome ignores autocomplete=off, the only way to disable it is
|
|
7600
|
-
* to provide an 'invalid' value, for which 'disabled' serves.
|
|
7601
|
-
*/
|
|
7602
|
-
autoComplete: PropTypes__default.default.oneOf(['on', 'off', 'disabled']),
|
|
7603
|
-
className: PropTypes__default.default.string,
|
|
7604
|
-
disabled: PropTypes__default.default.bool,
|
|
7605
|
-
id: PropTypes__default.default.string,
|
|
7606
|
-
maxLength: PropTypes__default.default.number,
|
|
7607
|
-
minLength: PropTypes__default.default.number,
|
|
7608
|
-
name: PropTypes__default.default.string,
|
|
7609
|
-
onFocus: PropTypes__default.default.func,
|
|
7610
|
-
onBlur: PropTypes__default.default.func,
|
|
7611
|
-
onChange: PropTypes__default.default.func.isRequired,
|
|
7612
|
-
placeholder: PropTypes__default.default.string,
|
|
7613
|
-
readOnly: PropTypes__default.default.bool,
|
|
7614
|
-
render: PropTypes__default.default.func.isRequired,
|
|
7615
|
-
required: PropTypes__default.default.bool,
|
|
7616
|
-
displayPattern: PropTypes__default.default.string,
|
|
7617
|
-
type: PropTypes__default.default.string,
|
|
7618
|
-
inputMode: PropTypes__default.default.string,
|
|
7619
|
-
value: PropTypes__default.default.string
|
|
7620
|
-
};
|
|
7621
|
-
WithDisplayFormat.defaultProps = {
|
|
7622
|
-
autoComplete: 'off',
|
|
7623
|
-
className: null,
|
|
7624
|
-
disabled: false,
|
|
7625
|
-
id: null,
|
|
7626
|
-
maxLength: null,
|
|
7627
|
-
minLength: null,
|
|
7628
|
-
name: null,
|
|
7629
|
-
placeholder: null,
|
|
7630
|
-
readOnly: false,
|
|
7631
|
-
required: false,
|
|
7632
|
-
displayPattern: '',
|
|
7633
|
-
type: 'text',
|
|
7634
|
-
inputMode: null,
|
|
7635
|
-
value: '',
|
|
7636
|
-
onFocus: null,
|
|
7637
|
-
onBlur: null
|
|
7638
|
-
};
|
|
7639
|
-
var WithDisplayFormat$1 = WithDisplayFormat;
|
|
7640
7649
|
|
|
7641
|
-
const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat
|
|
7650
|
+
const InputWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
|
|
7642
7651
|
...props,
|
|
7643
|
-
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(
|
|
7652
|
+
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(Input, {
|
|
7644
7653
|
...renderProps
|
|
7645
7654
|
})
|
|
7646
7655
|
});
|
|
7647
|
-
InputWithDisplayFormat.propTypes = {
|
|
7648
|
-
displayPattern: PropTypes__default.default.string.isRequired,
|
|
7649
|
-
onChange: PropTypes__default.default.func.isRequired
|
|
7650
|
-
};
|
|
7651
|
-
var InputWithDisplayFormat$1 = InputWithDisplayFormat;
|
|
7652
7656
|
|
|
7653
7657
|
const InstructionsList = ({
|
|
7654
7658
|
dos,
|
|
@@ -9597,79 +9601,111 @@ const countries = [{
|
|
|
9597
9601
|
iso3: 'ZWE',
|
|
9598
9602
|
phone: '+263'
|
|
9599
9603
|
}];
|
|
9604
|
+
var countries$1 = countries;
|
|
9600
9605
|
|
|
9601
9606
|
const longestMatchingPrefix = matchingCodes => matchingCodes.reduce((a, b) => a.phone.length > b.phone.length ? a : b);
|
|
9602
9607
|
|
|
9603
9608
|
const findCountryByCode = code => {
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
return longestMatchingPrefix(matchingCodes);
|
|
9608
|
-
}
|
|
9609
|
+
let matchingCodes;
|
|
9610
|
+
if (code && code.length === 2) {
|
|
9611
|
+
matchingCodes = countries$1.filter(country => code.toUpperCase() === country.iso2);
|
|
9609
9612
|
}
|
|
9610
|
-
return null;
|
|
9613
|
+
return matchingCodes && matchingCodes.length > 0 ? longestMatchingPrefix(matchingCodes) : null;
|
|
9611
9614
|
};
|
|
9612
9615
|
|
|
9613
9616
|
/**
|
|
9614
9617
|
* Default phone code, the UK one `+44`
|
|
9615
9618
|
*/
|
|
9616
9619
|
const DEFAULT_PHONE_CODE = '+44';
|
|
9620
|
+
|
|
9617
9621
|
/**
|
|
9618
9622
|
* Given a valid locale it returns the correspondent prefix if found or +44 otherwise.
|
|
9619
9623
|
*
|
|
9620
|
-
* @param locale
|
|
9621
|
-
* @param countryCode
|
|
9624
|
+
* @param {string} locale - a string that represent the locale ex:'es-ES'
|
|
9625
|
+
* @param countryCode
|
|
9626
|
+
* @returns {string}
|
|
9622
9627
|
*/
|
|
9623
9628
|
const setDefaultPrefix = (locale, countryCode) => {
|
|
9624
|
-
const country =
|
|
9625
|
-
|
|
9629
|
+
const country = findCountryByCode(countryCode) ||
|
|
9630
|
+
// when `locale` code has explicit region: `en-GB`, `en-US`, `ar-AE`
|
|
9631
|
+
findCountryByCode(getCountryFromLocale(locale)) ||
|
|
9632
|
+
// when `locale` code is only two chars value: `fr`, `es`
|
|
9633
|
+
findCountryByCode(locale);
|
|
9634
|
+
return country?.phone || DEFAULT_PHONE_CODE;
|
|
9626
9635
|
};
|
|
9627
9636
|
|
|
9628
9637
|
/**
|
|
9629
9638
|
*
|
|
9630
9639
|
* @param phoneNumber
|
|
9631
|
-
* @returns
|
|
9640
|
+
* @returns {boolean} - returns true for number that starts with '+' and contains a mix of digits and spaces with
|
|
9641
|
+
* at least 4 digits.
|
|
9632
9642
|
*/
|
|
9633
|
-
const isValidPhoneNumber = phoneNumber => /^\+[\d-\s]+$/.test(phoneNumber) && (phoneNumber.match(/\d+/g)
|
|
9643
|
+
const isValidPhoneNumber = phoneNumber => /^\+[\d-\s]+$/.test(phoneNumber) && phoneNumber.match(/\d+/g) && phoneNumber.match(/\d+/g).join('').length >= 4;
|
|
9634
9644
|
|
|
9635
9645
|
const findCountryByPrefix = number => {
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
|
|
9639
|
-
return longestMatchingPrefix(matchingCodes);
|
|
9640
|
-
}
|
|
9646
|
+
let matchingCodes = null;
|
|
9647
|
+
if (number && number.length > 1) {
|
|
9648
|
+
matchingCodes = countries$1.filter(country => number.indexOf(country.phone) === 0);
|
|
9641
9649
|
}
|
|
9642
|
-
return null;
|
|
9650
|
+
return matchingCodes && matchingCodes.length > 0 ? longestMatchingPrefix(matchingCodes) : null;
|
|
9643
9651
|
};
|
|
9644
9652
|
|
|
9645
9653
|
/**
|
|
9646
|
-
*
|
|
9654
|
+
* Given a sting in a valid format ex:'+447573135343' it returns an object of shape
|
|
9655
|
+
* {prefix=+44 ,suffix=7573135343}
|
|
9656
|
+
*
|
|
9657
|
+
* @param {string} number - a string that defines a phone number.
|
|
9658
|
+
* @returns {{prefix: (string|*), suffix: string, format: string}}
|
|
9647
9659
|
*/
|
|
9648
9660
|
const explodeNumberModel = number => {
|
|
9661
|
+
let prefix = '';
|
|
9662
|
+
let suffix = '';
|
|
9663
|
+
let format = '';
|
|
9649
9664
|
const country = findCountryByPrefix(number);
|
|
9650
|
-
|
|
9651
|
-
prefix
|
|
9652
|
-
suffix
|
|
9653
|
-
format
|
|
9654
|
-
}
|
|
9655
|
-
prefix
|
|
9656
|
-
suffix
|
|
9665
|
+
if (country) {
|
|
9666
|
+
prefix = country.phone;
|
|
9667
|
+
suffix = number.slice(country.phone.length);
|
|
9668
|
+
format = country.phoneFormat || '';
|
|
9669
|
+
} else {
|
|
9670
|
+
prefix = '';
|
|
9671
|
+
suffix = number.slice(1);
|
|
9672
|
+
format = '';
|
|
9673
|
+
}
|
|
9674
|
+
return {
|
|
9675
|
+
prefix,
|
|
9676
|
+
suffix,
|
|
9677
|
+
format
|
|
9657
9678
|
};
|
|
9658
9679
|
};
|
|
9659
9680
|
|
|
9660
9681
|
const DIGITS_MATCH = /^$|^(\+)|([\d]+)/g;
|
|
9661
|
-
const cleanNumber = number => number.match(DIGITS_MATCH)
|
|
9682
|
+
const cleanNumber = number => number.match(DIGITS_MATCH) && number.match(DIGITS_MATCH).join('') || '';
|
|
9662
9683
|
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
}
|
|
9684
|
+
// Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
|
9685
|
+
const sortArrayByProperty = (arrayToSort, property) => [...arrayToSort].sort((a, b) => a[property].localeCompare(b[property]));
|
|
9666
9686
|
|
|
9667
9687
|
const groupCountriesByPrefix = countries => {
|
|
9668
|
-
const
|
|
9669
|
-
|
|
9670
|
-
|
|
9671
|
-
|
|
9672
|
-
|
|
9688
|
+
const groupedArray = countries.reduce((accumulator, country) => {
|
|
9689
|
+
const {
|
|
9690
|
+
name,
|
|
9691
|
+
iso2,
|
|
9692
|
+
iso3,
|
|
9693
|
+
phone
|
|
9694
|
+
} = country;
|
|
9695
|
+
if (accumulator[phone]) {
|
|
9696
|
+
const previousValue = accumulator[phone];
|
|
9697
|
+
accumulator[phone] = {
|
|
9698
|
+
...previousValue,
|
|
9699
|
+
name: neptuneValidation.isArray(previousValue.name) ? [...previousValue.name, name] : [previousValue.name, name],
|
|
9700
|
+
iso2: neptuneValidation.isArray(previousValue.iso2) ? [...previousValue.iso2, iso2] : [previousValue.iso2, iso2],
|
|
9701
|
+
iso3: neptuneValidation.isArray(previousValue.iso3) ? [...previousValue.iso3, iso3] : [previousValue.iso3, iso3]
|
|
9702
|
+
};
|
|
9703
|
+
} else {
|
|
9704
|
+
accumulator[phone] = country;
|
|
9705
|
+
}
|
|
9706
|
+
return accumulator;
|
|
9707
|
+
}, {});
|
|
9708
|
+
return Object.values(groupedArray);
|
|
9673
9709
|
};
|
|
9674
9710
|
|
|
9675
9711
|
// Reference fro localeCompare : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
|
@@ -9677,38 +9713,41 @@ const filterCountriesByIso3 = (countries, iso3Codes) => {
|
|
|
9677
9713
|
const iso3CodesSet = new Set(iso3Codes);
|
|
9678
9714
|
return countries.filter(country => !iso3CodesSet.has(country.iso3));
|
|
9679
9715
|
};
|
|
9716
|
+
|
|
9680
9717
|
/**
|
|
9681
9718
|
* Removes the countries sepecified in the second param
|
|
9682
9719
|
*
|
|
9683
|
-
* @param countries list of country metadata objects
|
|
9684
|
-
* @param disabledCountries list of iso3 country codes to remove from the list
|
|
9720
|
+
* @param {Array} countries: list of country metadata objects
|
|
9721
|
+
* @param {Array} disabledCountries: list of iso3 country codes to remove from the list
|
|
9722
|
+
* @returns
|
|
9685
9723
|
*/
|
|
9686
9724
|
const excludeCountries = (countries, disabledCountries) => {
|
|
9687
9725
|
return disabledCountries.length > 0 ? filterCountriesByIso3(countries, disabledCountries) : countries;
|
|
9688
9726
|
};
|
|
9689
9727
|
|
|
9690
9728
|
const ALLOWED_PHONE_CHARS = /^$|^[\d-\s]+$/;
|
|
9691
|
-
const
|
|
9692
|
-
const
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
disabledCountries = defaultDisabledCountries
|
|
9707
|
-
}) => {
|
|
9729
|
+
const PhoneNumberInput = props => {
|
|
9730
|
+
const {
|
|
9731
|
+
id,
|
|
9732
|
+
onChange,
|
|
9733
|
+
searchPlaceholder,
|
|
9734
|
+
disabled,
|
|
9735
|
+
required,
|
|
9736
|
+
size,
|
|
9737
|
+
placeholder,
|
|
9738
|
+
onFocus,
|
|
9739
|
+
onBlur,
|
|
9740
|
+
countryCode,
|
|
9741
|
+
selectProps,
|
|
9742
|
+
disabledCountries
|
|
9743
|
+
} = props;
|
|
9708
9744
|
const {
|
|
9709
9745
|
locale
|
|
9710
9746
|
} = reactIntl.useIntl();
|
|
9711
|
-
const
|
|
9747
|
+
const getInitialValue = () => {
|
|
9748
|
+
const {
|
|
9749
|
+
initialValue
|
|
9750
|
+
} = props;
|
|
9712
9751
|
const cleanValue = initialValue ? cleanNumber(initialValue) : null;
|
|
9713
9752
|
if (!cleanValue || !isValidPhoneNumber(cleanValue)) {
|
|
9714
9753
|
return {
|
|
@@ -9717,16 +9756,54 @@ const PhoneNumberInput = ({
|
|
|
9717
9756
|
};
|
|
9718
9757
|
}
|
|
9719
9758
|
return explodeNumberModel(cleanValue);
|
|
9720
|
-
}
|
|
9759
|
+
};
|
|
9760
|
+
const [internalValue, setInternalValue] = React.useState(getInitialValue());
|
|
9721
9761
|
const [broadcastedValue, setBroadcastedValue] = React.useState(null);
|
|
9722
|
-
const
|
|
9762
|
+
const getSelectOptions = () => {
|
|
9763
|
+
const countriesList = excludeCountries(countries$1, disabledCountries);
|
|
9764
|
+
const listSortedByISO3 = groupCountriesByPrefix(sortArrayByProperty(countriesList, 'iso3'));
|
|
9765
|
+
return listSortedByISO3.map(option => {
|
|
9766
|
+
const {
|
|
9767
|
+
phone,
|
|
9768
|
+
iso3,
|
|
9769
|
+
iso2,
|
|
9770
|
+
name
|
|
9771
|
+
} = option;
|
|
9772
|
+
let note = '';
|
|
9773
|
+
if (iso3) {
|
|
9774
|
+
note = neptuneValidation.isArray(iso3) ? iso3.join(', ') : iso3;
|
|
9775
|
+
} else if (iso2) {
|
|
9776
|
+
note = neptuneValidation.isArray(iso2) ? iso2.join(', ') : iso2;
|
|
9777
|
+
}
|
|
9778
|
+
return {
|
|
9779
|
+
type: 'option',
|
|
9780
|
+
value: {
|
|
9781
|
+
value: phone,
|
|
9782
|
+
label: phone,
|
|
9783
|
+
note: note
|
|
9784
|
+
},
|
|
9785
|
+
filterMatchers: [phone, note, name]
|
|
9786
|
+
};
|
|
9787
|
+
});
|
|
9788
|
+
};
|
|
9789
|
+
const options = getSelectOptions();
|
|
9790
|
+
const onPrefixChange = ({
|
|
9791
|
+
value
|
|
9792
|
+
}) => {
|
|
9793
|
+
setInternalValue({
|
|
9794
|
+
prefix: value,
|
|
9795
|
+
suffix: internalValue.suffix
|
|
9796
|
+
});
|
|
9797
|
+
};
|
|
9723
9798
|
const onSuffixChange = event => {
|
|
9724
|
-
const
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9799
|
+
const {
|
|
9800
|
+
value = ''
|
|
9801
|
+
} = event.target;
|
|
9802
|
+
if (ALLOWED_PHONE_CHARS.test(value)) {
|
|
9803
|
+
setInternalValue({
|
|
9804
|
+
prefix: internalValue.prefix,
|
|
9805
|
+
suffix: value
|
|
9806
|
+
});
|
|
9730
9807
|
}
|
|
9731
9808
|
};
|
|
9732
9809
|
const onPaste = event => {
|
|
@@ -9734,22 +9811,31 @@ const PhoneNumberInput = ({
|
|
|
9734
9811
|
return;
|
|
9735
9812
|
}
|
|
9736
9813
|
const pastedValue = (event.nativeEvent.clipboardData.getData('text/plain') || '').replace(/(\s|-)+/g, '');
|
|
9737
|
-
const
|
|
9738
|
-
|
|
9739
|
-
|
|
9814
|
+
const {
|
|
9815
|
+
prefix: pastedPrefix,
|
|
9816
|
+
suffix: pastedSuffix
|
|
9817
|
+
} = explodeNumberModel(pastedValue);
|
|
9818
|
+
const selectedPrefix = options.find(({
|
|
9819
|
+
value
|
|
9820
|
+
}) => value.value === pastedPrefix);
|
|
9821
|
+
if (selectedPrefix && ALLOWED_PHONE_CHARS.test(pastedSuffix)) {
|
|
9822
|
+
setInternalValue({
|
|
9823
|
+
prefix: pastedPrefix,
|
|
9824
|
+
suffix: pastedSuffix
|
|
9825
|
+
});
|
|
9740
9826
|
}
|
|
9741
9827
|
};
|
|
9742
9828
|
React.useEffect(() => {
|
|
9743
9829
|
if (broadcastedValue === null) {
|
|
9744
9830
|
return setBroadcastedValue(internalValue);
|
|
9745
9831
|
}
|
|
9746
|
-
const internalPhoneNumber =
|
|
9747
|
-
const broadcastedPhoneNumber =
|
|
9832
|
+
const internalPhoneNumber = internalValue.prefix + internalValue.suffix;
|
|
9833
|
+
const broadcastedPhoneNumber = broadcastedValue.prefix + broadcastedValue.suffix;
|
|
9748
9834
|
if (internalPhoneNumber === broadcastedPhoneNumber) {
|
|
9749
9835
|
return;
|
|
9750
9836
|
}
|
|
9751
9837
|
const newValue = isValidPhoneNumber(internalPhoneNumber) ? cleanNumber(internalPhoneNumber) : null;
|
|
9752
|
-
onChange(newValue, internalValue.prefix
|
|
9838
|
+
onChange(newValue, internalValue.prefix);
|
|
9753
9839
|
setBroadcastedValue(internalValue);
|
|
9754
9840
|
}, [onChange, broadcastedValue, internalValue]);
|
|
9755
9841
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
@@ -9757,29 +9843,18 @@ const PhoneNumberInput = ({
|
|
|
9757
9843
|
children: [/*#__PURE__*/jsxRuntime.jsx("div", {
|
|
9758
9844
|
className: "tw-telephone__country-select",
|
|
9759
9845
|
children: /*#__PURE__*/jsxRuntime.jsx(SelectInput, {
|
|
9760
|
-
placeholder: "Select an option
|
|
9761
|
-
items:
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
value: internalValue.prefix,
|
|
9767
|
-
renderValue: (prefix, withinTrigger) => /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContent, {
|
|
9768
|
-
title: prefix,
|
|
9769
|
-
note: withinTrigger ? undefined : countriesByPrefix.get(prefix)?.map(country => country.iso3).join(', ')
|
|
9846
|
+
placeholder: "Select an option...",
|
|
9847
|
+
items: options,
|
|
9848
|
+
value: options.find(item => item.value.value === internalValue.prefix)?.value,
|
|
9849
|
+
renderValue: (option, withinTrigger) => /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContent, {
|
|
9850
|
+
title: option.label,
|
|
9851
|
+
note: withinTrigger ? undefined : option.note
|
|
9770
9852
|
}),
|
|
9771
9853
|
filterable: true,
|
|
9772
9854
|
filterPlaceholder: searchPlaceholder,
|
|
9773
9855
|
disabled: disabled,
|
|
9774
9856
|
size: size,
|
|
9775
|
-
onChange:
|
|
9776
|
-
const country = prefix != null ? findCountryByPrefix(prefix) : null;
|
|
9777
|
-
setInternalValue(prev => ({
|
|
9778
|
-
...prev,
|
|
9779
|
-
prefix,
|
|
9780
|
-
format: country?.phoneFormat
|
|
9781
|
-
}));
|
|
9782
|
-
},
|
|
9857
|
+
onChange: onPrefixChange,
|
|
9783
9858
|
...selectProps
|
|
9784
9859
|
})
|
|
9785
9860
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
@@ -9805,6 +9880,37 @@ const PhoneNumberInput = ({
|
|
|
9805
9880
|
})]
|
|
9806
9881
|
});
|
|
9807
9882
|
};
|
|
9883
|
+
PhoneNumberInput.propTypes = {
|
|
9884
|
+
id: PropTypes__default.default.string,
|
|
9885
|
+
required: PropTypes__default.default.bool,
|
|
9886
|
+
disabled: PropTypes__default.default.bool,
|
|
9887
|
+
initialValue: PropTypes__default.default.string,
|
|
9888
|
+
onChange: PropTypes__default.default.func.isRequired,
|
|
9889
|
+
onFocus: PropTypes__default.default.func,
|
|
9890
|
+
onBlur: PropTypes__default.default.func,
|
|
9891
|
+
countryCode: PropTypes__default.default.string,
|
|
9892
|
+
searchPlaceholder: PropTypes__default.default.string,
|
|
9893
|
+
size: PropTypes__default.default.oneOf(['sm', 'md', 'lg']),
|
|
9894
|
+
placeholder: PropTypes__default.default.string,
|
|
9895
|
+
selectProps: PropTypes__default.default.object,
|
|
9896
|
+
/** List of iso3 codes of countries to remove from the list */
|
|
9897
|
+
disabledCountries: PropTypes__default.default.arrayOf(PropTypes__default.default.string)
|
|
9898
|
+
};
|
|
9899
|
+
PhoneNumberInput.defaultProps = {
|
|
9900
|
+
id: null,
|
|
9901
|
+
required: false,
|
|
9902
|
+
disabled: false,
|
|
9903
|
+
initialValue: null,
|
|
9904
|
+
onFocus() {},
|
|
9905
|
+
onBlur() {},
|
|
9906
|
+
countryCode: null,
|
|
9907
|
+
searchPlaceholder: 'Prefix',
|
|
9908
|
+
size: exports.Size.MEDIUM,
|
|
9909
|
+
placeholder: '',
|
|
9910
|
+
selectProps: {},
|
|
9911
|
+
disabledCountries: []
|
|
9912
|
+
};
|
|
9913
|
+
var PhoneNumberInput$1 = PhoneNumberInput;
|
|
9808
9914
|
|
|
9809
9915
|
const Progress = ({
|
|
9810
9916
|
className,
|
|
@@ -12223,17 +12329,12 @@ Tabs.defaultProps = {
|
|
|
12223
12329
|
};
|
|
12224
12330
|
var Tabs$1 = Tabs;
|
|
12225
12331
|
|
|
12226
|
-
const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat
|
|
12332
|
+
const TextareaWithDisplayFormat = props => /*#__PURE__*/jsxRuntime.jsx(WithDisplayFormat, {
|
|
12227
12333
|
...props,
|
|
12228
|
-
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(
|
|
12334
|
+
render: renderProps => /*#__PURE__*/jsxRuntime.jsx(TextArea, {
|
|
12229
12335
|
...renderProps
|
|
12230
12336
|
})
|
|
12231
12337
|
});
|
|
12232
|
-
TextareaWithDisplayFormat.propTypes = {
|
|
12233
|
-
displayPattern: PropTypes__default.default.string.isRequired,
|
|
12234
|
-
onChange: PropTypes__default.default.func.isRequired
|
|
12235
|
-
};
|
|
12236
|
-
var TextareaWithDisplayFormat$1 = TextareaWithDisplayFormat;
|
|
12237
12338
|
|
|
12238
12339
|
/* eslint-disable jsx-a11y/no-autofocus */
|
|
12239
12340
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
@@ -15570,7 +15671,7 @@ exports.Info = Info;
|
|
|
15570
15671
|
exports.InlineAlert = InlineAlert;
|
|
15571
15672
|
exports.Input = Input;
|
|
15572
15673
|
exports.InputGroup = InputGroup;
|
|
15573
|
-
exports.InputWithDisplayFormat = InputWithDisplayFormat
|
|
15674
|
+
exports.InputWithDisplayFormat = InputWithDisplayFormat;
|
|
15574
15675
|
exports.InstructionsList = InstructionsList$1;
|
|
15575
15676
|
exports.LanguageProvider = LanguageProvider;
|
|
15576
15677
|
exports.Link = Link;
|
|
@@ -15586,7 +15687,7 @@ exports.NavigationOptionsList = NavigationOptionList$1;
|
|
|
15586
15687
|
exports.Nudge = Nudge;
|
|
15587
15688
|
exports.Option = Option$2;
|
|
15588
15689
|
exports.OverlayHeader = OverlayHeader$1;
|
|
15589
|
-
exports.PhoneNumberInput = PhoneNumberInput;
|
|
15690
|
+
exports.PhoneNumberInput = PhoneNumberInput$1;
|
|
15590
15691
|
exports.Popover = Popover$2;
|
|
15591
15692
|
exports.ProcessIndicator = ProcessIndicator$1;
|
|
15592
15693
|
exports.Progress = Progress;
|
|
@@ -15618,7 +15719,7 @@ exports.Switch = Switch;
|
|
|
15618
15719
|
exports.SwitchOption = SwitchOption;
|
|
15619
15720
|
exports.Tabs = Tabs$1;
|
|
15620
15721
|
exports.TextArea = TextArea;
|
|
15621
|
-
exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat
|
|
15722
|
+
exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat;
|
|
15622
15723
|
exports.Title = Title;
|
|
15623
15724
|
exports.Tooltip = Tooltip$1;
|
|
15624
15725
|
exports.Typeahead = Typeahead;
|