@xsolla/xui-input-phone 0.133.0 → 0.135.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 +35 -144
- package/web/index.js.map +1 -1
- package/web/index.mjs +10 -119
- 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.135.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.135.0",
|
|
17
|
+
"@xsolla/xui-primitives-core": "0.135.0",
|
|
18
18
|
"libphonenumber-js": "^1.10.56"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
package/web/index.js
CHANGED
|
@@ -41,120 +41,13 @@ __export(index_exports, {
|
|
|
41
41
|
module.exports = __toCommonJS(index_exports);
|
|
42
42
|
|
|
43
43
|
// src/InputPhone.tsx
|
|
44
|
-
var
|
|
44
|
+
var import_react3 = __toESM(require("react"));
|
|
45
45
|
|
|
46
46
|
// ../primitives-web/src/Box.tsx
|
|
47
|
-
var import_react2 = __toESM(require("react"));
|
|
48
|
-
var import_styled_components = __toESM(require("styled-components"));
|
|
49
|
-
|
|
50
|
-
// ../primitives-web/src/filterDOMProps.ts
|
|
51
47
|
var import_react = __toESM(require("react"));
|
|
52
|
-
var
|
|
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
|
|
48
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
155
49
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
156
|
-
var
|
|
157
|
-
var StyledBox = (0, import_styled_components.default)(FilteredDiv)`
|
|
50
|
+
var StyledBox = import_styled_components.default.div`
|
|
158
51
|
display: flex;
|
|
159
52
|
box-sizing: border-box;
|
|
160
53
|
background-color: ${(props) => props.backgroundColor || "transparent"};
|
|
@@ -241,7 +134,7 @@ var StyledBox = (0, import_styled_components.default)(FilteredDiv)`
|
|
|
241
134
|
${(props) => props.pressStyle?.backgroundColor && `background-color: ${props.pressStyle.backgroundColor};`}
|
|
242
135
|
}
|
|
243
136
|
`;
|
|
244
|
-
var Box =
|
|
137
|
+
var Box = import_react.default.forwardRef(
|
|
245
138
|
({
|
|
246
139
|
children,
|
|
247
140
|
onPress,
|
|
@@ -293,7 +186,7 @@ var Box = import_react2.default.forwardRef(
|
|
|
293
186
|
StyledBox,
|
|
294
187
|
{
|
|
295
188
|
ref,
|
|
296
|
-
|
|
189
|
+
as,
|
|
297
190
|
id,
|
|
298
191
|
type: as === "button" ? type || "button" : void 0,
|
|
299
192
|
disabled: as === "button" ? disabled : void 0,
|
|
@@ -324,8 +217,7 @@ Box.displayName = "Box";
|
|
|
324
217
|
// ../primitives-web/src/Text.tsx
|
|
325
218
|
var import_styled_components2 = __toESM(require("styled-components"));
|
|
326
219
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
327
|
-
var
|
|
328
|
-
var StyledText = (0, import_styled_components2.default)(FilteredSpan)`
|
|
220
|
+
var StyledText = import_styled_components2.default.span`
|
|
329
221
|
color: ${(props) => props.color || "inherit"};
|
|
330
222
|
font-size: ${(props) => typeof props.fontSize === "number" ? `${props.fontSize}px` : props.fontSize || "inherit"};
|
|
331
223
|
font-weight: ${(props) => props.fontWeight || "normal"};
|
|
@@ -358,8 +250,7 @@ var Text = ({
|
|
|
358
250
|
// ../primitives-web/src/Icon.tsx
|
|
359
251
|
var import_styled_components3 = __toESM(require("styled-components"));
|
|
360
252
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
361
|
-
var
|
|
362
|
-
var StyledIcon = (0, import_styled_components3.default)(FilteredDiv2)`
|
|
253
|
+
var StyledIcon = import_styled_components3.default.div`
|
|
363
254
|
display: flex;
|
|
364
255
|
align-items: center;
|
|
365
256
|
justify-content: center;
|
|
@@ -379,7 +270,7 @@ var Icon = ({ children, ...props }) => {
|
|
|
379
270
|
};
|
|
380
271
|
|
|
381
272
|
// ../primitives-web/src/Input.tsx
|
|
382
|
-
var
|
|
273
|
+
var import_react2 = require("react");
|
|
383
274
|
var import_styled_components4 = __toESM(require("styled-components"));
|
|
384
275
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
385
276
|
var StyledInput = import_styled_components4.default.input`
|
|
@@ -413,7 +304,7 @@ var StyledInput = import_styled_components4.default.input`
|
|
|
413
304
|
-webkit-text-fill-color: ${(props) => props.color || "inherit"} !important;
|
|
414
305
|
}
|
|
415
306
|
`;
|
|
416
|
-
var InputPrimitive = (0,
|
|
307
|
+
var InputPrimitive = (0, import_react2.forwardRef)(
|
|
417
308
|
({
|
|
418
309
|
value,
|
|
419
310
|
placeholder,
|
|
@@ -2402,7 +2293,7 @@ var ChevronUp = () => /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(
|
|
|
2402
2293
|
)
|
|
2403
2294
|
}
|
|
2404
2295
|
);
|
|
2405
|
-
var InputPhone = (0,
|
|
2296
|
+
var InputPhone = (0, import_react3.forwardRef)(
|
|
2406
2297
|
({
|
|
2407
2298
|
value,
|
|
2408
2299
|
placeholder = "+1 (000) 000-0000",
|
|
@@ -2428,35 +2319,35 @@ var InputPhone = (0, import_react4.forwardRef)(
|
|
|
2428
2319
|
themeProductContext
|
|
2429
2320
|
}, ref) => {
|
|
2430
2321
|
const { theme } = (0, import_xui_core.useResolvedTheme)({ themeMode, themeProductContext });
|
|
2431
|
-
const [internalState, setInternalState] = (0,
|
|
2322
|
+
const [internalState, setInternalState] = (0, import_react3.useState)(
|
|
2432
2323
|
"default"
|
|
2433
2324
|
);
|
|
2434
|
-
const [passValue, setPassValue] = (0,
|
|
2435
|
-
const [isDropdownOpen, setIsDropdownOpen] = (0,
|
|
2436
|
-
const [highlightedIndex, setHighlightedIndex] = (0,
|
|
2437
|
-
const [searchQuery, setSearchQuery] = (0,
|
|
2438
|
-
const inputRef = (0,
|
|
2439
|
-
const dropdownRef = (0,
|
|
2440
|
-
const countryButtonRef = (0,
|
|
2441
|
-
const searchInputRef = (0,
|
|
2442
|
-
const selectedCountryRef = (0,
|
|
2443
|
-
const countryListRef = (0,
|
|
2325
|
+
const [passValue, setPassValue] = (0, import_react3.useState)(value ?? "");
|
|
2326
|
+
const [isDropdownOpen, setIsDropdownOpen] = (0, import_react3.useState)(false);
|
|
2327
|
+
const [highlightedIndex, setHighlightedIndex] = (0, import_react3.useState)(-1);
|
|
2328
|
+
const [searchQuery, setSearchQuery] = (0, import_react3.useState)("");
|
|
2329
|
+
const inputRef = (0, import_react3.useRef)(null);
|
|
2330
|
+
const dropdownRef = (0, import_react3.useRef)(null);
|
|
2331
|
+
const countryButtonRef = (0, import_react3.useRef)(null);
|
|
2332
|
+
const searchInputRef = (0, import_react3.useRef)(null);
|
|
2333
|
+
const selectedCountryRef = (0, import_react3.useRef)(null);
|
|
2334
|
+
const countryListRef = (0, import_react3.useRef)(null);
|
|
2444
2335
|
const rawId = (0, import_xui_core.useId)();
|
|
2445
2336
|
const safeId = rawId.replace(/:/g, "");
|
|
2446
2337
|
const inputId = providedId || `input-phone-${safeId}`;
|
|
2447
2338
|
const errorId = `${inputId}-error`;
|
|
2448
2339
|
const dropdownId = `${inputId}-dropdown`;
|
|
2449
|
-
|
|
2340
|
+
import_react3.default.useImperativeHandle(
|
|
2450
2341
|
ref,
|
|
2451
2342
|
() => inputRef.current,
|
|
2452
2343
|
[]
|
|
2453
2344
|
);
|
|
2454
|
-
(0,
|
|
2345
|
+
(0, import_react3.useEffect)(() => {
|
|
2455
2346
|
if (value !== void 0) {
|
|
2456
2347
|
setPassValue(value);
|
|
2457
2348
|
}
|
|
2458
2349
|
}, [value]);
|
|
2459
|
-
(0,
|
|
2350
|
+
(0, import_react3.useEffect)(() => {
|
|
2460
2351
|
if (isDropdownOpen && selectedCountryRef.current && countryListRef.current) {
|
|
2461
2352
|
const timeoutId = setTimeout(() => {
|
|
2462
2353
|
const selectedItem = selectedCountryRef.current;
|
|
@@ -2467,7 +2358,7 @@ var InputPhone = (0, import_react4.forwardRef)(
|
|
|
2467
2358
|
return () => clearTimeout(timeoutId);
|
|
2468
2359
|
}
|
|
2469
2360
|
}, [isDropdownOpen]);
|
|
2470
|
-
(0,
|
|
2361
|
+
(0, import_react3.useEffect)(() => {
|
|
2471
2362
|
if (!isDropdownOpen || !import_xui_core.isWeb) return;
|
|
2472
2363
|
const handleClickOutside = (event) => {
|
|
2473
2364
|
const target = event.target;
|
|
@@ -2598,7 +2489,7 @@ var InputPhone = (0, import_react4.forwardRef)(
|
|
|
2598
2489
|
break;
|
|
2599
2490
|
}
|
|
2600
2491
|
};
|
|
2601
|
-
(0,
|
|
2492
|
+
(0, import_react3.useEffect)(() => {
|
|
2602
2493
|
if (isDropdownOpen && highlightedIndex >= 0 && highlightedIndex < filteredCountries.length) {
|
|
2603
2494
|
const handleEnter = (e) => {
|
|
2604
2495
|
if (e.key === "Enter") {
|
|
@@ -2753,7 +2644,7 @@ var InputPhone = (0, import_react4.forwardRef)(
|
|
|
2753
2644
|
borderColor: inputColors.borderHover
|
|
2754
2645
|
} : void 0,
|
|
2755
2646
|
children: [
|
|
2756
|
-
selectedCountry?.flag ? /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(Box, { width: flagSize, height: flagSize, children:
|
|
2647
|
+
selectedCountry?.flag ? /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(Box, { width: flagSize, height: flagSize, children: import_react3.default.isValidElement(selectedCountry.flag) ? import_react3.default.cloneElement(
|
|
2757
2648
|
selectedCountry.flag,
|
|
2758
2649
|
{ size: flagSize }
|
|
2759
2650
|
) : selectedCountry.flag }) : /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(Location, { size: flagSize, variant: "line", color: iconColor }),
|
|
@@ -3014,7 +2905,7 @@ var InputPhone = (0, import_react4.forwardRef)(
|
|
|
3014
2905
|
backgroundColor: inputColors.bgHover
|
|
3015
2906
|
} : void 0,
|
|
3016
2907
|
children: [
|
|
3017
|
-
country.flag ? /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(Box, { width: flagSize, height: flagSize, children:
|
|
2908
|
+
country.flag ? /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(Box, { width: flagSize, height: flagSize, children: import_react3.default.isValidElement(country.flag) ? import_react3.default.cloneElement(
|
|
3018
2909
|
country.flag,
|
|
3019
2910
|
{ size: flagSize }
|
|
3020
2911
|
) : country.flag }) : /* @__PURE__ */ (0, import_jsx_runtime258.jsx)(
|
|
@@ -3081,7 +2972,7 @@ var InputPhone = (0, import_react4.forwardRef)(
|
|
|
3081
2972
|
InputPhone.displayName = "InputPhone";
|
|
3082
2973
|
|
|
3083
2974
|
// src/usePhoneNumber.ts
|
|
3084
|
-
var
|
|
2975
|
+
var import_react4 = require("react");
|
|
3085
2976
|
var import_libphonenumber_js = require("libphonenumber-js");
|
|
3086
2977
|
var getNormalizedPhoneNumber = (phoneNumber) => {
|
|
3087
2978
|
if (!phoneNumber) return "";
|
|
@@ -3146,20 +3037,20 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3146
3037
|
}
|
|
3147
3038
|
return void 0;
|
|
3148
3039
|
};
|
|
3149
|
-
const [phoneNumber, setPhoneNumberState] = (0,
|
|
3040
|
+
const [phoneNumber, setPhoneNumberState] = (0, import_react4.useState)(() => {
|
|
3150
3041
|
if (initialValue) {
|
|
3151
3042
|
return getNormalizedPhoneNumber(initialValue);
|
|
3152
3043
|
}
|
|
3153
3044
|
return "";
|
|
3154
3045
|
});
|
|
3155
|
-
const [country, setCountry] = (0,
|
|
3046
|
+
const [country, setCountry] = (0, import_react4.useState)(
|
|
3156
3047
|
getInitialCountry
|
|
3157
3048
|
);
|
|
3158
3049
|
const formattedPhoneNumber = phoneNumber ? (0, import_libphonenumber_js.formatIncompletePhoneNumber)(
|
|
3159
3050
|
phoneNumber,
|
|
3160
3051
|
country?.code
|
|
3161
3052
|
) : "";
|
|
3162
|
-
const handlePhoneChange = (0,
|
|
3053
|
+
const handlePhoneChange = (0, import_react4.useCallback)(
|
|
3163
3054
|
(value) => {
|
|
3164
3055
|
let normalizedValue = value;
|
|
3165
3056
|
const digitsOnly = value.replace(/\D/g, "");
|
|
@@ -3186,7 +3077,7 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3186
3077
|
},
|
|
3187
3078
|
[country?.code, onChange, onCountryChange]
|
|
3188
3079
|
);
|
|
3189
|
-
const handleCountryChange = (0,
|
|
3080
|
+
const handleCountryChange = (0, import_react4.useCallback)(
|
|
3190
3081
|
(newCountry) => {
|
|
3191
3082
|
const previousCountry = country;
|
|
3192
3083
|
setCountry(newCountry);
|
|
@@ -3211,7 +3102,7 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3211
3102
|
},
|
|
3212
3103
|
[country, phoneNumber, onChange, onCountryChange]
|
|
3213
3104
|
);
|
|
3214
|
-
const setPhoneNumber = (0,
|
|
3105
|
+
const setPhoneNumber = (0, import_react4.useCallback)(
|
|
3215
3106
|
(value) => {
|
|
3216
3107
|
const normalized = getNormalizedPhoneNumber(value);
|
|
3217
3108
|
setPhoneNumberState(normalized);
|
|
@@ -3227,7 +3118,7 @@ var usePhoneNumber = (options = {}) => {
|
|
|
3227
3118
|
},
|
|
3228
3119
|
[country?.code, onChange, onCountryChange]
|
|
3229
3120
|
);
|
|
3230
|
-
(0,
|
|
3121
|
+
(0, import_react4.useEffect)(() => {
|
|
3231
3122
|
if (initialValue && initialValue !== phoneNumber) {
|
|
3232
3123
|
const normalized = getNormalizedPhoneNumber(initialValue);
|
|
3233
3124
|
setPhoneNumberState(normalized);
|