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