@xsolla/xui-input-phone 0.131.0 → 0.133.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/package.json +3 -3
- package/web/index.js +144 -35
- package/web/index.js.map +1 -1
- package/web/index.mjs +119 -10
- 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.133.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.133.0",
|
|
17
|
+
"@xsolla/xui-primitives-core": "0.133.0",
|
|
18
18
|
"libphonenumber-js": "^1.10.56"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
package/web/index.js
CHANGED
|
@@ -41,13 +41,120 @@ __export(index_exports, {
|
|
|
41
41
|
module.exports = __toCommonJS(index_exports);
|
|
42
42
|
|
|
43
43
|
// src/InputPhone.tsx
|
|
44
|
-
var
|
|
44
|
+
var import_react4 = __toESM(require("react"));
|
|
45
45
|
|
|
46
46
|
// ../primitives-web/src/Box.tsx
|
|
47
|
-
var
|
|
47
|
+
var import_react2 = __toESM(require("react"));
|
|
48
48
|
var import_styled_components = __toESM(require("styled-components"));
|
|
49
|
+
|
|
50
|
+
// ../primitives-web/src/filterDOMProps.ts
|
|
51
|
+
var import_react = __toESM(require("react"));
|
|
52
|
+
var NON_HTML_PROPS = /* @__PURE__ */ new Set([
|
|
53
|
+
// BoxProps — layout & styling
|
|
54
|
+
"backgroundColor",
|
|
55
|
+
"borderColor",
|
|
56
|
+
"borderWidth",
|
|
57
|
+
"borderBottomWidth",
|
|
58
|
+
"borderBottomColor",
|
|
59
|
+
"borderTopWidth",
|
|
60
|
+
"borderTopColor",
|
|
61
|
+
"borderLeftWidth",
|
|
62
|
+
"borderLeftColor",
|
|
63
|
+
"borderRightWidth",
|
|
64
|
+
"borderRightColor",
|
|
65
|
+
"borderRadius",
|
|
66
|
+
"borderStyle",
|
|
67
|
+
"flexDirection",
|
|
68
|
+
"flexWrap",
|
|
69
|
+
"alignItems",
|
|
70
|
+
"justifyContent",
|
|
71
|
+
"alignSelf",
|
|
72
|
+
"flex",
|
|
73
|
+
"flexShrink",
|
|
74
|
+
"gap",
|
|
75
|
+
"position",
|
|
76
|
+
"top",
|
|
77
|
+
"bottom",
|
|
78
|
+
"left",
|
|
79
|
+
"right",
|
|
80
|
+
"outline",
|
|
81
|
+
"overflow",
|
|
82
|
+
"overflowX",
|
|
83
|
+
"overflowY",
|
|
84
|
+
"zIndex",
|
|
85
|
+
"cursor",
|
|
86
|
+
"padding",
|
|
87
|
+
"paddingHorizontal",
|
|
88
|
+
"paddingVertical",
|
|
89
|
+
"paddingTop",
|
|
90
|
+
"paddingBottom",
|
|
91
|
+
"paddingLeft",
|
|
92
|
+
"paddingRight",
|
|
93
|
+
"margin",
|
|
94
|
+
"marginTop",
|
|
95
|
+
"marginBottom",
|
|
96
|
+
"marginLeft",
|
|
97
|
+
"marginRight",
|
|
98
|
+
"minWidth",
|
|
99
|
+
"minHeight",
|
|
100
|
+
"maxWidth",
|
|
101
|
+
"maxHeight",
|
|
102
|
+
"hoverStyle",
|
|
103
|
+
"pressStyle",
|
|
104
|
+
"focusStyle",
|
|
105
|
+
"outlineColor",
|
|
106
|
+
"outlineWidth",
|
|
107
|
+
"outlineOffset",
|
|
108
|
+
"outlineStyle",
|
|
109
|
+
// BoxProps — RN-only
|
|
110
|
+
"onPress",
|
|
111
|
+
"onLayout",
|
|
112
|
+
"onMoveShouldSetResponder",
|
|
113
|
+
"onResponderGrant",
|
|
114
|
+
"onResponderMove",
|
|
115
|
+
"onResponderRelease",
|
|
116
|
+
"onResponderTerminate",
|
|
117
|
+
"testID",
|
|
118
|
+
// Box — custom element type
|
|
119
|
+
"elementType",
|
|
120
|
+
// TextProps
|
|
121
|
+
"fontSize",
|
|
122
|
+
"fontWeight",
|
|
123
|
+
"fontFamily",
|
|
124
|
+
"lineHeight",
|
|
125
|
+
"whiteSpace",
|
|
126
|
+
"textAlign",
|
|
127
|
+
"textDecoration",
|
|
128
|
+
"numberOfLines",
|
|
129
|
+
"letterSpacing",
|
|
130
|
+
"textTransform",
|
|
131
|
+
// SpinnerProps
|
|
132
|
+
"strokeWidth",
|
|
133
|
+
// DividerProps
|
|
134
|
+
"vertical",
|
|
135
|
+
"dashStroke"
|
|
136
|
+
]);
|
|
137
|
+
function createFilteredElement(defaultTag) {
|
|
138
|
+
const Component = import_react.default.forwardRef(
|
|
139
|
+
({ children, elementType, ...props }, ref) => {
|
|
140
|
+
const Tag = elementType || defaultTag;
|
|
141
|
+
const htmlProps = {};
|
|
142
|
+
for (const key of Object.keys(props)) {
|
|
143
|
+
if (!NON_HTML_PROPS.has(key)) {
|
|
144
|
+
htmlProps[key] = props[key];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return import_react.default.createElement(Tag, { ref, ...htmlProps }, children);
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
Component.displayName = `Filtered(${defaultTag})`;
|
|
151
|
+
return Component;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ../primitives-web/src/Box.tsx
|
|
49
155
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
50
|
-
var
|
|
156
|
+
var FilteredDiv = createFilteredElement("div");
|
|
157
|
+
var StyledBox = (0, import_styled_components.default)(FilteredDiv)`
|
|
51
158
|
display: flex;
|
|
52
159
|
box-sizing: border-box;
|
|
53
160
|
background-color: ${(props) => props.backgroundColor || "transparent"};
|
|
@@ -134,7 +241,7 @@ var StyledBox = import_styled_components.default.div`
|
|
|
134
241
|
${(props) => props.pressStyle?.backgroundColor && `background-color: ${props.pressStyle.backgroundColor};`}
|
|
135
242
|
}
|
|
136
243
|
`;
|
|
137
|
-
var Box =
|
|
244
|
+
var Box = import_react2.default.forwardRef(
|
|
138
245
|
({
|
|
139
246
|
children,
|
|
140
247
|
onPress,
|
|
@@ -186,7 +293,7 @@ var Box = import_react.default.forwardRef(
|
|
|
186
293
|
StyledBox,
|
|
187
294
|
{
|
|
188
295
|
ref,
|
|
189
|
-
as,
|
|
296
|
+
elementType: as,
|
|
190
297
|
id,
|
|
191
298
|
type: as === "button" ? type || "button" : void 0,
|
|
192
299
|
disabled: as === "button" ? disabled : void 0,
|
|
@@ -217,7 +324,8 @@ Box.displayName = "Box";
|
|
|
217
324
|
// ../primitives-web/src/Text.tsx
|
|
218
325
|
var import_styled_components2 = __toESM(require("styled-components"));
|
|
219
326
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
220
|
-
var
|
|
327
|
+
var FilteredSpan = createFilteredElement("span");
|
|
328
|
+
var StyledText = (0, import_styled_components2.default)(FilteredSpan)`
|
|
221
329
|
color: ${(props) => props.color || "inherit"};
|
|
222
330
|
font-size: ${(props) => typeof props.fontSize === "number" ? `${props.fontSize}px` : props.fontSize || "inherit"};
|
|
223
331
|
font-weight: ${(props) => props.fontWeight || "normal"};
|
|
@@ -250,7 +358,8 @@ var Text = ({
|
|
|
250
358
|
// ../primitives-web/src/Icon.tsx
|
|
251
359
|
var import_styled_components3 = __toESM(require("styled-components"));
|
|
252
360
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
253
|
-
var
|
|
361
|
+
var FilteredDiv2 = createFilteredElement("div");
|
|
362
|
+
var StyledIcon = (0, import_styled_components3.default)(FilteredDiv2)`
|
|
254
363
|
display: flex;
|
|
255
364
|
align-items: center;
|
|
256
365
|
justify-content: center;
|
|
@@ -270,7 +379,7 @@ var Icon = ({ children, ...props }) => {
|
|
|
270
379
|
};
|
|
271
380
|
|
|
272
381
|
// ../primitives-web/src/Input.tsx
|
|
273
|
-
var
|
|
382
|
+
var import_react3 = require("react");
|
|
274
383
|
var import_styled_components4 = __toESM(require("styled-components"));
|
|
275
384
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
276
385
|
var StyledInput = import_styled_components4.default.input`
|
|
@@ -304,7 +413,7 @@ var StyledInput = import_styled_components4.default.input`
|
|
|
304
413
|
-webkit-text-fill-color: ${(props) => props.color || "inherit"} !important;
|
|
305
414
|
}
|
|
306
415
|
`;
|
|
307
|
-
var InputPrimitive = (0,
|
|
416
|
+
var InputPrimitive = (0, import_react3.forwardRef)(
|
|
308
417
|
({
|
|
309
418
|
value,
|
|
310
419
|
placeholder,
|
|
@@ -2293,7 +2402,7 @@ var ChevronUp = () => /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(
|
|
|
2293
2402
|
)
|
|
2294
2403
|
}
|
|
2295
2404
|
);
|
|
2296
|
-
var InputPhone = (0,
|
|
2405
|
+
var InputPhone = (0, import_react4.forwardRef)(
|
|
2297
2406
|
({
|
|
2298
2407
|
value,
|
|
2299
2408
|
placeholder = "+1 (000) 000-0000",
|
|
@@ -2319,35 +2428,35 @@ var InputPhone = (0, import_react3.forwardRef)(
|
|
|
2319
2428
|
themeProductContext
|
|
2320
2429
|
}, ref) => {
|
|
2321
2430
|
const { theme } = (0, import_xui_core.useResolvedTheme)({ themeMode, themeProductContext });
|
|
2322
|
-
const [internalState, setInternalState] = (0,
|
|
2431
|
+
const [internalState, setInternalState] = (0, import_react4.useState)(
|
|
2323
2432
|
"default"
|
|
2324
2433
|
);
|
|
2325
|
-
const [passValue, setPassValue] = (0,
|
|
2326
|
-
const [isDropdownOpen, setIsDropdownOpen] = (0,
|
|
2327
|
-
const [highlightedIndex, setHighlightedIndex] = (0,
|
|
2328
|
-
const [searchQuery, setSearchQuery] = (0,
|
|
2329
|
-
const inputRef = (0,
|
|
2330
|
-
const dropdownRef = (0,
|
|
2331
|
-
const countryButtonRef = (0,
|
|
2332
|
-
const searchInputRef = (0,
|
|
2333
|
-
const selectedCountryRef = (0,
|
|
2334
|
-
const countryListRef = (0,
|
|
2434
|
+
const [passValue, setPassValue] = (0, import_react4.useState)(value ?? "");
|
|
2435
|
+
const [isDropdownOpen, setIsDropdownOpen] = (0, import_react4.useState)(false);
|
|
2436
|
+
const [highlightedIndex, setHighlightedIndex] = (0, import_react4.useState)(-1);
|
|
2437
|
+
const [searchQuery, setSearchQuery] = (0, import_react4.useState)("");
|
|
2438
|
+
const inputRef = (0, import_react4.useRef)(null);
|
|
2439
|
+
const dropdownRef = (0, import_react4.useRef)(null);
|
|
2440
|
+
const countryButtonRef = (0, import_react4.useRef)(null);
|
|
2441
|
+
const searchInputRef = (0, import_react4.useRef)(null);
|
|
2442
|
+
const selectedCountryRef = (0, import_react4.useRef)(null);
|
|
2443
|
+
const countryListRef = (0, import_react4.useRef)(null);
|
|
2335
2444
|
const rawId = (0, import_xui_core.useId)();
|
|
2336
2445
|
const safeId = rawId.replace(/:/g, "");
|
|
2337
2446
|
const inputId = providedId || `input-phone-${safeId}`;
|
|
2338
2447
|
const errorId = `${inputId}-error`;
|
|
2339
2448
|
const dropdownId = `${inputId}-dropdown`;
|
|
2340
|
-
|
|
2449
|
+
import_react4.default.useImperativeHandle(
|
|
2341
2450
|
ref,
|
|
2342
2451
|
() => inputRef.current,
|
|
2343
2452
|
[]
|
|
2344
2453
|
);
|
|
2345
|
-
(0,
|
|
2454
|
+
(0, import_react4.useEffect)(() => {
|
|
2346
2455
|
if (value !== void 0) {
|
|
2347
2456
|
setPassValue(value);
|
|
2348
2457
|
}
|
|
2349
2458
|
}, [value]);
|
|
2350
|
-
(0,
|
|
2459
|
+
(0, import_react4.useEffect)(() => {
|
|
2351
2460
|
if (isDropdownOpen && selectedCountryRef.current && countryListRef.current) {
|
|
2352
2461
|
const timeoutId = setTimeout(() => {
|
|
2353
2462
|
const selectedItem = selectedCountryRef.current;
|
|
@@ -2358,7 +2467,7 @@ var InputPhone = (0, import_react3.forwardRef)(
|
|
|
2358
2467
|
return () => clearTimeout(timeoutId);
|
|
2359
2468
|
}
|
|
2360
2469
|
}, [isDropdownOpen]);
|
|
2361
|
-
(0,
|
|
2470
|
+
(0, import_react4.useEffect)(() => {
|
|
2362
2471
|
if (!isDropdownOpen || !import_xui_core.isWeb) return;
|
|
2363
2472
|
const handleClickOutside = (event) => {
|
|
2364
2473
|
const target = event.target;
|
|
@@ -2489,7 +2598,7 @@ var InputPhone = (0, import_react3.forwardRef)(
|
|
|
2489
2598
|
break;
|
|
2490
2599
|
}
|
|
2491
2600
|
};
|
|
2492
|
-
(0,
|
|
2601
|
+
(0, import_react4.useEffect)(() => {
|
|
2493
2602
|
if (isDropdownOpen && highlightedIndex >= 0 && highlightedIndex < filteredCountries.length) {
|
|
2494
2603
|
const handleEnter = (e) => {
|
|
2495
2604
|
if (e.key === "Enter") {
|
|
@@ -2644,7 +2753,7 @@ var InputPhone = (0, import_react3.forwardRef)(
|
|
|
2644
2753
|
borderColor: inputColors.borderHover
|
|
2645
2754
|
} : void 0,
|
|
2646
2755
|
children: [
|
|
2647
|
-
selectedCountry?.flag ? /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(Box, { width: flagSize, height: flagSize, children:
|
|
2756
|
+
selectedCountry?.flag ? /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(Box, { width: flagSize, height: flagSize, children: import_react4.default.isValidElement(selectedCountry.flag) ? import_react4.default.cloneElement(
|
|
2648
2757
|
selectedCountry.flag,
|
|
2649
2758
|
{ size: flagSize }
|
|
2650
2759
|
) : selectedCountry.flag }) : /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(Location, { size: flagSize, variant: "line", color: iconColor }),
|
|
@@ -2905,7 +3014,7 @@ var InputPhone = (0, import_react3.forwardRef)(
|
|
|
2905
3014
|
backgroundColor: inputColors.bgHover
|
|
2906
3015
|
} : void 0,
|
|
2907
3016
|
children: [
|
|
2908
|
-
country.flag ? /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(Box, { width: flagSize, height: flagSize, children:
|
|
3017
|
+
country.flag ? /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(Box, { width: flagSize, height: flagSize, children: import_react4.default.isValidElement(country.flag) ? import_react4.default.cloneElement(
|
|
2909
3018
|
country.flag,
|
|
2910
3019
|
{ size: flagSize }
|
|
2911
3020
|
) : country.flag }) : /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(
|
|
@@ -2972,7 +3081,7 @@ var InputPhone = (0, import_react3.forwardRef)(
|
|
|
2972
3081
|
InputPhone.displayName = "InputPhone";
|
|
2973
3082
|
|
|
2974
3083
|
// src/usePhoneNumber.ts
|
|
2975
|
-
var
|
|
3084
|
+
var import_react5 = require("react");
|
|
2976
3085
|
var import_libphonenumber_js = require("libphonenumber-js");
|
|
2977
3086
|
var getNormalizedPhoneNumber = (phoneNumber) => {
|
|
2978
3087
|
if (!phoneNumber) return "";
|
|
@@ -3037,20 +3146,20 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3037
3146
|
}
|
|
3038
3147
|
return void 0;
|
|
3039
3148
|
};
|
|
3040
|
-
const [phoneNumber, setPhoneNumberState] = (0,
|
|
3149
|
+
const [phoneNumber, setPhoneNumberState] = (0, import_react5.useState)(() => {
|
|
3041
3150
|
if (initialValue) {
|
|
3042
3151
|
return getNormalizedPhoneNumber(initialValue);
|
|
3043
3152
|
}
|
|
3044
3153
|
return "";
|
|
3045
3154
|
});
|
|
3046
|
-
const [country, setCountry] = (0,
|
|
3155
|
+
const [country, setCountry] = (0, import_react5.useState)(
|
|
3047
3156
|
getInitialCountry
|
|
3048
3157
|
);
|
|
3049
3158
|
const formattedPhoneNumber = phoneNumber ? (0, import_libphonenumber_js.formatIncompletePhoneNumber)(
|
|
3050
3159
|
phoneNumber,
|
|
3051
3160
|
country?.code
|
|
3052
3161
|
) : "";
|
|
3053
|
-
const handlePhoneChange = (0,
|
|
3162
|
+
const handlePhoneChange = (0, import_react5.useCallback)(
|
|
3054
3163
|
(value) => {
|
|
3055
3164
|
let normalizedValue = value;
|
|
3056
3165
|
const digitsOnly = value.replace(/\D/g, "");
|
|
@@ -3077,7 +3186,7 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3077
3186
|
},
|
|
3078
3187
|
[country?.code, onChange, onCountryChange]
|
|
3079
3188
|
);
|
|
3080
|
-
const handleCountryChange = (0,
|
|
3189
|
+
const handleCountryChange = (0, import_react5.useCallback)(
|
|
3081
3190
|
(newCountry) => {
|
|
3082
3191
|
const previousCountry = country;
|
|
3083
3192
|
setCountry(newCountry);
|
|
@@ -3102,7 +3211,7 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3102
3211
|
},
|
|
3103
3212
|
[country, phoneNumber, onChange, onCountryChange]
|
|
3104
3213
|
);
|
|
3105
|
-
const setPhoneNumber = (0,
|
|
3214
|
+
const setPhoneNumber = (0, import_react5.useCallback)(
|
|
3106
3215
|
(value) => {
|
|
3107
3216
|
const normalized = getNormalizedPhoneNumber(value);
|
|
3108
3217
|
setPhoneNumberState(normalized);
|
|
@@ -3118,7 +3227,7 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3118
3227
|
},
|
|
3119
3228
|
[country?.code, onChange, onCountryChange]
|
|
3120
3229
|
);
|
|
3121
|
-
(0,
|
|
3230
|
+
(0, import_react5.useEffect)(() => {
|
|
3122
3231
|
if (initialValue && initialValue !== phoneNumber) {
|
|
3123
3232
|
const normalized = getNormalizedPhoneNumber(initialValue);
|
|
3124
3233
|
setPhoneNumberState(normalized);
|