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