@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsolla/xui-input-phone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.154.0",
|
|
4
4
|
"main": "./web/index.js",
|
|
5
5
|
"module": "./web/index.mjs",
|
|
6
6
|
"types": "./web/index.d.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"test:coverage": "vitest run --coverage"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@xsolla/xui-core": "0.
|
|
17
|
-
"@xsolla/xui-primitives-core": "0.
|
|
16
|
+
"@xsolla/xui-core": "0.154.0",
|
|
17
|
+
"@xsolla/xui-primitives-core": "0.154.0",
|
|
18
18
|
"libphonenumber-js": "^1.10.56"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
package/web/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/web/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/web/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);
|
|
@@ -1804,6 +1805,8 @@ var svgContent246 = `<svg viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.o
|
|
|
1804
1805
|
var FlagZW = (props) => /* @__PURE__ */ (0, import_jsx_runtime256.jsx)(FlagIcon, { ...props, svgContent: svgContent246 });
|
|
1805
1806
|
|
|
1806
1807
|
// src/countries.tsx
|
|
1808
|
+
var import_libphonenumber_js = require("libphonenumber-js");
|
|
1809
|
+
var import_examples_mobile = __toESM(require("libphonenumber-js/examples.mobile.json"));
|
|
1807
1810
|
var import_jsx_runtime257 = require("react/jsx-runtime");
|
|
1808
1811
|
var flagMap = {
|
|
1809
1812
|
AD: FlagAD,
|
|
@@ -2320,6 +2323,19 @@ var getCountryByDialCode = (dialCode) => {
|
|
|
2320
2323
|
(country) => country.dialCode === normalizedDialCode
|
|
2321
2324
|
);
|
|
2322
2325
|
};
|
|
2326
|
+
function getPlaceholderByCode(code) {
|
|
2327
|
+
if (!code) return void 0;
|
|
2328
|
+
try {
|
|
2329
|
+
const example = (0, import_libphonenumber_js.getExampleNumber)(
|
|
2330
|
+
code.toUpperCase(),
|
|
2331
|
+
import_examples_mobile.default
|
|
2332
|
+
);
|
|
2333
|
+
if (!example) return void 0;
|
|
2334
|
+
return "+" + example.countryCallingCode + example.formatInternational().slice(example.countryCallingCode.length + 1).replace(/\d/g, "0");
|
|
2335
|
+
} catch {
|
|
2336
|
+
return void 0;
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2323
2339
|
var defaultCountries = [
|
|
2324
2340
|
getCountryByCode("US"),
|
|
2325
2341
|
getCountryByCode("GB"),
|
|
@@ -3060,10 +3076,10 @@ InputPhone.displayName = "InputPhone";
|
|
|
3060
3076
|
|
|
3061
3077
|
// src/usePhoneNumber.ts
|
|
3062
3078
|
var import_react5 = require("react");
|
|
3063
|
-
var
|
|
3079
|
+
var import_libphonenumber_js2 = require("libphonenumber-js");
|
|
3064
3080
|
var getNormalizedPhoneNumber = (phoneNumber) => {
|
|
3065
3081
|
if (!phoneNumber) return "";
|
|
3066
|
-
const asYouType = new
|
|
3082
|
+
const asYouType = new import_libphonenumber_js2.AsYouType();
|
|
3067
3083
|
asYouType.input(phoneNumber);
|
|
3068
3084
|
const parsed = asYouType.getNumber();
|
|
3069
3085
|
if (parsed?.number) {
|
|
@@ -3081,7 +3097,7 @@ var detectCountryFromPhone = (phoneNumber, currentCountryCode) => {
|
|
|
3081
3097
|
if (digitsOnly.length === 0) return currentCountryCode;
|
|
3082
3098
|
const normalizedPhone = phoneNumber.startsWith("+") ? phoneNumber : `+${digitsOnly}`;
|
|
3083
3099
|
try {
|
|
3084
|
-
const parsed = (0,
|
|
3100
|
+
const parsed = (0, import_libphonenumber_js2.parsePhoneNumber)(normalizedPhone, {
|
|
3085
3101
|
defaultCountry: currentCountryCode,
|
|
3086
3102
|
extract: false
|
|
3087
3103
|
});
|
|
@@ -3091,7 +3107,7 @@ var detectCountryFromPhone = (phoneNumber, currentCountryCode) => {
|
|
|
3091
3107
|
} catch {
|
|
3092
3108
|
}
|
|
3093
3109
|
try {
|
|
3094
|
-
const asYouType = new
|
|
3110
|
+
const asYouType = new import_libphonenumber_js2.AsYouType(currentCountryCode);
|
|
3095
3111
|
asYouType.input(normalizedPhone);
|
|
3096
3112
|
if (asYouType.country) {
|
|
3097
3113
|
return asYouType.country;
|
|
@@ -3100,7 +3116,7 @@ var detectCountryFromPhone = (phoneNumber, currentCountryCode) => {
|
|
|
3100
3116
|
}
|
|
3101
3117
|
if (currentCountryCode) {
|
|
3102
3118
|
try {
|
|
3103
|
-
const callingCode = (0,
|
|
3119
|
+
const callingCode = (0, import_libphonenumber_js2.getCountryCallingCode)(
|
|
3104
3120
|
currentCountryCode
|
|
3105
3121
|
);
|
|
3106
3122
|
if (digitsOnly.startsWith(callingCode)) {
|
|
@@ -3133,7 +3149,7 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3133
3149
|
const [country, setCountry] = (0, import_react5.useState)(
|
|
3134
3150
|
getInitialCountry
|
|
3135
3151
|
);
|
|
3136
|
-
const formattedPhoneNumber = phoneNumber ? (0,
|
|
3152
|
+
const formattedPhoneNumber = phoneNumber ? (0, import_libphonenumber_js2.formatIncompletePhoneNumber)(
|
|
3137
3153
|
phoneNumber,
|
|
3138
3154
|
country?.code
|
|
3139
3155
|
) : "";
|
|
@@ -3218,11 +3234,16 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3218
3234
|
}
|
|
3219
3235
|
}
|
|
3220
3236
|
}, [initialValue]);
|
|
3237
|
+
const placeholder = (0, import_react5.useMemo)(
|
|
3238
|
+
() => getPlaceholderByCode(country?.code),
|
|
3239
|
+
[country?.code]
|
|
3240
|
+
);
|
|
3221
3241
|
return {
|
|
3222
3242
|
phoneNumber,
|
|
3223
3243
|
formattedPhoneNumber,
|
|
3224
3244
|
country,
|
|
3225
3245
|
countries: allCountries,
|
|
3246
|
+
placeholder,
|
|
3226
3247
|
handlePhoneChange,
|
|
3227
3248
|
handleCountryChange,
|
|
3228
3249
|
setPhoneNumber
|
|
@@ -3236,6 +3257,7 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3236
3257
|
getCountryByCode,
|
|
3237
3258
|
getCountryByDialCode,
|
|
3238
3259
|
getFlag,
|
|
3260
|
+
getPlaceholderByCode,
|
|
3239
3261
|
usePhoneNumber
|
|
3240
3262
|
});
|
|
3241
3263
|
//# sourceMappingURL=index.js.map
|