@adam-milo/ui 1.0.33 → 1.0.34
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/dist/index.cjs +1 -1
- package/dist/index.js +57 -23
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +94 -56
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +199 -40
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +305 -105
- package/dist/index13.cjs +1 -1
- package/dist/index13.js +260 -74
- package/dist/index14.cjs +1 -1
- package/dist/index14.js +135 -27
- package/dist/index15.cjs +1 -1
- package/dist/index15.js +52 -469
- package/dist/index16.cjs +1 -1
- package/dist/index16.js +57 -111
- package/dist/index17.cjs +1 -1
- package/dist/index17.js +101 -20
- package/dist/index18.cjs +1 -1
- package/dist/index18.js +76 -21
- package/dist/index19.cjs +1 -1
- package/dist/index19.js +25 -29
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +6 -4
- package/dist/index20.cjs +1 -1
- package/dist/index20.js +468 -31
- package/dist/index21.cjs +1 -1
- package/dist/index21.js +155 -39
- package/dist/index22.cjs +1 -1
- package/dist/index22.js +16 -27
- package/dist/index23.cjs +1 -1
- package/dist/index23.js +36 -12
- package/dist/index24.cjs +1 -0
- package/dist/index24.js +46 -0
- package/dist/index25.cjs +1 -1
- package/dist/index25.js +80 -263
- package/dist/index26.cjs +1 -1
- package/dist/index26.js +52 -13
- package/dist/index27.cjs +1 -0
- package/dist/index27.js +45 -0
- package/dist/index28.cjs +1 -0
- package/dist/index28.js +53 -0
- package/dist/index29.cjs +1 -0
- package/dist/index29.js +55 -0
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +33 -33
- package/dist/index30.cjs +1 -0
- package/dist/index30.js +72 -0
- package/dist/index31.cjs +1 -0
- package/dist/index31.js +14 -0
- package/dist/index32.cjs +1 -0
- package/dist/index32.js +332 -0
- package/dist/index36.cjs +1 -1
- package/dist/index36.js +383 -6
- package/dist/index37.cjs +1 -0
- package/dist/index37.js +16 -0
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +59 -11
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +19 -35
- package/dist/index50.cjs +1 -0
- package/dist/index50.js +9 -0
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +11 -101
- package/dist/index62.cjs +1 -0
- package/dist/index62.js +502 -0
- package/dist/index64.cjs +1 -0
- package/dist/index64.js +11 -0
- package/dist/index65.cjs +1 -0
- package/dist/index65.js +39 -0
- package/dist/index66.cjs +1 -0
- package/dist/index66.js +64 -0
- package/dist/index67.cjs +1 -0
- package/dist/index67.js +212 -0
- package/dist/index68.cjs +1 -0
- package/dist/index68.js +14 -0
- package/dist/index69.cjs +1 -0
- package/dist/index69.js +293 -0
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +46 -97
- package/dist/index70.cjs +1 -0
- package/dist/index70.js +18 -0
- package/dist/index71.cjs +1 -0
- package/dist/index71.js +129 -0
- package/dist/index72.cjs +1 -0
- package/dist/index72.js +43 -0
- package/dist/index73.cjs +1 -0
- package/dist/index73.js +99 -0
- package/dist/index74.cjs +1 -0
- package/dist/index74.js +71 -0
- package/dist/index75.cjs +1 -0
- package/dist/index75.js +36 -0
- package/dist/index76.cjs +1 -0
- package/dist/index76.js +14 -0
- package/dist/index77.cjs +1 -0
- package/dist/index77.js +17 -0
- package/dist/index78.cjs +1 -0
- package/dist/index78.js +6 -0
- package/dist/index79.cjs +1 -0
- package/dist/index79.js +297 -0
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +97 -88
- package/dist/index80.cjs +1 -0
- package/dist/index80.js +25 -0
- package/dist/index81.cjs +1 -0
- package/dist/index81.js +39 -0
- package/dist/index82.cjs +1 -0
- package/dist/index82.js +625 -0
- package/dist/index83.cjs +1 -0
- package/dist/index83.js +721 -0
- package/dist/index84.cjs +1 -0
- package/dist/index84.js +154 -0
- package/dist/index85.cjs +1 -0
- package/dist/index85.js +173 -0
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +55 -197
- package/dist/src/components/core/button/Button.component.d.ts +13 -7
- package/dist/src/components/core/button/Button.component.d.ts.map +1 -1
- package/dist/src/components/core/icon/Icon.component.d.ts +1 -1
- package/dist/src/components/core/icon/Icon.component.d.ts.map +1 -1
- package/dist/src/components/core/icon-button/IconButton.component.d.ts +36 -0
- package/dist/src/components/core/icon-button/IconButton.component.d.ts.map +1 -0
- package/dist/src/components/core/menu-icon-button/MenuIconButton.component.d.ts +79 -0
- package/dist/src/components/core/menu-icon-button/MenuIconButton.component.d.ts.map +1 -0
- package/dist/src/components/feedback/spinner/Spinner.component.d.ts +62 -0
- package/dist/src/components/feedback/spinner/Spinner.component.d.ts.map +1 -0
- package/dist/src/components/forms/input/Input.component.d.ts +5 -0
- package/dist/src/components/forms/input/Input.component.d.ts.map +1 -1
- package/dist/src/components/forms/otp-input/OTPInput.component.d.ts +82 -0
- package/dist/src/components/forms/otp-input/OTPInput.component.d.ts.map +1 -0
- package/dist/src/components/forms/phone-input/PhoneInput.component.d.ts +96 -0
- package/dist/src/components/forms/phone-input/PhoneInput.component.d.ts.map +1 -0
- package/dist/src/components/forms/phone-input/countries.d.ts +93 -0
- package/dist/src/components/forms/phone-input/countries.d.ts.map +1 -0
- package/dist/src/components/forms/select/Select.component.d.ts +5 -1
- package/dist/src/components/forms/select/Select.component.d.ts.map +1 -1
- package/dist/src/components/forms/toggle/Toggle.component.d.ts +80 -0
- package/dist/src/components/forms/toggle/Toggle.component.d.ts.map +1 -0
- package/dist/src/components/layout/auth-layout/AuthLayout.component.d.ts +86 -0
- package/dist/src/components/layout/auth-layout/AuthLayout.component.d.ts.map +1 -0
- package/dist/src/components/overlays/dialog/Dialog.component.d.ts +36 -2
- package/dist/src/components/overlays/dialog/Dialog.component.d.ts.map +1 -1
- package/dist/src/components/typography/heading/Heading.component.d.ts +3 -2
- package/dist/src/components/typography/heading/Heading.component.d.ts.map +1 -1
- package/dist/src/components/typography/link/Link.component.d.ts +80 -0
- package/dist/src/components/typography/link/Link.component.d.ts.map +1 -0
- package/dist/src/index.d.ts +22 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +2 -1
- /package/dist/{index44.cjs → index61.cjs} +0 -0
- /package/dist/{index44.js → index61.js} +0 -0
package/dist/index12.js
CHANGED
|
@@ -1,125 +1,325 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef } from "react";
|
|
3
|
-
import { cn } from "./
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState, useId, useRef, useEffect, useCallback } from "react";
|
|
3
|
+
import { cn } from "./index31.js";
|
|
4
|
+
import { Icon } from "@adam-milo/icons";
|
|
5
|
+
import { commonCountries, getPhoneMask, getPhoneDigits, formatPhoneNumber } from "./index32.js";
|
|
6
|
+
import { allCountries, defaultCountries, defaultPhoneMask, getCountriesByDialCode, getCountryByCode, getCountryByDialCode, isValidPhoneLength, phoneMasks, searchCountries } from "./index32.js";
|
|
4
7
|
/* empty css */
|
|
5
|
-
const
|
|
8
|
+
const PhoneInput = forwardRef(
|
|
6
9
|
({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
label,
|
|
11
|
+
error,
|
|
12
|
+
helperText,
|
|
13
|
+
fullWidth = true,
|
|
14
|
+
value = "",
|
|
15
|
+
onChange,
|
|
16
|
+
countryCode = "US",
|
|
17
|
+
onCountryChange,
|
|
18
|
+
countries = commonCountries,
|
|
19
|
+
enableFormatting = true,
|
|
20
|
+
onValidationChange,
|
|
21
|
+
disabled,
|
|
22
|
+
required,
|
|
23
|
+
placeholder,
|
|
24
|
+
id: providedId,
|
|
10
25
|
"data-cy": dataCy,
|
|
11
26
|
"data-testid": dataTestId,
|
|
27
|
+
className,
|
|
28
|
+
onFocus,
|
|
29
|
+
onBlur,
|
|
12
30
|
...props
|
|
13
31
|
}, ref) => {
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"data-cy": finalDataCy,
|
|
40
|
-
"data-testid": finalTestId,
|
|
41
|
-
...props
|
|
32
|
+
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
33
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
34
|
+
const [highlightedIndex, setHighlightedIndex] = useState(0);
|
|
35
|
+
const generatedId = useId();
|
|
36
|
+
const id = providedId || generatedId;
|
|
37
|
+
const errorId = `${id}-error`;
|
|
38
|
+
const helperId = `${id}-helper`;
|
|
39
|
+
const listboxId = `${id}-listbox`;
|
|
40
|
+
const wrapperRef = useRef(null);
|
|
41
|
+
const dropdownRef = useRef(null);
|
|
42
|
+
const triggerRef = useRef(null);
|
|
43
|
+
const finalDataCy = dataCy || "phone-input";
|
|
44
|
+
const finalTestId = dataTestId || "phone-input";
|
|
45
|
+
const selectedCountry = countries.find((c) => c.code === countryCode) || countries[0];
|
|
46
|
+
const phoneMask = getPhoneMask(countryCode);
|
|
47
|
+
const displayPlaceholder = placeholder || phoneMask.placeholder;
|
|
48
|
+
const displayLabel = label && required && !label.includes("*") ? `${label}*` : label;
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const handleClickOutside = (event) => {
|
|
51
|
+
if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
|
|
52
|
+
setIsDropdownOpen(false);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
if (isDropdownOpen) {
|
|
56
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
42
57
|
}
|
|
58
|
+
return () => {
|
|
59
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
60
|
+
};
|
|
61
|
+
}, [isDropdownOpen]);
|
|
62
|
+
const handleCountrySelect = useCallback(
|
|
63
|
+
(country) => {
|
|
64
|
+
onCountryChange == null ? void 0 : onCountryChange(country);
|
|
65
|
+
setIsDropdownOpen(false);
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
var _a;
|
|
68
|
+
const input = (_a = wrapperRef.current) == null ? void 0 : _a.querySelector("input");
|
|
69
|
+
input == null ? void 0 : input.focus();
|
|
70
|
+
}, 0);
|
|
71
|
+
},
|
|
72
|
+
[onCountryChange]
|
|
43
73
|
);
|
|
44
|
-
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
const handleDropdownKeyDown = useCallback(
|
|
75
|
+
(e) => {
|
|
76
|
+
var _a;
|
|
77
|
+
switch (e.key) {
|
|
78
|
+
case "ArrowDown":
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
setHighlightedIndex((prev) => Math.min(prev + 1, countries.length - 1));
|
|
81
|
+
break;
|
|
82
|
+
case "ArrowUp":
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
setHighlightedIndex((prev) => Math.max(prev - 1, 0));
|
|
85
|
+
break;
|
|
86
|
+
case "Enter":
|
|
87
|
+
case " ":
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
handleCountrySelect(countries[highlightedIndex]);
|
|
90
|
+
break;
|
|
91
|
+
case "Escape":
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
setIsDropdownOpen(false);
|
|
94
|
+
(_a = triggerRef.current) == null ? void 0 : _a.focus();
|
|
95
|
+
break;
|
|
96
|
+
case "Tab":
|
|
97
|
+
setIsDropdownOpen(false);
|
|
98
|
+
break;
|
|
61
99
|
}
|
|
62
|
-
|
|
100
|
+
},
|
|
101
|
+
[countries, highlightedIndex, handleCountrySelect]
|
|
63
102
|
);
|
|
64
|
-
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const finalTestId = dataTestId || "card-description";
|
|
71
|
-
return /* @__PURE__ */ jsx(
|
|
72
|
-
"p",
|
|
73
|
-
{
|
|
74
|
-
ref,
|
|
75
|
-
className: cn("card-description", className),
|
|
76
|
-
"data-cy": finalDataCy,
|
|
77
|
-
"data-testid": finalTestId,
|
|
78
|
-
...props
|
|
103
|
+
const handleTriggerKeyDown = (e) => {
|
|
104
|
+
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
setIsDropdownOpen(true);
|
|
107
|
+
const index = countries.findIndex((c) => c.code === countryCode);
|
|
108
|
+
setHighlightedIndex(index === -1 ? 0 : index);
|
|
79
109
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
...props
|
|
110
|
+
};
|
|
111
|
+
const handleInputChange = (e) => {
|
|
112
|
+
const inputValue = e.target.value;
|
|
113
|
+
if (enableFormatting) {
|
|
114
|
+
const digits = getPhoneDigits(inputValue);
|
|
115
|
+
const limitedDigits = digits.slice(0, phoneMask.maxLength);
|
|
116
|
+
const formattedValue = formatPhoneNumber(limitedDigits, countryCode);
|
|
117
|
+
onChange == null ? void 0 : onChange(formattedValue);
|
|
118
|
+
const isValid = limitedDigits.length === phoneMask.maxLength;
|
|
119
|
+
onValidationChange == null ? void 0 : onValidationChange(isValid);
|
|
120
|
+
} else {
|
|
121
|
+
const numericValue = inputValue.replace(/[^0-9]/g, "");
|
|
122
|
+
onChange == null ? void 0 : onChange(numericValue);
|
|
123
|
+
const isValid = numericValue.length === phoneMask.maxLength;
|
|
124
|
+
onValidationChange == null ? void 0 : onValidationChange(isValid);
|
|
96
125
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
126
|
+
};
|
|
127
|
+
const handleInputFocus = (e) => {
|
|
128
|
+
setIsFocused(true);
|
|
129
|
+
onFocus == null ? void 0 : onFocus(e);
|
|
130
|
+
};
|
|
131
|
+
const handleInputBlur = (e) => {
|
|
132
|
+
setIsFocused(false);
|
|
133
|
+
onBlur == null ? void 0 : onBlur(e);
|
|
134
|
+
};
|
|
135
|
+
const inputState = disabled ? "disabled" : error ? "error" : isFocused || isDropdownOpen ? "focus" : "idle";
|
|
136
|
+
return /* @__PURE__ */ jsxs(
|
|
106
137
|
"div",
|
|
107
138
|
{
|
|
108
|
-
ref,
|
|
109
|
-
className: cn("
|
|
110
|
-
"data-cy": finalDataCy
|
|
111
|
-
"data-testid": finalTestId
|
|
112
|
-
|
|
139
|
+
ref: wrapperRef,
|
|
140
|
+
className: cn("phone-input-wrapper", fullWidth && "phone-input-wrapper--full-width"),
|
|
141
|
+
"data-cy": `${finalDataCy}-wrapper`,
|
|
142
|
+
"data-testid": `${finalTestId}-wrapper`,
|
|
143
|
+
children: [
|
|
144
|
+
label && /* @__PURE__ */ jsx(
|
|
145
|
+
"label",
|
|
146
|
+
{
|
|
147
|
+
htmlFor: id,
|
|
148
|
+
className: "phone-input__label",
|
|
149
|
+
"data-cy": `${finalDataCy}-label`,
|
|
150
|
+
"data-testid": `${finalTestId}-label`,
|
|
151
|
+
children: displayLabel
|
|
152
|
+
}
|
|
153
|
+
),
|
|
154
|
+
/* @__PURE__ */ jsxs(
|
|
155
|
+
"div",
|
|
156
|
+
{
|
|
157
|
+
className: cn(
|
|
158
|
+
"phone-input__container",
|
|
159
|
+
inputState === "focus" && "phone-input__container--focus",
|
|
160
|
+
inputState === "error" && "phone-input__container--error",
|
|
161
|
+
inputState === "disabled" && "phone-input__container--disabled"
|
|
162
|
+
),
|
|
163
|
+
"data-state": inputState,
|
|
164
|
+
"data-cy": `${finalDataCy}-container`,
|
|
165
|
+
"data-testid": `${finalTestId}-container`,
|
|
166
|
+
children: [
|
|
167
|
+
/* @__PURE__ */ jsxs(
|
|
168
|
+
"button",
|
|
169
|
+
{
|
|
170
|
+
ref: triggerRef,
|
|
171
|
+
type: "button",
|
|
172
|
+
className: "phone-input__country-trigger",
|
|
173
|
+
onClick: () => !disabled && setIsDropdownOpen(!isDropdownOpen),
|
|
174
|
+
onKeyDown: handleTriggerKeyDown,
|
|
175
|
+
disabled,
|
|
176
|
+
"aria-haspopup": "listbox",
|
|
177
|
+
"aria-expanded": isDropdownOpen,
|
|
178
|
+
"aria-controls": listboxId,
|
|
179
|
+
"aria-label": `Select country. Current: ${selectedCountry.name}`,
|
|
180
|
+
"data-cy": `${finalDataCy}-country-trigger`,
|
|
181
|
+
"data-testid": `${finalTestId}-country-trigger`,
|
|
182
|
+
children: [
|
|
183
|
+
/* @__PURE__ */ jsx(
|
|
184
|
+
"span",
|
|
185
|
+
{
|
|
186
|
+
className: "phone-input__flag",
|
|
187
|
+
"data-cy": `${finalDataCy}-flag`,
|
|
188
|
+
"data-testid": `${finalTestId}-flag`,
|
|
189
|
+
children: selectedCountry.flag
|
|
190
|
+
}
|
|
191
|
+
),
|
|
192
|
+
/* @__PURE__ */ jsx(
|
|
193
|
+
Icon,
|
|
194
|
+
{
|
|
195
|
+
name: "ChevronDownIcon",
|
|
196
|
+
size: "sm",
|
|
197
|
+
color: isFocused || isDropdownOpen ? "clickable" : "text",
|
|
198
|
+
decorative: true,
|
|
199
|
+
"data-cy": `${finalDataCy}-chevron`
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
),
|
|
205
|
+
/* @__PURE__ */ jsx(
|
|
206
|
+
"span",
|
|
207
|
+
{
|
|
208
|
+
className: "phone-input__dial-code",
|
|
209
|
+
"data-cy": `${finalDataCy}-dial-code`,
|
|
210
|
+
"data-testid": `${finalTestId}-dial-code`,
|
|
211
|
+
children: selectedCountry.dialCode
|
|
212
|
+
}
|
|
213
|
+
),
|
|
214
|
+
/* @__PURE__ */ jsx(
|
|
215
|
+
"input",
|
|
216
|
+
{
|
|
217
|
+
ref,
|
|
218
|
+
id,
|
|
219
|
+
type: "tel",
|
|
220
|
+
inputMode: "numeric",
|
|
221
|
+
value,
|
|
222
|
+
onChange: handleInputChange,
|
|
223
|
+
onFocus: handleInputFocus,
|
|
224
|
+
onBlur: handleInputBlur,
|
|
225
|
+
placeholder: displayPlaceholder,
|
|
226
|
+
disabled,
|
|
227
|
+
required,
|
|
228
|
+
className: cn("phone-input__input", className),
|
|
229
|
+
"aria-invalid": error ? "true" : "false",
|
|
230
|
+
"aria-required": required ? "true" : void 0,
|
|
231
|
+
"aria-describedby": error ? errorId : helperText ? helperId : void 0,
|
|
232
|
+
"data-cy": finalDataCy,
|
|
233
|
+
"data-testid": finalTestId,
|
|
234
|
+
...props
|
|
235
|
+
}
|
|
236
|
+
)
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
),
|
|
240
|
+
isDropdownOpen && /* @__PURE__ */ jsx(
|
|
241
|
+
"div",
|
|
242
|
+
{
|
|
243
|
+
ref: dropdownRef,
|
|
244
|
+
id: listboxId,
|
|
245
|
+
role: "listbox",
|
|
246
|
+
"aria-label": "Select country",
|
|
247
|
+
className: "phone-input__dropdown",
|
|
248
|
+
tabIndex: -1,
|
|
249
|
+
onKeyDown: handleDropdownKeyDown,
|
|
250
|
+
"data-cy": `${finalDataCy}-dropdown`,
|
|
251
|
+
"data-testid": `${finalTestId}-dropdown`,
|
|
252
|
+
children: countries.map((country, index) => /* @__PURE__ */ jsxs(
|
|
253
|
+
"div",
|
|
254
|
+
{
|
|
255
|
+
role: "option",
|
|
256
|
+
"aria-selected": country.code === countryCode,
|
|
257
|
+
className: cn(
|
|
258
|
+
"phone-input__option",
|
|
259
|
+
country.code === countryCode && "phone-input__option--selected",
|
|
260
|
+
index === highlightedIndex && "phone-input__option--highlighted"
|
|
261
|
+
),
|
|
262
|
+
onClick: () => handleCountrySelect(country),
|
|
263
|
+
onKeyDown: (e) => {
|
|
264
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
265
|
+
e.preventDefault();
|
|
266
|
+
handleCountrySelect(country);
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
onMouseEnter: () => setHighlightedIndex(index),
|
|
270
|
+
tabIndex: index === highlightedIndex ? 0 : -1,
|
|
271
|
+
"data-cy": `${finalDataCy}-option-${country.code.toLowerCase()}`,
|
|
272
|
+
"data-testid": `${finalTestId}-option-${country.code.toLowerCase()}`,
|
|
273
|
+
children: [
|
|
274
|
+
/* @__PURE__ */ jsx("span", { className: "phone-input__option-flag", children: country.flag }),
|
|
275
|
+
/* @__PURE__ */ jsx("span", { className: "phone-input__option-name", children: country.name }),
|
|
276
|
+
/* @__PURE__ */ jsx("span", { className: "phone-input__option-dial-code", children: country.dialCode })
|
|
277
|
+
]
|
|
278
|
+
},
|
|
279
|
+
country.code
|
|
280
|
+
))
|
|
281
|
+
}
|
|
282
|
+
),
|
|
283
|
+
error && /* @__PURE__ */ jsx(
|
|
284
|
+
"span",
|
|
285
|
+
{
|
|
286
|
+
id: errorId,
|
|
287
|
+
className: "phone-input__error",
|
|
288
|
+
role: "alert",
|
|
289
|
+
"data-cy": `${finalDataCy}-error`,
|
|
290
|
+
"data-testid": `${finalTestId}-error`,
|
|
291
|
+
children: error
|
|
292
|
+
}
|
|
293
|
+
),
|
|
294
|
+
helperText && !error && /* @__PURE__ */ jsx(
|
|
295
|
+
"span",
|
|
296
|
+
{
|
|
297
|
+
id: helperId,
|
|
298
|
+
className: "phone-input__helper",
|
|
299
|
+
"data-cy": `${finalDataCy}-helper`,
|
|
300
|
+
"data-testid": `${finalTestId}-helper`,
|
|
301
|
+
children: helperText
|
|
302
|
+
}
|
|
303
|
+
)
|
|
304
|
+
]
|
|
113
305
|
}
|
|
114
306
|
);
|
|
115
307
|
}
|
|
116
308
|
);
|
|
117
|
-
|
|
309
|
+
PhoneInput.displayName = "PhoneInput";
|
|
118
310
|
export {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
311
|
+
PhoneInput,
|
|
312
|
+
allCountries,
|
|
313
|
+
commonCountries,
|
|
314
|
+
defaultCountries,
|
|
315
|
+
defaultPhoneMask,
|
|
316
|
+
formatPhoneNumber,
|
|
317
|
+
getCountriesByDialCode,
|
|
318
|
+
getCountryByCode,
|
|
319
|
+
getCountryByDialCode,
|
|
320
|
+
getPhoneDigits,
|
|
321
|
+
getPhoneMask,
|
|
322
|
+
isValidPhoneLength,
|
|
323
|
+
phoneMasks,
|
|
324
|
+
searchCountries
|
|
125
325
|
};
|
package/dist/index13.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),a=require("./index31.cjs");;/* empty css */const r=t.forwardRef(({length:r=4,label:l,value:n="",onChange:i,onComplete:s,error:c,helperText:o,disabled:u=!1,autoFocus:p=!1,fullWidth:d=!1,centered:f=!1,type:b="numeric",required:h=!1,"data-cy":g,"data-testid":y},m)=>{const $=t.useId(),_=`${$}-error`,x=`${$}-helper`,k=g||"otp-input",v=y||"otp-input",D=t.useRef([]),[j,C]=t.useState(()=>n.split("").slice(0,r).concat(Array(r).fill("")).slice(0,r));t.useEffect(()=>{const e=n.split("").slice(0,r).concat(Array(r).fill("")).slice(0,r);C(e)},[n,r]);const w=t.useCallback(e=>"numeric"===b?/^\d$/.test(e):/^[a-zA-Z0-9]$/.test(e),[b]),A=t.useCallback(e=>{C(e);const t=e.join("");null==i||i(t),e.every(e=>""!==e)&&e.length===r&&(null==s||s(t))},[i,s,r]),I=t.useCallback(e=>{const t=D.current[e];t&&(t.focus(),t.select())},[]),N=t.useCallback((e,t)=>{const a=t.target.value;if(1===a.length&&w(a)){const t=[...j];t[e]=a,A(t),e<r-1&&I(e+1)}else if(a.length>1){const t=a.split("").filter(w),l=[...j];t.forEach((t,a)=>{e+a<r&&(l[e+a]=t)}),A(l);const n=l.findIndex(e=>""===e);I(-1===n?r-1:n)}},[j,r,w,A,I]),q=t.useCallback((e,t)=>{switch(t.key){case"Backspace":if(t.preventDefault(),j[e]){const t=[...j];t[e]="",A(t)}else if(e>0){const t=[...j];t[e-1]="",A(t),I(e-1)}break;case"Delete":if(t.preventDefault(),j[e]){const t=[...j];t[e]="",A(t)}break;case"ArrowLeft":t.preventDefault(),e>0&&I(e-1);break;case"ArrowRight":t.preventDefault(),e<r-1&&I(e+1);break;case"Home":t.preventDefault(),I(0);break;case"End":t.preventDefault(),I(r-1);break;default:if(1===t.key.length&&w(t.key)){t.preventDefault();const a=[...j];a[e]=t.key,A(a),e<r-1&&I(e+1)}}},[j,r,w,A,I]),E=t.useCallback((e,t)=>{t.preventDefault();const a=t.clipboardData.getData("text").split("").filter(w);if(0===a.length)return;const l=[...j];a.forEach((t,a)=>{e+a<r&&(l[e+a]=t)}),A(l);const n=l.findIndex(e=>""===e);I(-1===n?r-1:n)},[j,r,w,A,I]),P=t.useCallback(e=>{e.target.select()},[]);return t.useImperativeHandle(m,()=>({focus:()=>{const e=j.findIndex(e=>""===e);I(-1===e?r-1:e)},clear:()=>{const e=Array(r).fill("");A(e),I(0)},getValue:()=>j.join("")}),[j,r,I,A]),t.useEffect(()=>{p&&!u&&I(0)},[p,u,I]),e.jsxs("div",{className:a.cn("otp-input-wrapper",d&&"otp-input-wrapper--full-width"),"data-cy":`${k}-wrapper`,"data-testid":`${v}-wrapper`,children:[l&&e.jsx("label",{className:a.cn("otp-input__label",c&&"otp-input__label--error",u&&"otp-input__label--disabled"),"data-cy":`${k}-label`,"data-testid":`${v}-label`,children:l}),e.jsx("div",{className:a.cn("otp-input__container",f&&"otp-input__container--centered"),role:"group","aria-label":l||"OTP Input","data-cy":`${k}-container`,"data-testid":`${v}-container`,children:Array.from({length:r},(t,l)=>e.jsx("input",{ref:e=>{D.current[l]=e},type:"text",inputMode:"numeric"===b?"numeric":"text",pattern:"numeric"===b?"[0-9]*":"[a-zA-Z0-9]*",maxLength:1,value:j[l]||"",onChange:e=>N(l,e),onKeyDown:e=>q(l,e),onPaste:e=>E(l,e),onFocus:P,disabled:u,required:h,"aria-label":`Digit ${l+1} of ${r}`,"aria-invalid":c?"true":"false","aria-describedby":c?_:o?x:void 0,className:a.cn("otp-input__digit",j[l]&&"otp-input__digit--filled",c&&"otp-input__digit--error"),"data-cy":`${k}-digit-${l}`,"data-testid":`${v}-digit-${l}`,autoComplete:"one-time-code"},l))}),c&&e.jsx("span",{id:_,className:"otp-input__error",role:"alert","data-cy":`${k}-error`,"data-testid":`${v}-error`,children:c}),o&&!c&&e.jsx("span",{id:x,className:"otp-input__helper","data-cy":`${k}-helper`,"data-testid":`${v}-helper`,children:o})]})});r.displayName="OTPInput",exports.OTPInput=r;
|