@xsolla/xui-input-phone 0.153.2 → 0.154.0
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/native/index.d.mts +10 -2
- package/native/index.d.ts +10 -2
- package/native/index.js +28 -6
- package/native/index.js.map +1 -1
- package/native/index.mjs +22 -1
- package/native/index.mjs.map +1 -1
- package/package.json +3 -3
- package/web/index.d.mts +10 -2
- package/web/index.d.ts +10 -2
- package/web/index.js +28 -6
- package/web/index.js.map +1 -1
- package/web/index.mjs +22 -1
- package/web/index.mjs.map +1 -1
package/native/index.d.mts
CHANGED
|
@@ -114,6 +114,8 @@ interface UsePhoneNumberReturn {
|
|
|
114
114
|
country: Country | undefined;
|
|
115
115
|
/** All available countries */
|
|
116
116
|
countries: Country[];
|
|
117
|
+
/** Country-specific placeholder mask */
|
|
118
|
+
placeholder: string | undefined;
|
|
117
119
|
/** Handle phone number input change */
|
|
118
120
|
handlePhoneChange: (value: string) => void;
|
|
119
121
|
/** Handle country selection change */
|
|
@@ -122,11 +124,13 @@ interface UsePhoneNumberReturn {
|
|
|
122
124
|
setPhoneNumber: (value: string) => void;
|
|
123
125
|
}
|
|
124
126
|
/**
|
|
125
|
-
* Hook for managing phone number input with formatting
|
|
127
|
+
* Hook for managing phone number input with formatting, country detection
|
|
128
|
+
* and a country-specific placeholder.
|
|
126
129
|
*
|
|
127
130
|
* @example
|
|
128
131
|
* ```tsx
|
|
129
132
|
* const {
|
|
133
|
+
* placeholder,
|
|
130
134
|
* phoneNumber,
|
|
131
135
|
* formattedPhoneNumber,
|
|
132
136
|
* country,
|
|
@@ -158,9 +162,13 @@ declare const getCountryByCode: (code: string) => Country | undefined;
|
|
|
158
162
|
* Get a country by its dial code
|
|
159
163
|
*/
|
|
160
164
|
declare const getCountryByDialCode: (dialCode: string) => Country | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Get a placeholder by country
|
|
167
|
+
*/
|
|
168
|
+
declare function getPlaceholderByCode(code?: string): string | undefined;
|
|
161
169
|
/**
|
|
162
170
|
* Default countries (commonly used)
|
|
163
171
|
*/
|
|
164
172
|
declare const defaultCountries: Country[];
|
|
165
173
|
|
|
166
|
-
export { type Country, InputPhone, type InputPhoneProps, type UsePhoneNumberOptions, type UsePhoneNumberReturn, allCountries, defaultCountries, getCountryByCode, getCountryByDialCode, getFlag, usePhoneNumber };
|
|
174
|
+
export { type Country, InputPhone, type InputPhoneProps, type UsePhoneNumberOptions, type UsePhoneNumberReturn, allCountries, defaultCountries, getCountryByCode, getCountryByDialCode, getFlag, getPlaceholderByCode, usePhoneNumber };
|
package/native/index.d.ts
CHANGED
|
@@ -114,6 +114,8 @@ interface UsePhoneNumberReturn {
|
|
|
114
114
|
country: Country | undefined;
|
|
115
115
|
/** All available countries */
|
|
116
116
|
countries: Country[];
|
|
117
|
+
/** Country-specific placeholder mask */
|
|
118
|
+
placeholder: string | undefined;
|
|
117
119
|
/** Handle phone number input change */
|
|
118
120
|
handlePhoneChange: (value: string) => void;
|
|
119
121
|
/** Handle country selection change */
|
|
@@ -122,11 +124,13 @@ interface UsePhoneNumberReturn {
|
|
|
122
124
|
setPhoneNumber: (value: string) => void;
|
|
123
125
|
}
|
|
124
126
|
/**
|
|
125
|
-
* Hook for managing phone number input with formatting
|
|
127
|
+
* Hook for managing phone number input with formatting, country detection
|
|
128
|
+
* and a country-specific placeholder.
|
|
126
129
|
*
|
|
127
130
|
* @example
|
|
128
131
|
* ```tsx
|
|
129
132
|
* const {
|
|
133
|
+
* placeholder,
|
|
130
134
|
* phoneNumber,
|
|
131
135
|
* formattedPhoneNumber,
|
|
132
136
|
* country,
|
|
@@ -158,9 +162,13 @@ declare const getCountryByCode: (code: string) => Country | undefined;
|
|
|
158
162
|
* Get a country by its dial code
|
|
159
163
|
*/
|
|
160
164
|
declare const getCountryByDialCode: (dialCode: string) => Country | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Get a placeholder by country
|
|
167
|
+
*/
|
|
168
|
+
declare function getPlaceholderByCode(code?: string): string | undefined;
|
|
161
169
|
/**
|
|
162
170
|
* Default countries (commonly used)
|
|
163
171
|
*/
|
|
164
172
|
declare const defaultCountries: Country[];
|
|
165
173
|
|
|
166
|
-
export { type Country, InputPhone, type InputPhoneProps, type UsePhoneNumberOptions, type UsePhoneNumberReturn, allCountries, defaultCountries, getCountryByCode, getCountryByDialCode, getFlag, usePhoneNumber };
|
|
174
|
+
export { type Country, InputPhone, type InputPhoneProps, type UsePhoneNumberOptions, type UsePhoneNumberReturn, allCountries, defaultCountries, getCountryByCode, getCountryByDialCode, getFlag, getPlaceholderByCode, usePhoneNumber };
|
package/native/index.js
CHANGED
|
@@ -36,6 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
getCountryByCode: () => getCountryByCode,
|
|
37
37
|
getCountryByDialCode: () => getCountryByDialCode,
|
|
38
38
|
getFlag: () => getFlag,
|
|
39
|
+
getPlaceholderByCode: () => getPlaceholderByCode,
|
|
39
40
|
usePhoneNumber: () => usePhoneNumber
|
|
40
41
|
});
|
|
41
42
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1777,6 +1778,8 @@ var svgContent246 = `<svg viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.o
|
|
|
1777
1778
|
var FlagZW = (props) => /* @__PURE__ */ (0, import_jsx_runtime256.jsx)(FlagIcon, { ...props, svgContent: svgContent246 });
|
|
1778
1779
|
|
|
1779
1780
|
// src/countries.tsx
|
|
1781
|
+
var import_libphonenumber_js = require("libphonenumber-js");
|
|
1782
|
+
var import_examples_mobile = __toESM(require("libphonenumber-js/examples.mobile.json"));
|
|
1780
1783
|
var import_jsx_runtime257 = require("react/jsx-runtime");
|
|
1781
1784
|
var flagMap = {
|
|
1782
1785
|
AD: FlagAD,
|
|
@@ -2293,6 +2296,19 @@ var getCountryByDialCode = (dialCode) => {
|
|
|
2293
2296
|
(country) => country.dialCode === normalizedDialCode
|
|
2294
2297
|
);
|
|
2295
2298
|
};
|
|
2299
|
+
function getPlaceholderByCode(code) {
|
|
2300
|
+
if (!code) return void 0;
|
|
2301
|
+
try {
|
|
2302
|
+
const example = (0, import_libphonenumber_js.getExampleNumber)(
|
|
2303
|
+
code.toUpperCase(),
|
|
2304
|
+
import_examples_mobile.default
|
|
2305
|
+
);
|
|
2306
|
+
if (!example) return void 0;
|
|
2307
|
+
return "+" + example.countryCallingCode + example.formatInternational().slice(example.countryCallingCode.length + 1).replace(/\d/g, "0");
|
|
2308
|
+
} catch {
|
|
2309
|
+
return void 0;
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2296
2312
|
var defaultCountries = [
|
|
2297
2313
|
getCountryByCode("US"),
|
|
2298
2314
|
getCountryByCode("GB"),
|
|
@@ -3033,10 +3049,10 @@ InputPhone.displayName = "InputPhone";
|
|
|
3033
3049
|
|
|
3034
3050
|
// src/usePhoneNumber.ts
|
|
3035
3051
|
var import_react4 = require("react");
|
|
3036
|
-
var
|
|
3052
|
+
var import_libphonenumber_js2 = require("libphonenumber-js");
|
|
3037
3053
|
var getNormalizedPhoneNumber = (phoneNumber) => {
|
|
3038
3054
|
if (!phoneNumber) return "";
|
|
3039
|
-
const asYouType = new
|
|
3055
|
+
const asYouType = new import_libphonenumber_js2.AsYouType();
|
|
3040
3056
|
asYouType.input(phoneNumber);
|
|
3041
3057
|
const parsed = asYouType.getNumber();
|
|
3042
3058
|
if (parsed?.number) {
|
|
@@ -3054,7 +3070,7 @@ var detectCountryFromPhone = (phoneNumber, currentCountryCode) => {
|
|
|
3054
3070
|
if (digitsOnly.length === 0) return currentCountryCode;
|
|
3055
3071
|
const normalizedPhone = phoneNumber.startsWith("+") ? phoneNumber : `+${digitsOnly}`;
|
|
3056
3072
|
try {
|
|
3057
|
-
const parsed = (0,
|
|
3073
|
+
const parsed = (0, import_libphonenumber_js2.parsePhoneNumber)(normalizedPhone, {
|
|
3058
3074
|
defaultCountry: currentCountryCode,
|
|
3059
3075
|
extract: false
|
|
3060
3076
|
});
|
|
@@ -3064,7 +3080,7 @@ var detectCountryFromPhone = (phoneNumber, currentCountryCode) => {
|
|
|
3064
3080
|
} catch {
|
|
3065
3081
|
}
|
|
3066
3082
|
try {
|
|
3067
|
-
const asYouType = new
|
|
3083
|
+
const asYouType = new import_libphonenumber_js2.AsYouType(currentCountryCode);
|
|
3068
3084
|
asYouType.input(normalizedPhone);
|
|
3069
3085
|
if (asYouType.country) {
|
|
3070
3086
|
return asYouType.country;
|
|
@@ -3073,7 +3089,7 @@ var detectCountryFromPhone = (phoneNumber, currentCountryCode) => {
|
|
|
3073
3089
|
}
|
|
3074
3090
|
if (currentCountryCode) {
|
|
3075
3091
|
try {
|
|
3076
|
-
const callingCode = (0,
|
|
3092
|
+
const callingCode = (0, import_libphonenumber_js2.getCountryCallingCode)(
|
|
3077
3093
|
currentCountryCode
|
|
3078
3094
|
);
|
|
3079
3095
|
if (digitsOnly.startsWith(callingCode)) {
|
|
@@ -3106,7 +3122,7 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3106
3122
|
const [country, setCountry] = (0, import_react4.useState)(
|
|
3107
3123
|
getInitialCountry
|
|
3108
3124
|
);
|
|
3109
|
-
const formattedPhoneNumber = phoneNumber ? (0,
|
|
3125
|
+
const formattedPhoneNumber = phoneNumber ? (0, import_libphonenumber_js2.formatIncompletePhoneNumber)(
|
|
3110
3126
|
phoneNumber,
|
|
3111
3127
|
country?.code
|
|
3112
3128
|
) : "";
|
|
@@ -3191,11 +3207,16 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3191
3207
|
}
|
|
3192
3208
|
}
|
|
3193
3209
|
}, [initialValue]);
|
|
3210
|
+
const placeholder = (0, import_react4.useMemo)(
|
|
3211
|
+
() => getPlaceholderByCode(country?.code),
|
|
3212
|
+
[country?.code]
|
|
3213
|
+
);
|
|
3194
3214
|
return {
|
|
3195
3215
|
phoneNumber,
|
|
3196
3216
|
formattedPhoneNumber,
|
|
3197
3217
|
country,
|
|
3198
3218
|
countries: allCountries,
|
|
3219
|
+
placeholder,
|
|
3199
3220
|
handlePhoneChange,
|
|
3200
3221
|
handleCountryChange,
|
|
3201
3222
|
setPhoneNumber
|
|
@@ -3209,6 +3230,7 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3209
3230
|
getCountryByCode,
|
|
3210
3231
|
getCountryByDialCode,
|
|
3211
3232
|
getFlag,
|
|
3233
|
+
getPlaceholderByCode,
|
|
3212
3234
|
usePhoneNumber
|
|
3213
3235
|
});
|
|
3214
3236
|
//# sourceMappingURL=index.js.map
|