From 10de49f8ca112710ceabbe483dfffec8487b0e28 Mon Sep 17 00:00:00 2001 From: Artyom Vancyan Date: Sat, 5 Oct 2024 19:44:28 +0400 Subject: [PATCH 1/5] Sync with the latest releases --- development/src/ant-phone/index.tsx | 8 +- development/src/mui-phone/base/index.tsx | 1 + development/src/mui-phone/index.tsx | 8 +- development/src/mui-phone/joy/index.tsx | 30 ++++- development/src/mui-phone/joy/types.ts | 2 + .../src/phone-hooks/metadata/countries.json | 112 +++++++++++------- .../src/phone-hooks/metadata/validations.json | 84 ++++++------- development/src/phone-hooks/styles.ts | 19 +-- development/tsconfig.json | 16 +-- 9 files changed, 166 insertions(+), 114 deletions(-) diff --git a/development/src/ant-phone/index.tsx b/development/src/ant-phone/index.tsx index 217c97a..8e28878 100644 --- a/development/src/ant-phone/index.tsx +++ b/development/src/ant-phone/index.tsx @@ -32,6 +32,7 @@ import { usePhone, } from "../phone-hooks"; +import locale from "./locale"; import {injectMergedStyles} from "./styles"; import {PhoneInputProps, PhoneNumber} from "./types"; @@ -46,6 +47,8 @@ const PhoneInput = forwardRef(({ onlyCountries = [], excludeCountries = [], preferredCountries = [], + searchNotFound: defaultSearchNotFound = "No country found", + searchPlaceholder: defaultSearchPlaceholder = "Search country", dropdownRender = (node) => node, onMount: handleMount = () => null, onInput: handleInput = () => null, @@ -66,8 +69,8 @@ const PhoneInput = forwardRef(({ const [countryCode, setCountryCode] = useState(country); const { - searchNotFound = "No country found", - searchPlaceholder = "Search country", + searchNotFound = defaultSearchNotFound, + searchPlaceholder = defaultSearchPlaceholder, countries = new Proxy({}, ({get: (_: any, prop: any) => prop})), } = (locale as any).PhoneInput || {}; @@ -266,3 +269,4 @@ const PhoneInput = forwardRef(({ }) export default PhoneInput; +export type {PhoneInputProps, PhoneNumber, locale}; diff --git a/development/src/mui-phone/base/index.tsx b/development/src/mui-phone/base/index.tsx index 6c9fcab..6eb1214 100644 --- a/development/src/mui-phone/base/index.tsx +++ b/development/src/mui-phone/base/index.tsx @@ -145,3 +145,4 @@ const PhoneInput = forwardRef(({ }) export default PhoneInput; +export type {PhoneInputProps, PhoneNumber}; diff --git a/development/src/mui-phone/index.tsx b/development/src/mui-phone/index.tsx index 41195c1..6d2cab3 100644 --- a/development/src/mui-phone/index.tsx +++ b/development/src/mui-phone/index.tsx @@ -16,6 +16,7 @@ import { usePhone, } from "../phone-hooks"; +import locale from "./locale"; import {injectMergedStyles} from "./styles"; import {PhoneInputProps, PhoneNumber} from "./types"; @@ -34,6 +35,8 @@ const PhoneInput = forwardRef(({ onlyCountries = [], excludeCountries = [], preferredCountries = [], + searchNotFound: defaultSearchNotFound = "No country found", + searchPlaceholder: defaultSearchPlaceholder = "Search country", onMount: handleMount = () => null, onInput: handleInput = () => null, onChange: handleChange = () => null, @@ -50,8 +53,8 @@ const PhoneInput = forwardRef(({ const [countryCode, setCountryCode] = useState(country); const { - searchNotFound = "No country found", - searchPlaceholder = "Search country", + searchNotFound = defaultSearchNotFound, + searchPlaceholder = defaultSearchPlaceholder, countries = new Proxy({}, ({get: (_: any, prop: any) => prop})), } = useThemeProps({props: {}, name: "MuiPhoneInput"}) as any; @@ -225,3 +228,4 @@ const PhoneInput = forwardRef(({ }) export default PhoneInput; +export type {PhoneInputProps, PhoneNumber, locale}; diff --git a/development/src/mui-phone/joy/index.tsx b/development/src/mui-phone/joy/index.tsx index 0b9f8f1..f17f29c 100644 --- a/development/src/mui-phone/joy/index.tsx +++ b/development/src/mui-phone/joy/index.tsx @@ -1,7 +1,7 @@ "use client"; import {ChangeEvent, forwardRef, KeyboardEvent, useCallback, useEffect, useMemo, useRef, useState} from "react"; -import {Input, Option, Select} from "@mui/joy"; +import {Input, Option, Select, useThemeProps} from "@mui/joy"; import { checkValidity, @@ -16,6 +16,7 @@ import { usePhone, } from "../../phone-hooks"; +import locale from "../locale"; import {injectMergedStyles} from "./styles"; import {PhoneInputProps, PhoneNumber} from "./types"; @@ -27,14 +28,15 @@ const PhoneInput = forwardRef(({ searchVariant = undefined, country = getDefaultISO2Code(), disabled = false, + enableArrow = false, enableSearch = false, disableDropdown = false, disableParentheses = false, onlyCountries = [], excludeCountries = [], preferredCountries = [], - searchNotFound = "No country found", - searchPlaceholder = "Search country", + searchNotFound: defaultSearchNotFound = "No country found", + searchPlaceholder: defaultSearchPlaceholder = "Search country", onMount: handleMount = () => null, onInput: handleInput = () => null, onChange: handleChange = () => null, @@ -50,6 +52,12 @@ const PhoneInput = forwardRef(({ const [maxWidth, setMaxWidth] = useState(0); const [countryCode, setCountryCode] = useState(country); + const { + searchNotFound = defaultSearchNotFound, + searchPlaceholder = defaultSearchPlaceholder, + countries = new Proxy({}, ({get: (_: any, prop: any) => prop})), + } = useThemeProps({props: {}, name: "MuiPhoneInput"}) as any; + const { value, pattern, @@ -168,7 +176,7 @@ const PhoneInput = forwardRef(({ children={
- {name} {displayFormat(mask)} + {countries[name]} {displayFormat(mask)}
} /> @@ -189,10 +197,21 @@ const PhoneInput = forwardRef(({ onKeyDown={onKeyDown} startDecorator={( setOpen(!open)} >
+ {enableArrow && ( + + + + )} )} {...(muiInputProps as any)} @@ -202,3 +221,4 @@ const PhoneInput = forwardRef(({ }) export default PhoneInput; +export type {PhoneInputProps, PhoneNumber, locale}; diff --git a/development/src/mui-phone/joy/types.ts b/development/src/mui-phone/joy/types.ts index 915d123..5326e7e 100644 --- a/development/src/mui-phone/joy/types.ts +++ b/development/src/mui-phone/joy/types.ts @@ -13,6 +13,8 @@ export interface PhoneInputProps extends Omit country?: string; + enableArrow?: boolean; + enableSearch?: boolean; searchNotFound?: string; diff --git a/development/src/phone-hooks/metadata/countries.json b/development/src/phone-hooks/metadata/countries.json index 8914ded..cde19ed 100644 --- a/development/src/phone-hooks/metadata/countries.json +++ b/development/src/phone-hooks/metadata/countries.json @@ -309,7 +309,7 @@ "bz", "Belize", "501", - "+501 (...) .... ...." + "+501 (...) ...." ], [ "bj", @@ -345,13 +345,13 @@ "bw", "Botswana", "267", - "+267 (..) ... ....." + "+267 (..) ... ..." ], [ "br", "Brazil", "55", - "+55 (..) .... ....." + "+55 (..) ..... ...." ], [ "io", @@ -375,7 +375,7 @@ "bg", "Bulgaria", "359", - "+359 (...) ... ... ..." + "+359 (...) ... ..." ], [ "bf", @@ -711,7 +711,7 @@ "cd", "Congo", "243", - "+243 (...) ... ..." + "+243 (...) ... ...." ], [ "cg", @@ -807,7 +807,7 @@ "ec", "Ecuador", "593", - "+593 (..) ... ... ..." + "+593 (..) ... ...." ], [ "eg", @@ -837,7 +837,31 @@ "ee", "Estonia", "372", - "+372 (....) ... ..." + "+372 (...) ....." + ], + [ + "ee", + "Estonia", + "37287", + "+372 (87.) ....." + ], + [ + "ee", + "Estonia", + "3725", + "+372 (5...) ...." + ], + [ + "ee", + "Estonia", + "3728", + "+372 (8...) ...." + ], + [ + "ee", + "Estonia", + "37240", + "+372 (40..) ...." ], [ "et", @@ -861,7 +885,7 @@ "fj", "Fiji", "679", - "+679 (..) ... ... ..." + "+679 (..) ....." ], [ "fi", @@ -885,7 +909,7 @@ "pf", "French Polynesia", "689", - "+689 (..) ... ...." + "+689 (..) ... ..." ], [ "ga", @@ -927,7 +951,7 @@ "gr", "Greece", "30", - "+30 (...) ... ... ..." + "+30 (...) ... ...." ], [ "gl", @@ -1017,7 +1041,7 @@ "id", "Indonesia", "62", - "+62 (..) ... ... ....." + "+62 (..) ... ... ... ... ..." ], [ "ir", @@ -1077,91 +1101,91 @@ "kz", "Kazakhstan", "7310", - "+7 (310) ... ... ....." + "+7 (310) ... ...." ], [ "kz", "Kazakhstan", "7311", - "+7 (311) ... ... ....." + "+7 (311) ... ...." ], [ "kz", "Kazakhstan", "7312", - "+7 (312) ... ... ....." + "+7 (312) ... ...." ], [ "kz", "Kazakhstan", "7313", - "+7 (313) ... ... ....." + "+7 (313) ... ...." ], [ "kz", "Kazakhstan", "7315", - "+7 (315) ... ... ....." + "+7 (315) ... ...." ], [ "kz", "Kazakhstan", "7318", - "+7 (318) ... ... ....." + "+7 (318) ... ...." ], [ "kz", "Kazakhstan", "7321", - "+7 (321) ... ... ....." + "+7 (321) ... ...." ], [ "kz", "Kazakhstan", "7324", - "+7 (324) ... ... ....." + "+7 (324) ... ...." ], [ "kz", "Kazakhstan", "7325", - "+7 (325) ... ... ....." + "+7 (325) ... ...." ], [ "kz", "Kazakhstan", "7326", - "+7 (326) ... ... ....." + "+7 (326) ... ...." ], [ "kz", "Kazakhstan", "7327", - "+7 (327) ... ... ....." + "+7 (327) ... ...." ], [ "kz", "Kazakhstan", "7336", - "+7 (336) ... ... ....." + "+7 (336) ... ...." ], [ "kz", "Kazakhstan", "77172", - "+7 (717) 2.. ... ....." + "+7 (717) 2.. ...." ], [ "kz", "Kazakhstan", "773622", - "+7 (736) 22. ... ....." + "+7 (736) 22. ...." ], [ "ke", "Kenya", "254", - "+254 (...) ... ...." + "+254 (...) ... ..." ], [ "ki", @@ -1185,7 +1209,7 @@ "kg", "Kyrgyzstan", "996", - "+996 (...) ... ...." + "+996 (...) ... ..." ], [ "la", @@ -1311,7 +1335,7 @@ "mu", "Mauritius", "230", - "+230 (...) ... ...." + "+230 (...) ....." ], [ "mx", @@ -1617,7 +1641,7 @@ "me", "Montenegro", "382", - "+382 (..) ... ...." + "+382 (..) ... ..." ], [ "ms", @@ -1659,7 +1683,7 @@ "np", "Nepal", "977", - "+977 (..) ... ... ..." + "+977 (..) ... ....." ], [ "nl", @@ -1731,7 +1755,7 @@ "om", "Oman", "968", - "+968 (..) ... ...." + "+968 (..) ... ..." ], [ "pk", @@ -1755,7 +1779,7 @@ "pa", "Panama", "507", - "+507 (...) ... ....." + "+507 (...) ....." ], [ "pg", @@ -1767,7 +1791,7 @@ "py", "Paraguay", "595", - "+595 (...) ... ....." + "+595 (...) ... ..." ], [ "pe", @@ -1779,13 +1803,13 @@ "ph", "Philippines", "63", - "+63 (...) ... ... ...." + "+63 (...) ... ...." ], [ "pl", "Poland", "48", - "+48 (...) ... ...." + "+48 (...) ... ..." ], [ "pt", @@ -1809,7 +1833,7 @@ "qa", "Qatar", "974", - "+974 (....) .... ..." + "+974 (....) ...." ], [ "ro", @@ -1821,7 +1845,7 @@ "ru", "Russia", "7", - "+7 (...) ... ... ....." + "+7 (...) ... ...." ], [ "rw", @@ -1953,7 +1977,7 @@ "es", "Spain", "34", - "+34 (...) ... ..." + "+34 (...) .. .. .." ], [ "lk", @@ -2037,7 +2061,7 @@ "th", "Thailand", "66", - "+66 (..) ... ... ....." + "+66 (..) ... ....." ], [ "tl", @@ -2079,7 +2103,7 @@ "tr", "Turkey", "90", - "+90 (...) ... ... ...." + "+90 (...) ... .. .." ], [ "tm", @@ -2121,13 +2145,13 @@ "ae", "United Arab Emirates", "971", - "+971 (.) ... ... ....." + "+971 (.) ... ....." ], [ "ae", "United Arab Emirates", "9715", - "+971 (..) ... ... ...." + "+971 (..) ... ...." ], [ "gb", @@ -3591,7 +3615,7 @@ "uy", "Uruguay", "598", - "+598 (.) ... ... ... ..." + "+598 (.) ... ...." ], [ "uz", @@ -3627,7 +3651,7 @@ "wf", "Wallis & Futuna", "681", - "+681 (..) ... ...." + "+681 (..) ...." ], [ "ye", diff --git a/development/src/phone-hooks/metadata/validations.json b/development/src/phone-hooks/metadata/validations.json index 3fe5e61..8c4797c 100644 --- a/development/src/phone-hooks/metadata/validations.json +++ b/development/src/phone-hooks/metadata/validations.json @@ -4,7 +4,7 @@ "^(?:1|6\\d)\\d{7}|[135-9]\\d{5}$" ], "ae": [ - "^\\d{5,12}$", + "^\\d{8,9}$", "^(?:[4-7]\\d|9[0-689])\\d{7}|800\\d{2,9}|[2-4679]\\d{7}$" ], "af": [ @@ -76,7 +76,7 @@ "^[025-7]\\d{7}$" ], "bg": [ - "^\\d{6,12}$", + "^\\d{6,9}$", "^00800\\d{7}|[2-7]\\d{6,7}|[89]\\d{6,8}|2\\d{5}$" ], "bh": [ @@ -101,7 +101,7 @@ ], "bo": [ "^\\d{8,9}$", - "^(?:[2-467]\\d\\d|8001)\\d{5}$" + "^8001\\d{5}|(?:[2-467]\\d|50)\\d{6}$" ], "bq": [ "^\\d{7}$", @@ -120,7 +120,7 @@ "^[17]\\d{7}|[2-8]\\d{6}$" ], "bw": [ - "^\\d{7,10}$", + "^\\d{7,8}$", "^(?:0800|(?:[37]|800)\\d)\\d{6}|(?:[2-6]\\d|90)\\d{5}$" ], "by": [ @@ -128,7 +128,7 @@ "^(?:[12]\\d|33|44|902)\\d{7}|8(?:0[0-79]\\d{5,7}|[1-7]\\d{9})|8(?:1[0-489]|[5-79]\\d)\\d{7}|8[1-79]\\d{6,7}|8[0-79]\\d{5}|8\\d{5}$" ], "bz": [ - "^\\d{7,11}$", + "^\\d{7}$", "^(?:0800\\d|[2-8])\\d{6}$" ], "ca": [ @@ -136,8 +136,8 @@ "^(?:[2-8]\\d|90)\\d{8}|3\\d{6}$" ], "cd": [ - "^\\d{7,9}$", - "^[189]\\d{8}|[1-68]\\d{6}$" + "^\\d{7,10}$", + "^(?:(?:[189]|5\\d)\\d|2)\\d{7}|[1-68]\\d{6}$" ], "cf": [ "^\\d{8}$", @@ -164,16 +164,16 @@ "^12300\\d{6}|6\\d{9,10}|[2-9]\\d{8}$" ], "cm": [ - "^\\d{8,9}$", + "^\\d{9}$", "^[26]\\d{8}|88\\d{6,7}$" ], "cn": [ "^\\d{7,12}$", - "^1[127]\\d{8,9}|2\\d{9}(?:\\d{2})?|[12]\\d{6,7}|86\\d{6}|(?:1[03-689]\\d|6)\\d{7,9}|(?:[3-579]\\d|8[0-57-9])\\d{6,9}$" + "^(?:(?:1[03-689]|2\\d)\\d\\d|6)\\d{8}|1\\d{10}|[126]\\d{6}(?:\\d(?:\\d{2})?)?|86\\d{5,6}|(?:[3-579]\\d|8[0-57-9])\\d{5,9}$" ], "co": [ "^\\d{10,11}$", - "^(?:60\\d\\d|9101)\\d{6}|(?:1\\d|3)\\d{9}$" + "^60\\d{8}|(?:1\\d|[39])\\d{9}$" ], "cr": [ "^\\d{8,10}$", @@ -224,11 +224,11 @@ "^(?:[1-4]|[5-79]\\d|80)\\d{7}$" ], "ec": [ - "^\\d{8,11}$", + "^\\d{8,9}$", "^1\\d{9,10}|(?:[2-7]|9\\d)\\d{7}$" ], "ee": [ - "^\\d{7,10}$", + "^\\d{7,8}$", "^8\\d{9}|[4578]\\d{7}|(?:[3-8]\\d|90)\\d{5}$" ], "eg": [ @@ -252,7 +252,7 @@ "^[1-35689]\\d{4}|7\\d{10,11}|(?:[124-7]\\d|3[0-46-9])\\d{8}|[1-9]\\d{5,8}$" ], "fj": [ - "^\\d{7,11}$", + "^\\d{7}$", "^45\\d{5}|(?:0800\\d|[235-9])\\d{6}$" ], "fk": [ @@ -320,7 +320,7 @@ "^222\\d{6}|(?:3\\d|55|[89]0)\\d{7}$" ], "gr": [ - "^\\d{10,12}$", + "^\\d{10}$", "^5005000\\d{3}|8\\d{9,11}|(?:[269]\\d|70)\\d{8}$" ], "gt": [ @@ -360,15 +360,15 @@ "^[235-7]\\d{8}|[1-9]\\d{7}$" ], "id": [ - "^\\d{7,13}$", - "^(?:(?:00[1-9]|8\\d)\\d{4}|[1-36])\\d{6}|00\\d{10}|[1-9]\\d{8,10}|[2-9]\\d{7}$" + "^\\d{7,17}$", + "^00[1-9]\\d{9,14}|(?:[1-36]|8\\d{5})\\d{6}|00\\d{9}|[1-9]\\d{8,10}|[2-9]\\d{7}$" ], "ie": [ "^\\d{7,10}$", "^(?:1\\d|[2569])\\d{6,8}|4\\d{6,9}|7\\d{8}|8\\d{8,9}$" ], "il": [ - "^\\d{7,12}$", + "^\\d{8,12}$", "^1\\d{6}(?:\\d{3,5})?|[57]\\d{8}|[1-489]\\d{7}$" ], "in": [ @@ -412,11 +412,11 @@ "^00[1-9]\\d{6,14}|[257-9]\\d{9}|(?:00|[1-9]\\d\\d)\\d{6}$" ], "ke": [ - "^\\d{7,10}$", + "^\\d{7,9}$", "^(?:[17]\\d\\d|900)\\d{6}|(?:2|80)0\\d{6,7}|[4-6]\\d{6,8}$" ], "kg": [ - "^\\d{9,10}$", + "^\\d{9}$", "^8\\d{9}|[235-9]\\d{8}$" ], "kh": [ @@ -444,7 +444,7 @@ "^00[1-9]\\d{8,11}|(?:[12]|5\\d{3})\\d{7}|[13-6]\\d{9}|(?:[1-6]\\d|80)\\d{7}|[3-6]\\d{4,5}|(?:00|7)0\\d{8}$" ], "kw": [ - "^\\d{7,8}$", + "^\\d{8}$", "^18\\d{5}|(?:[2569]\\d|41)\\d{6}$" ], "ky": [ @@ -452,7 +452,7 @@ "^(?:345|[58]\\d\\d|900)\\d{7}$" ], "kz": [ - "^\\d{10,14}$", + "^\\d{10}$", "^(?:33622|8\\d{8})\\d{5}|[78]\\d{9}$" ], "la": [ @@ -512,7 +512,7 @@ "^(?:[235-7]\\d|[89]0)\\d{6}$" ], "me": [ - "^\\d{8,9}$", + "^\\d{8}$", "^(?:20|[3-79]\\d)\\d{6}|80\\d{6,7}$" ], "mg": [ @@ -540,7 +540,7 @@ "^[12]\\d{7,9}|[5-9]\\d{7}$" ], "mo": [ - "^\\d{7,8}$", + "^\\d{8}$", "^0800\\d{3}|(?:28|[68]\\d)\\d{6}$" ], "mp": [ @@ -564,7 +564,7 @@ "^3550\\d{4}|(?:[2579]\\d\\d|800)\\d{5}$" ], "mu": [ - "^\\d{7,10}$", + "^\\d{7,8}$", "^(?:[57]|8\\d\\d)\\d{7}|[2-468]\\d{6}$" ], "mv": [ @@ -604,8 +604,8 @@ "^[13]\\d{5}$" ], "ng": [ - "^\\d{7,14}$", - "^2[0-24-9]\\d{8}|[78]\\d{10,13}|[7-9]\\d{9}|[1-9]\\d{7}|[124-7]\\d{6}$" + "^\\d{8,14}$", + "^38\\d{6}|[78]\\d{9,13}|(?:20|9\\d)\\d{8}$" ], "ni": [ "^\\d{8}$", @@ -620,7 +620,7 @@ "^(?:0|[2-9]\\d{3})\\d{4}$" ], "np": [ - "^\\d{8,11}$", + "^\\d{8,10}$", "^(?:1\\d|9)\\d{9}|[1-9]\\d{7}$" ], "nr": [ @@ -636,11 +636,11 @@ "^[1289]\\d{9}|50\\d{5}(?:\\d{2,3})?|[27-9]\\d{7,8}|(?:[34]\\d|6[0-35-9])\\d{6}|8\\d{4,6}$" ], "om": [ - "^\\d{7,9}$", + "^\\d{8}$", "^(?:1505|[279]\\d{3}|500)\\d{4}|800\\d{5,6}$" ], "pa": [ - "^\\d{7,11}$", + "^\\d{7,8}$", "^(?:00800|8\\d{3})\\d{6}|[68]\\d{7}|[1-57-9]\\d{6}$" ], "pe": [ @@ -648,7 +648,7 @@ "^(?:[14-8]|9\\d)\\d{7}$" ], "pf": [ - "^\\d{6,9}$", + "^\\d{6,8}$", "^4\\d{5}(?:\\d{2})?|8\\d{7,8}$" ], "pg": [ @@ -656,7 +656,7 @@ "^(?:180|[78]\\d{3})\\d{4}|(?:[2-589]\\d|64)\\d{5}$" ], "ph": [ - "^\\d{6,13}$", + "^\\d{6,10}$", "^(?:[2-7]|9\\d)\\d{8}|2\\d{5}|(?:1800|8)\\d{7,9}$" ], "pk": [ @@ -664,7 +664,7 @@ "^122\\d{6}|[24-8]\\d{10,11}|9(?:[013-9]\\d{8,10}|2(?:[01]\\d\\d|2(?:[06-8]\\d|1[01]))\\d{7})|(?:[2-8]\\d{3}|92(?:[0-7]\\d|8[1-9]))\\d{6}|[24-9]\\d{8}|[89]\\d{7}$" ], "pl": [ - "^\\d{6,10}$", + "^\\d{6,9}$", "^(?:6|8\\d\\d)\\d{7}|[1-9]\\d{6}(?:\\d{2})?|[26]\\d{5}$" ], "pm": [ @@ -688,11 +688,11 @@ "^(?:[24-8]\\d\\d|345|900)\\d{4}$" ], "py": [ - "^\\d{6,11}$", + "^\\d{6,9}$", "^59\\d{4,6}|9\\d{5,10}|(?:[2-46-8]\\d|5[0-8])\\d{4,7}$" ], "qa": [ - "^\\d{7,11}$", + "^\\d{7,8}$", "^800\\d{4}|(?:2|800)\\d{6}|(?:0080|[3-7])\\d{7}$" ], "re": [ @@ -708,7 +708,7 @@ "^38[02-9]\\d{6,9}|6\\d{7,9}|90\\d{4,8}|38\\d{5,6}|(?:7\\d\\d|800)\\d{3,9}|(?:[12]\\d|3[0-79])\\d{5,10}$" ], "ru": [ - "^\\d{10,14}$", + "^\\d{10}$", "^8\\d{13}|[347-9]\\d{9}$" ], "rw": [ @@ -725,14 +725,14 @@ ], "sc": [ "^\\d{7}$", - "^800\\d{4}|(?:[249]\\d|64)\\d{5}$" + "^(?:[2489]\\d|64)\\d{5}$" ], "sd": [ "^\\d{9}$", "^[19]\\d{8}$" ], "se": [ - "^\\d{6,12}$", + "^\\d{7,12}$", "^(?:[26]\\d\\d|9)\\d{9}|[1-9]\\d{8}|[1-689]\\d{7}|[1-4689]\\d{6}|2\\d{5}$" ], "sg": [ @@ -801,14 +801,14 @@ ], "td": [ "^\\d{8}$", - "^(?:22|[69]\\d|77)\\d{6}$" + "^(?:22|[689]\\d|77)\\d{6}$" ], "tg": [ "^\\d{8}$", "^[279]\\d{7}$" ], "th": [ - "^\\d{8,13}$", + "^\\d{8,10}$", "^(?:001800|[2-57]|[689]\\d)\\d{7}|1\\d{7,9}$" ], "tj": [ @@ -836,7 +836,7 @@ "^(?:0800|(?:[5-8]\\d\\d|999)\\d)\\d{3}|[2-8]\\d{4}$" ], "tr": [ - "^\\d{7,13}$", + "^\\d{7,10}$", "^4\\d{6}|8\\d{11,12}|(?:[2-58]\\d\\d|900)\\d{7}$" ], "tt": [ @@ -868,7 +868,7 @@ "^[2-9]\\d{9}|3\\d{6}$" ], "uy": [ - "^\\d{6,13}$", + "^\\d{7,8}$", "^0004\\d{2,9}|[1249]\\d{7}|(?:[49]\\d|80)\\d{5}$" ], "uz": [ @@ -904,7 +904,7 @@ "^[57-9]\\d{6}|(?:[238]\\d|48)\\d{3}$" ], "wf": [ - "^\\d{6,9}$", + "^\\d{6}$", "^(?:40|72)\\d{4}|8\\d{5}(?:\\d{3})?$" ], "ws": [ diff --git a/development/src/phone-hooks/styles.ts b/development/src/phone-hooks/styles.ts index 1921545..08f67e0 100644 --- a/development/src/phone-hooks/styles.ts +++ b/development/src/phone-hooks/styles.ts @@ -11,14 +11,17 @@ export const jsonToCss = (stylesheet: object) => { export const injectStyles = (cssText: string) => { /** Inject the given `cssText` in the document head */ - const style = document.createElement("style"); - style.setAttribute("type", "text/css"); + try { + const style = document.createElement("style"); + style.setAttribute("type", "text/css"); - if ((style as any).styleSheet) { - (style as any).styleSheet.cssText = cssText; - } else { - style.appendChild(document.createTextNode(cssText)); - } + if ((style as any).styleSheet) { + (style as any).styleSheet.cssText = cssText; + } else { + style.appendChild(document.createTextNode(cssText)); + } - document.head.appendChild(style); + document.head.appendChild(style); + } catch (err) { + } } diff --git a/development/tsconfig.json b/development/tsconfig.json index aaedb1f..75771ab 100644 --- a/development/tsconfig.json +++ b/development/tsconfig.json @@ -1,26 +1,20 @@ { "compilerOptions": { - "alwaysStrict": true, - "noFallthroughCasesInSwitch": true, "noImplicitAny": true, - "noImplicitOverride": true, - "noImplicitReturns": false, - "noImplicitThis": true, "noUnusedLocals": true, "noUnusedParameters": true, - "strict": true, - "strictBindCallApply": true, - "strictFunctionTypes": true, + "noImplicitUseStrict": true, "strictNullChecks": true, "strictPropertyInitialization": true, "module": "esnext", "moduleResolution": "node", + "ignoreDeprecations": "5.0", "resolveJsonModule": true, "outDir": "dist", - "allowSyntheticDefaultImports": true, "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "isolatedModules": true, + "skipLibCheck": true, + "stripInternal": true, + "experimentalDecorators": true, "jsx": "react-jsx", "lib": [ "esnext", From f51c1612ed9d8bafd00a5e50abe015025f9a973c Mon Sep 17 00:00:00 2001 From: Artyom Vancyan Date: Mon, 7 Oct 2024 12:43:15 +0400 Subject: [PATCH 2/5] Add default select option --- development/src/ant-phone/index.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/development/src/ant-phone/index.tsx b/development/src/ant-phone/index.tsx index 8e28878..d1934cc 100644 --- a/development/src/ant-phone/index.tsx +++ b/development/src/ant-phone/index.tsx @@ -222,6 +222,16 @@ const PhoneInput = forwardRef(({
)} > + +
+ {suffixIcon} + } + /> {countriesList.map(([iso, name, dial, pattern]) => { const mask = disableParentheses ? pattern.replace(/[()]/g, "") : pattern; return ( From 645a85c8c6c9352a8db072aef69383b25544fb63 Mon Sep 17 00:00:00 2001 From: Artyom Vancyan Date: Mon, 7 Oct 2024 12:44:40 +0400 Subject: [PATCH 3/5] Optimize suffix icon calculation --- development/src/ant-phone/index.tsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/development/src/ant-phone/index.tsx b/development/src/ant-phone/index.tsx index d1934cc..2f1af2d 100644 --- a/development/src/ant-phone/index.tsx +++ b/development/src/ant-phone/index.tsx @@ -183,6 +183,18 @@ const PhoneInput = forwardRef(({ setValue(formattedNumber); }, [countriesList, metadata, onMount, pattern, setValue, value]) + const suffixIcon = useMemo(() => { + return enableArrow && ( + + + + + + ); + }, [enableArrow]) + const countriesSelect = useMemo(() => ( - ), [selectValue, query, enableArrow, disabled, disableParentheses, disableDropdown, onDropdownVisibleChange, minWidth, searchNotFound, countries, countriesList, setFieldValue, setValue, prefixCls, enableSearch, searchPlaceholder]) + ), [selectValue, suffixIcon, countryCode, query, disabled, disableParentheses, disableDropdown, onDropdownVisibleChange, minWidth, searchNotFound, countries, countriesList, setFieldValue, setValue, prefixCls, enableSearch, searchPlaceholder]) return (
Date: Mon, 7 Oct 2024 12:45:29 +0400 Subject: [PATCH 4/5] Reset query on change --- development/src/ant-phone/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/development/src/ant-phone/index.tsx b/development/src/ant-phone/index.tsx index 2f1af2d..062634e 100644 --- a/development/src/ant-phone/index.tsx +++ b/development/src/ant-phone/index.tsx @@ -133,6 +133,7 @@ const PhoneInput = forwardRef(({ const phoneMetadata = parsePhoneNumber(formattedNumber, countriesList); setCountryCode(phoneMetadata.isoCode as any); setValue(formattedNumber); + setQuery(""); handleChange({...phoneMetadata, valid: (strict: boolean) => checkValidity(phoneMetadata, strict)}, event); }, [countriesList, handleChange, pattern, setValue]) From fc134ef538b9be9430c520ff1e638c35c00e2c0e Mon Sep 17 00:00:00 2001 From: Artyom Vancyan Date: Mon, 7 Oct 2024 14:11:30 +0400 Subject: [PATCH 5/5] Replace `notFoundContent` property usage --- development/src/ant-phone/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/development/src/ant-phone/index.tsx b/development/src/ant-phone/index.tsx index 062634e..1baa12c 100644 --- a/development/src/ant-phone/index.tsx +++ b/development/src/ant-phone/index.tsx @@ -219,7 +219,6 @@ const PhoneInput = forwardRef(({ }} optionLabelProp="label" dropdownStyle={{minWidth}} - notFoundContent={searchNotFound} onDropdownVisibleChange={onDropdownVisibleChange} dropdownRender={(menu) => (
@@ -231,7 +230,9 @@ const PhoneInput = forwardRef(({ onInput={({target}: any) => setQuery(target.value)} /> )} - {menu} + {countriesList.length ? menu : ( +
{searchNotFound}
+ )}
)} >