@caspeco/casper-ui-library 10.0.3 → 10.1.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/dist/components/combobox/combobox.d.ts.map +1 -1
- package/dist/components/combobox/combobox.js +186 -169
- package/dist/components/combobox/types.d.ts +1 -0
- package/dist/components/combobox/types.d.ts.map +1 -1
- package/dist/components/input/input-recipe.d.ts.map +1 -1
- package/dist/components/input/input-recipe.js +8 -3
- package/dist/components/input/input.composition.d.ts.map +1 -1
- package/dist/components/input/input.d.ts +1 -0
- package/dist/components/input/input.d.ts.map +1 -1
- package/dist/components/input/input.js +76 -52
- package/dist/components/input/types.d.ts +2 -2
- package/dist/components/input/types.d.ts.map +1 -1
- package/dist/components/menu/menu-box-button.d.ts +4 -1
- package/dist/components/menu/menu-box-button.d.ts.map +1 -1
- package/dist/components/menu/menu-box-button.js +15 -14
- package/dist/components/phone-input/country-data.d.ts +22 -0
- package/dist/components/phone-input/country-data.d.ts.map +1 -0
- package/dist/components/phone-input/country-data.js +38 -0
- package/dist/components/phone-input/country-data.spec.d.ts +2 -0
- package/dist/components/phone-input/country-data.spec.d.ts.map +1 -0
- package/dist/components/phone-input/country-list.d.ts +19 -0
- package/dist/components/phone-input/country-list.d.ts.map +1 -0
- package/dist/components/phone-input/country-list.js +27 -0
- package/dist/components/phone-input/country-selector.d.ts +59 -0
- package/dist/components/phone-input/country-selector.d.ts.map +1 -0
- package/dist/components/phone-input/country-selector.js +120 -0
- package/dist/components/phone-input/index.d.ts +5 -0
- package/dist/components/phone-input/index.d.ts.map +1 -0
- package/dist/components/phone-input/phone-input-helpers.d.ts +47 -0
- package/dist/components/phone-input/phone-input-helpers.d.ts.map +1 -0
- package/dist/components/phone-input/phone-input-helpers.js +134 -0
- package/dist/components/phone-input/phone-input-helpers.spec.d.ts +2 -0
- package/dist/components/phone-input/phone-input-helpers.spec.d.ts.map +1 -0
- package/dist/components/phone-input/phone-input.composition.d.ts +26 -0
- package/dist/components/phone-input/phone-input.composition.d.ts.map +1 -0
- package/dist/components/phone-input/phone-input.d.ts +22 -0
- package/dist/components/phone-input/phone-input.d.ts.map +1 -0
- package/dist/components/phone-input/phone-input.js +43 -0
- package/dist/components/phone-input/phone-input.spec.d.ts +2 -0
- package/dist/components/phone-input/phone-input.spec.d.ts.map +1 -0
- package/dist/components/phone-input/phone-input.visual.test.d.ts +2 -0
- package/dist/components/phone-input/phone-input.visual.test.d.ts.map +1 -0
- package/dist/components/phone-input/translations.d.ts +60 -0
- package/dist/components/phone-input/translations.d.ts.map +1 -0
- package/dist/components/phone-input/translations.js +54 -0
- package/dist/components/phone-input/types.d.ts +45 -0
- package/dist/components/phone-input/types.d.ts.map +1 -0
- package/dist/components/phone-input/use-phone-input.d.ts +49 -0
- package/dist/components/phone-input/use-phone-input.d.ts.map +1 -0
- package/dist/components/phone-input/use-phone-input.js +138 -0
- package/dist/components/phone-input/use-phone-input.spec.d.ts +2 -0
- package/dist/components/phone-input/use-phone-input.spec.d.ts.map +1 -0
- package/dist/hooks/use-measured-width.d.ts +23 -0
- package/dist/hooks/use-measured-width.d.ts.map +1 -0
- package/dist/hooks/use-measured-width.js +22 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +289 -285
- package/dist/node_modules/country-flag-icons/modules/countries.json.js +4 -0
- package/dist/node_modules/country-flag-icons/modules/hasFlag.js +7 -0
- package/dist/node_modules/country-flag-icons/modules/react/3x2/index.js +6303 -0
- package/dist/node_modules/country-flag-icons/react/3x2/index.js +269 -0
- package/dist/node_modules/libphonenumber-js/es6/ParseError.js +89 -0
- package/dist/node_modules/libphonenumber-js/es6/PhoneNumber.js +192 -0
- package/dist/node_modules/libphonenumber-js/es6/constants.js +10 -0
- package/dist/node_modules/libphonenumber-js/es6/format.js +98 -0
- package/dist/node_modules/libphonenumber-js/es6/getCountries.js +7 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/RFC3966.js +11 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/applyInternationalSeparatorStyle.js +7 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/checkNumberLength.js +16 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extension/createExtensionPattern.js +11 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extension/extractExtension.js +18 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractCountryCallingCode.js +46 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +27 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +23 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractNationalNumber.js +39 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +31 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractPhoneContext.js +23 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/formatNationalNumberUsingFormat.js +25 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getCountryAndCallingCodeFromOneOfThem.js +12 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getCountryByCallingCode.js +9 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getCountryByNationalNumber.js +43 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getIddPrefix.js +12 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getNumberType.js +52 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getPossibleCountriesForNumber.js +14 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/isCallingCode.js +7 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/isCountryCode.js +7 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/isObject.js +7 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/isViablePhoneNumber.js +20 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/matchesEntirely.js +6 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/parseDigits.js +79 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/stripIddPrefix.js +19 -0
- package/dist/node_modules/libphonenumber-js/es6/isPossible.js +35 -0
- package/dist/node_modules/libphonenumber-js/es6/isValid.js +14 -0
- package/dist/node_modules/libphonenumber-js/es6/isValidPhoneNumber.js +59 -0
- package/dist/node_modules/libphonenumber-js/es6/metadata.js +494 -0
- package/dist/node_modules/libphonenumber-js/es6/normalizeArguments.js +108 -0
- package/dist/node_modules/libphonenumber-js/es6/parse.js +138 -0
- package/dist/node_modules/libphonenumber-js/es6/parseIncompletePhoneNumber.js +40 -0
- package/dist/node_modules/libphonenumber-js/es6/parsePhoneNumber.js +9 -0
- package/dist/node_modules/libphonenumber-js/es6/parsePhoneNumberWithError_.js +55 -0
- package/dist/node_modules/libphonenumber-js/es6/parsePhoneNumber_.js +62 -0
- package/dist/node_modules/libphonenumber-js/es6/tools/semver-compare.js +14 -0
- package/dist/node_modules/libphonenumber-js/metadata.min.json.js +4 -0
- package/dist/node_modules/libphonenumber-js/min/exports/getCountries.js +8 -0
- package/dist/node_modules/libphonenumber-js/min/exports/getCountryCallingCode.js +8 -0
- package/dist/node_modules/libphonenumber-js/min/exports/isSupportedCountry.js +8 -0
- package/dist/node_modules/libphonenumber-js/min/exports/isValidPhoneNumber.js +8 -0
- package/dist/node_modules/libphonenumber-js/min/exports/parsePhoneNumber.js +8 -0
- package/dist/node_modules/libphonenumber-js/min/exports/withMetadataArgument.js +8 -0
- package/dist/test-utils/create-visual-tests.d.ts.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { translations as I } from "./translations.js";
|
|
2
|
+
import { parsePhoneNumber as u } from "../../node_modules/libphonenumber-js/min/exports/parsePhoneNumber.js";
|
|
3
|
+
import { getCountries as g } from "../../node_modules/libphonenumber-js/min/exports/getCountries.js";
|
|
4
|
+
import { getCountryCallingCode as o } from "../../node_modules/libphonenumber-js/min/exports/getCountryCallingCode.js";
|
|
5
|
+
import { isValidPhoneNumber as d } from "../../node_modules/libphonenumber-js/min/exports/isValidPhoneNumber.js";
|
|
6
|
+
import { isSupportedCountry as b } from "../../node_modules/libphonenumber-js/min/exports/isSupportedCountry.js";
|
|
7
|
+
function V(t, n, r = {}) {
|
|
8
|
+
const {
|
|
9
|
+
isRequired: e = !1,
|
|
10
|
+
showValidation: i = !1,
|
|
11
|
+
locale: s = "en-US"
|
|
12
|
+
} = r, a = I[s], f = h(t, n);
|
|
13
|
+
return f && d(t, n) ? {
|
|
14
|
+
isValid: !0
|
|
15
|
+
} : i ? f ? {
|
|
16
|
+
isValid: !1,
|
|
17
|
+
errorMessage: a.numberLooksIncomplete
|
|
18
|
+
} : {
|
|
19
|
+
isValid: !1,
|
|
20
|
+
errorMessage: e ? a.requiredFieldEmpty : void 0
|
|
21
|
+
} : {
|
|
22
|
+
isValid: !1,
|
|
23
|
+
errorMessage: void 0
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function F(t, n) {
|
|
27
|
+
return u(t, n)?.formatInternational() ?? t;
|
|
28
|
+
}
|
|
29
|
+
function L(t, n) {
|
|
30
|
+
const r = u(t, n);
|
|
31
|
+
if (r)
|
|
32
|
+
return r.format("E.164");
|
|
33
|
+
const e = t.trim().startsWith("+"), i = t.replace(/\D/g, "");
|
|
34
|
+
return i ? e ? `+${i}` : i : "";
|
|
35
|
+
}
|
|
36
|
+
function M(t, n) {
|
|
37
|
+
const r = u(t, n);
|
|
38
|
+
return r ? r.nationalNumber?.toString() ?? "" : m(t, n);
|
|
39
|
+
}
|
|
40
|
+
function m(t, n) {
|
|
41
|
+
const r = o(n), e = t.replace(/\D/g, "");
|
|
42
|
+
return e.startsWith(r) ? e.slice(r.length) : e;
|
|
43
|
+
}
|
|
44
|
+
function h(t, n) {
|
|
45
|
+
return m(t, n).length > 0;
|
|
46
|
+
}
|
|
47
|
+
function U(t, n) {
|
|
48
|
+
return h(t, n) && !d(t, n);
|
|
49
|
+
}
|
|
50
|
+
const l = {
|
|
51
|
+
1: "US",
|
|
52
|
+
7: "RU",
|
|
53
|
+
39: "IT",
|
|
54
|
+
44: "GB",
|
|
55
|
+
47: "NO",
|
|
56
|
+
61: "AU",
|
|
57
|
+
212: "MA",
|
|
58
|
+
262: "RE",
|
|
59
|
+
290: "SH",
|
|
60
|
+
358: "FI",
|
|
61
|
+
590: "GP",
|
|
62
|
+
599: "CW"
|
|
63
|
+
};
|
|
64
|
+
let c = null;
|
|
65
|
+
function p() {
|
|
66
|
+
return c || (c = new Set(g().map((t) => o(t).toString()))), c;
|
|
67
|
+
}
|
|
68
|
+
function C(t, n) {
|
|
69
|
+
return t.replace(/^\+/, "").replace(/\D/g, "").slice(0, n);
|
|
70
|
+
}
|
|
71
|
+
function S(t) {
|
|
72
|
+
if (!t.trim().startsWith("+"))
|
|
73
|
+
return;
|
|
74
|
+
const n = p(), r = C(t, 3);
|
|
75
|
+
for (let e = 3; e >= 1; e--) {
|
|
76
|
+
const i = r.slice(0, e);
|
|
77
|
+
if (i.length !== e || !n.has(i))
|
|
78
|
+
continue;
|
|
79
|
+
if (l[i])
|
|
80
|
+
return l[i];
|
|
81
|
+
const s = u(t);
|
|
82
|
+
return s?.country && o(s.country) === i ? s.country : g().find((a) => o(a) === i);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function w(t, n) {
|
|
86
|
+
const r = S(t);
|
|
87
|
+
if (r && r !== n && o(r) !== o(n))
|
|
88
|
+
return r;
|
|
89
|
+
}
|
|
90
|
+
function A(t) {
|
|
91
|
+
if (!t.trim().startsWith("+"))
|
|
92
|
+
return !1;
|
|
93
|
+
const n = C(t, 3);
|
|
94
|
+
if (!n)
|
|
95
|
+
return !1;
|
|
96
|
+
for (const r of p())
|
|
97
|
+
if (r.startsWith(n) || n.startsWith(r))
|
|
98
|
+
return !1;
|
|
99
|
+
return !0;
|
|
100
|
+
}
|
|
101
|
+
function N(t) {
|
|
102
|
+
if (t)
|
|
103
|
+
try {
|
|
104
|
+
const n = new Intl.Locale(t), r = n.region ?? n.maximize().region;
|
|
105
|
+
return r && b(r) ? r : void 0;
|
|
106
|
+
} catch {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function v() {
|
|
111
|
+
if (typeof navigator > "u")
|
|
112
|
+
return;
|
|
113
|
+
const t = navigator.languages?.length ? navigator.languages : [navigator.language];
|
|
114
|
+
for (const n of t) {
|
|
115
|
+
const r = N(n);
|
|
116
|
+
if (r)
|
|
117
|
+
return r;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function G(t, n) {
|
|
121
|
+
return t || (v() ?? N(n) ?? "SE");
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
w as detectCountryChange,
|
|
125
|
+
S as detectCountryFromInput,
|
|
126
|
+
M as extractNationalNumber,
|
|
127
|
+
F as formatPhoneNumber,
|
|
128
|
+
h as hasNationalContent,
|
|
129
|
+
U as isIncompletePhoneNumber,
|
|
130
|
+
A as isUnknownCallingCode,
|
|
131
|
+
G as resolveInitialCountry,
|
|
132
|
+
L as toE164,
|
|
133
|
+
V as validatePhoneNumber
|
|
134
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-input-helpers.spec.d.ts","sourceRoot":"","sources":["../../../lib/components/phone-input/phone-input-helpers.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default appearance: input with the country flag + prefilled dial code, and a label.
|
|
3
|
+
*/
|
|
4
|
+
export declare const Default: () => import("react").JSX.Element;
|
|
5
|
+
/**
|
|
6
|
+
* The four sizes stacked, to catch height + flag/icon scaling regressions.
|
|
7
|
+
*/
|
|
8
|
+
export declare const Sizes: () => import("react").JSX.Element;
|
|
9
|
+
/**
|
|
10
|
+
* Outline (default) vs ghost variants.
|
|
11
|
+
*/
|
|
12
|
+
export declare const Variants: () => import("react").JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* Invalid state: red border + the built-in error message rendered into the FormControl.
|
|
15
|
+
*/
|
|
16
|
+
export declare const Invalid: () => import("react").JSX.Element;
|
|
17
|
+
/**
|
|
18
|
+
* Disabled input + country selector.
|
|
19
|
+
*/
|
|
20
|
+
export declare const Disabled: () => import("react").JSX.Element;
|
|
21
|
+
/**
|
|
22
|
+
* Country selector open — the searchable dropdown with flags and calling codes.
|
|
23
|
+
* The visual test opens it via `beforeScreenshot`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const MenuOpen: () => import("react").JSX.Element;
|
|
26
|
+
//# sourceMappingURL=phone-input.composition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-input.composition.d.ts","sourceRoot":"","sources":["../../../lib/components/phone-input/phone-input.composition.tsx"],"names":[],"mappings":"AAiBA;;GAEG;AACH,eAAO,MAAM,OAAO,mCAQnB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,KAAK,mCAOjB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,mCAKpB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,OAAO,mCAQnB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,mCAQpB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,mCAQpB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PhoneInputProps } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Phone number input with integrated country selection, formatting and validation.
|
|
4
|
+
*
|
|
5
|
+
* Presentational — always driven by {@link usePhoneInput}. Spread `inputProps` onto it and
|
|
6
|
+
* wrap it in a `<FormControl>` you own (spread `formControlProps`); the component renders its
|
|
7
|
+
* own error message into that FormControl's context.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const phone = usePhoneInput({ defaultCountry: "SE", isRequired: true });
|
|
12
|
+
*
|
|
13
|
+
* <FormControl {...phone.formControlProps}>
|
|
14
|
+
* <FormLabel>Phone number</FormLabel>
|
|
15
|
+
* <PhoneInput {...phone.inputProps} placeholder="Enter phone number" />
|
|
16
|
+
* </FormControl>
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @see Docs https://caspeco.github.io/casper-ui-library/components/phone-input
|
|
20
|
+
*/
|
|
21
|
+
export declare function PhoneInput({ ref, value, onChange, onBlur, country, onCountryChange, unknownPrefix, errorMessage, locale, size, variant, placeholder, isDisabled: isDisabledProp, isReadOnly: isReadOnlyProp, ...rest }: PhoneInputProps): import("react").JSX.Element;
|
|
22
|
+
//# sourceMappingURL=phone-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-input.d.ts","sourceRoot":"","sources":["../../../lib/components/phone-input/phone-input.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,EAC1B,GAAG,EACH,KAAK,EACL,QAAQ,EACR,MAAM,EACN,OAAO,EACP,eAAe,EACf,aAAa,EACb,YAAY,EACZ,MAAgB,EAChB,IAAW,EACX,OAAmB,EACnB,WAAW,EACX,UAAU,EAAE,cAAc,EAC1B,UAAU,EAAE,cAAc,EAC1B,GAAG,IAAI,EACP,EAAE,eAAe,+BAsCjB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as E, jsxs as j, Fragment as z } from "react/jsx-runtime";
|
|
2
|
+
import { c as B } from "../../_virtual/compiler-runtime.js";
|
|
3
|
+
import { useFieldContext as I } from "@chakra-ui/react";
|
|
4
|
+
import { CountrySelector as S } from "./country-selector.js";
|
|
5
|
+
import { translations as N } from "./translations.js";
|
|
6
|
+
import { Input as U } from "../input/input.js";
|
|
7
|
+
import { FormErrorMessage as $ } from "../form-control/form-error-message.js";
|
|
8
|
+
function Q(R) {
|
|
9
|
+
const e = B.c(40);
|
|
10
|
+
let b, t, v, x, l, o, n, C, r, s, u, h, y, P, i;
|
|
11
|
+
e[0] !== R ? ({
|
|
12
|
+
ref: r,
|
|
13
|
+
value: i,
|
|
14
|
+
onChange: o,
|
|
15
|
+
onBlur: l,
|
|
16
|
+
country: b,
|
|
17
|
+
onCountryChange: n,
|
|
18
|
+
unknownPrefix: P,
|
|
19
|
+
errorMessage: t,
|
|
20
|
+
locale: u,
|
|
21
|
+
size: h,
|
|
22
|
+
variant: y,
|
|
23
|
+
placeholder: C,
|
|
24
|
+
isDisabled: v,
|
|
25
|
+
isReadOnly: x,
|
|
26
|
+
...s
|
|
27
|
+
} = R, e[0] = R, e[1] = b, e[2] = t, e[3] = v, e[4] = x, e[5] = l, e[6] = o, e[7] = n, e[8] = C, e[9] = r, e[10] = s, e[11] = u, e[12] = h, e[13] = y, e[14] = P, e[15] = i) : (b = e[1], t = e[2], v = e[3], x = e[4], l = e[5], o = e[6], n = e[7], C = e[8], r = e[9], s = e[10], u = e[11], h = e[12], y = e[13], P = e[14], i = e[15]);
|
|
28
|
+
const g = u === void 0 ? "en-US" : u, a = h === void 0 ? "md" : h, D = y === void 0 ? "outline" : y, M = N[g], F = I(), d = v ?? F?.disabled ?? !1, c = x ?? F?.readOnly ?? !1, k = C ?? M.enterPhoneNumberPlaceholder, w = P ? void 0 : b;
|
|
29
|
+
let m;
|
|
30
|
+
e[16] !== d || e[17] !== g || e[18] !== n || e[19] !== c || e[20] !== a || e[21] !== w ? (m = /* @__PURE__ */ E(S, { value: w, onChange: n, size: a, menuPlacement: "bottom-start", locale: g, isDisabled: d, isReadOnly: c }), e[16] = d, e[17] = g, e[18] = n, e[19] = c, e[20] = a, e[21] = w, e[22] = m) : m = e[22];
|
|
31
|
+
let f;
|
|
32
|
+
e[23] !== d || e[24] !== l || e[25] !== o || e[26] !== c || e[27] !== r || e[28] !== s || e[29] !== a || e[30] !== k || e[31] !== m || e[32] !== i || e[33] !== D ? (f = /* @__PURE__ */ E(U, { ref: r, type: "tel", inputMode: "tel", placeholder: k, value: i, size: a, variant: D, isDisabled: d, isReadOnly: c, onChange: o, onBlur: l, leftElement: m, ...s }), e[23] = d, e[24] = l, e[25] = o, e[26] = c, e[27] = r, e[28] = s, e[29] = a, e[30] = k, e[31] = m, e[32] = i, e[33] = D, e[34] = f) : f = e[34];
|
|
33
|
+
let p;
|
|
34
|
+
e[35] !== t ? (p = t && /* @__PURE__ */ E($, { wordBreak: "break-word", children: t }), e[35] = t, e[36] = p) : p = e[36];
|
|
35
|
+
let O;
|
|
36
|
+
return e[37] !== f || e[38] !== p ? (O = /* @__PURE__ */ j(z, { children: [
|
|
37
|
+
f,
|
|
38
|
+
p
|
|
39
|
+
] }), e[37] = f, e[38] = p, e[39] = O) : O = e[39], O;
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
Q as PhoneInput
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-input.spec.d.ts","sourceRoot":"","sources":["../../../lib/components/phone-input/phone-input.spec.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone-input.visual.test.d.ts","sourceRoot":"","sources":["../../../lib/components/phone-input/phone-input.visual.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type Locales = "en-US" | "nb-NO" | "da-DK" | "sv-SE" | "en-GB" | "fr-FR" | "nl-BE";
|
|
2
|
+
export declare const translations: {
|
|
3
|
+
"sv-SE": {
|
|
4
|
+
searchCountryPlaceholder: string;
|
|
5
|
+
noCountriesFound: string;
|
|
6
|
+
enterPhoneNumberPlaceholder: string;
|
|
7
|
+
numberLooksIncomplete: string;
|
|
8
|
+
requiredFieldEmpty: string;
|
|
9
|
+
openCountrySelector: string;
|
|
10
|
+
};
|
|
11
|
+
"en-US": {
|
|
12
|
+
searchCountryPlaceholder: string;
|
|
13
|
+
noCountriesFound: string;
|
|
14
|
+
enterPhoneNumberPlaceholder: string;
|
|
15
|
+
numberLooksIncomplete: string;
|
|
16
|
+
requiredFieldEmpty: string;
|
|
17
|
+
openCountrySelector: string;
|
|
18
|
+
};
|
|
19
|
+
"en-GB": {
|
|
20
|
+
searchCountryPlaceholder: string;
|
|
21
|
+
noCountriesFound: string;
|
|
22
|
+
enterPhoneNumberPlaceholder: string;
|
|
23
|
+
numberLooksIncomplete: string;
|
|
24
|
+
requiredFieldEmpty: string;
|
|
25
|
+
openCountrySelector: string;
|
|
26
|
+
};
|
|
27
|
+
"nb-NO": {
|
|
28
|
+
searchCountryPlaceholder: string;
|
|
29
|
+
noCountriesFound: string;
|
|
30
|
+
enterPhoneNumberPlaceholder: string;
|
|
31
|
+
numberLooksIncomplete: string;
|
|
32
|
+
requiredFieldEmpty: string;
|
|
33
|
+
openCountrySelector: string;
|
|
34
|
+
};
|
|
35
|
+
"da-DK": {
|
|
36
|
+
searchCountryPlaceholder: string;
|
|
37
|
+
noCountriesFound: string;
|
|
38
|
+
enterPhoneNumberPlaceholder: string;
|
|
39
|
+
numberLooksIncomplete: string;
|
|
40
|
+
requiredFieldEmpty: string;
|
|
41
|
+
openCountrySelector: string;
|
|
42
|
+
};
|
|
43
|
+
"fr-FR": {
|
|
44
|
+
searchCountryPlaceholder: string;
|
|
45
|
+
noCountriesFound: string;
|
|
46
|
+
enterPhoneNumberPlaceholder: string;
|
|
47
|
+
numberLooksIncomplete: string;
|
|
48
|
+
requiredFieldEmpty: string;
|
|
49
|
+
openCountrySelector: string;
|
|
50
|
+
};
|
|
51
|
+
"nl-BE": {
|
|
52
|
+
searchCountryPlaceholder: string;
|
|
53
|
+
noCountriesFound: string;
|
|
54
|
+
enterPhoneNumberPlaceholder: string;
|
|
55
|
+
numberLooksIncomplete: string;
|
|
56
|
+
requiredFieldEmpty: string;
|
|
57
|
+
openCountrySelector: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=translations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translations.d.ts","sourceRoot":"","sources":["../../../lib/components/phone-input/translations.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAW1F,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CxB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const e = {
|
|
2
|
+
searchCountryPlaceholder: "Search country...",
|
|
3
|
+
noCountriesFound: "No countries found",
|
|
4
|
+
enterPhoneNumberPlaceholder: "Enter your phone number",
|
|
5
|
+
numberLooksIncomplete: "Please enter a valid phone number",
|
|
6
|
+
requiredFieldEmpty: "Phone number is required",
|
|
7
|
+
openCountrySelector: "Open country selector"
|
|
8
|
+
}, n = {
|
|
9
|
+
"sv-SE": {
|
|
10
|
+
searchCountryPlaceholder: "Sök land...",
|
|
11
|
+
noCountriesFound: "Inga länder hittades",
|
|
12
|
+
enterPhoneNumberPlaceholder: "Ange ditt telefonnummer",
|
|
13
|
+
numberLooksIncomplete: "Ange ett giltigt telefonnummer",
|
|
14
|
+
requiredFieldEmpty: "Telefonnummer krävs",
|
|
15
|
+
openCountrySelector: "Öppna landsväljaren"
|
|
16
|
+
},
|
|
17
|
+
"en-US": e,
|
|
18
|
+
"en-GB": e,
|
|
19
|
+
"nb-NO": {
|
|
20
|
+
searchCountryPlaceholder: "Søk land...",
|
|
21
|
+
noCountriesFound: "Ingen land funnet",
|
|
22
|
+
enterPhoneNumberPlaceholder: "Skriv inn telefonnummeret ditt",
|
|
23
|
+
numberLooksIncomplete: "Skriv inn et gyldig telefonnummer",
|
|
24
|
+
requiredFieldEmpty: "Telefonnummer er påkrevd",
|
|
25
|
+
openCountrySelector: "Åpne landvelgeren"
|
|
26
|
+
},
|
|
27
|
+
"da-DK": {
|
|
28
|
+
searchCountryPlaceholder: "Søg land...",
|
|
29
|
+
noCountriesFound: "Ingen lande fundet",
|
|
30
|
+
enterPhoneNumberPlaceholder: "Indtast dit telefonnummer",
|
|
31
|
+
numberLooksIncomplete: "Indtast et gyldigt telefonnummer",
|
|
32
|
+
requiredFieldEmpty: "Telefonnummer er påkrævet",
|
|
33
|
+
openCountrySelector: "Åbn landevælgeren"
|
|
34
|
+
},
|
|
35
|
+
"fr-FR": {
|
|
36
|
+
searchCountryPlaceholder: "Rechercher un pays...",
|
|
37
|
+
noCountriesFound: "Aucun pays trouvé",
|
|
38
|
+
enterPhoneNumberPlaceholder: "Entrez votre numéro de téléphone",
|
|
39
|
+
numberLooksIncomplete: "Veuillez saisir un numéro de téléphone valide",
|
|
40
|
+
requiredFieldEmpty: "Le numéro de téléphone est obligatoire",
|
|
41
|
+
openCountrySelector: "Ouvrir le sélecteur de pays"
|
|
42
|
+
},
|
|
43
|
+
"nl-BE": {
|
|
44
|
+
searchCountryPlaceholder: "Zoek land...",
|
|
45
|
+
noCountriesFound: "Geen landen gevonden",
|
|
46
|
+
enterPhoneNumberPlaceholder: "Voer uw telefoonnummer in",
|
|
47
|
+
numberLooksIncomplete: "Voer een geldig telefoonnummer in",
|
|
48
|
+
requiredFieldEmpty: "Telefoonnummer is verplicht",
|
|
49
|
+
openCountrySelector: "Landselector openen"
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
n as translations
|
|
54
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { InputProps } from '../input/index.js';
|
|
2
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
3
|
+
import { ChangeEvent, FocusEvent, Ref } from 'react';
|
|
4
|
+
import { Locales } from './translations.js';
|
|
5
|
+
export type { CountryCode };
|
|
6
|
+
/**
|
|
7
|
+
* Phone number validation result. `isValid` is the bare fact (reveal-independent, drives e.g. a
|
|
8
|
+
* submit button); `errorMessage` is the localized reason, present only when a failure is revealed.
|
|
9
|
+
*/
|
|
10
|
+
export type PhoneValidationResult = {
|
|
11
|
+
isValid: boolean;
|
|
12
|
+
errorMessage?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Props produced by `usePhoneInput().inputProps` and spread onto `<PhoneInput>`.
|
|
16
|
+
* `PhoneInput` is presentational — it is always driven by these.
|
|
17
|
+
*/
|
|
18
|
+
export type PhoneInputControlProps = {
|
|
19
|
+
/** Current display value (the user's spacing preserved while typing). */
|
|
20
|
+
value: string;
|
|
21
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
22
|
+
onBlur: (e: FocusEvent<HTMLInputElement>) => void;
|
|
23
|
+
/** Currently selected country. */
|
|
24
|
+
country: CountryCode;
|
|
25
|
+
onCountryChange: (country: CountryCode) => void;
|
|
26
|
+
/** Whether the typed "+" prefix matches no known calling code (show the generic icon). */
|
|
27
|
+
unknownPrefix: boolean;
|
|
28
|
+
/** Localized message for the current invalid state, rendered in the error message slot. */
|
|
29
|
+
errorMessage?: string;
|
|
30
|
+
/** Locale for translations. */
|
|
31
|
+
locale: Locales;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Phone input component props. Spread `usePhoneInput().inputProps` and add presentational props.
|
|
35
|
+
*/
|
|
36
|
+
export type PhoneInputProps = PhoneInputControlProps & Pick<InputProps, "variant" | "placeholder" | "name" | "autoComplete" | "autoFocus"> & {
|
|
37
|
+
/** Size of the input and country selector. Defaults to "md". */
|
|
38
|
+
size?: "sm" | "md" | "lg" | "xl";
|
|
39
|
+
/** Disable the input + country selector. Falls back to the surrounding FormControl. */
|
|
40
|
+
isDisabled?: boolean;
|
|
41
|
+
/** Make the input read-only. Falls back to the surrounding FormControl. */
|
|
42
|
+
isReadOnly?: boolean;
|
|
43
|
+
ref?: Ref<HTMLInputElement>;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/components/phone-input/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,YAAY,EAAE,WAAW,EAAE,CAAC;AAE5B;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACpC,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACrD,MAAM,EAAE,CAAC,CAAC,EAAE,UAAU,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAClD,kCAAkC;IAClC,OAAO,EAAE,WAAW,CAAC;IACrB,eAAe,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IAChD,0FAA0F;IAC1F,aAAa,EAAE,OAAO,CAAC;IACvB,2FAA2F;IAC3F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,sBAAsB,GACnD,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,aAAa,GAAG,MAAM,GAAG,cAAc,GAAG,WAAW,CAAC,GAAG;IACrF,gEAAgE;IAChE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IACjC,uFAAuF;IACvF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC5B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
2
|
+
import { Locales } from './translations.js';
|
|
3
|
+
import { PhoneInputControlProps, PhoneValidationResult } from './types.js';
|
|
4
|
+
export type UsePhoneInputOptions = {
|
|
5
|
+
/** Initial country. Defaults to device locale, then the locale-prop region. */
|
|
6
|
+
defaultCountry?: CountryCode;
|
|
7
|
+
/** Initial display value. Defaults to the bare dial-code prefix. */
|
|
8
|
+
defaultValue?: string;
|
|
9
|
+
/** Whether the field is required. */
|
|
10
|
+
isRequired?: boolean;
|
|
11
|
+
/** Extra rule on the E.164 value once it's otherwise valid; return an error message to fail. Surfaces on blur/validate(). */
|
|
12
|
+
customValidator?: (e164: string) => string | undefined;
|
|
13
|
+
/** Locale for translations and messages. Defaults to "en-US". */
|
|
14
|
+
locale?: Locales;
|
|
15
|
+
};
|
|
16
|
+
export type UsePhoneInputReturn = {
|
|
17
|
+
/** Spread onto `<PhoneInput>`. */
|
|
18
|
+
inputProps: PhoneInputControlProps;
|
|
19
|
+
/** Spread onto the surrounding `<FormControl>`. */
|
|
20
|
+
formControlProps: {
|
|
21
|
+
isRequired: boolean;
|
|
22
|
+
isInvalid: boolean;
|
|
23
|
+
};
|
|
24
|
+
/** Current display value (the user's spacing preserved while typing, formatted on blur). */
|
|
25
|
+
value: string;
|
|
26
|
+
/** Canonical E.164 value for storage/submission (e.g. "+46737884410"); "" when empty. */
|
|
27
|
+
e164: string;
|
|
28
|
+
/** Current country. */
|
|
29
|
+
country: CountryCode;
|
|
30
|
+
/** Whether the current e164 is a valid number (independent of whether an error is shown). */
|
|
31
|
+
isValid: boolean;
|
|
32
|
+
/** Change the selected country, reformatting the current number into it. Does not reveal errors. */
|
|
33
|
+
setCountry: (country: CountryCode) => void;
|
|
34
|
+
/** Set the display value programmatically (prefill an existing number / clear). Like typing, this will update the country if a "+"-prefixed value is provided. */
|
|
35
|
+
setValue: (value: string) => void;
|
|
36
|
+
/** Reveal validation and return a fresh result. Call from `onSubmit` to gate submission. */
|
|
37
|
+
validate: () => PhoneValidationResult;
|
|
38
|
+
/** Reset to the initial value. */
|
|
39
|
+
reset: () => void;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Headless hook owning phone-input value + validation state. The display string is the single
|
|
43
|
+
* source of truth; `e164` is derived. `<PhoneInput>` is presentational — spread `inputProps` onto
|
|
44
|
+
* it and `formControlProps` onto the surrounding `<FormControl>`.
|
|
45
|
+
*
|
|
46
|
+
* @see Docs https://caspeco.github.io/casper-ui-library/components/phone-input
|
|
47
|
+
*/
|
|
48
|
+
export declare function usePhoneInput(options?: UsePhoneInputOptions): UsePhoneInputReturn;
|
|
49
|
+
//# sourceMappingURL=use-phone-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-phone-input.d.ts","sourceRoot":"","sources":["../../../lib/components/phone-input/use-phone-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAa5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAK7E,MAAM,MAAM,oBAAoB,GAAG;IAClC,+EAA+E;IAC/E,cAAc,CAAC,EAAE,WAAW,CAAC;IAE7B,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,qCAAqC;IACrC,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,6HAA6H;IAC7H,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAEvD,iEAAiE;IACjE,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IACjC,kCAAkC;IAClC,UAAU,EAAE,sBAAsB,CAAC;IAEnC,mDAAmD;IACnD,gBAAgB,EAAE;QAAE,UAAU,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;IAE9D,4FAA4F;IAC5F,KAAK,EAAE,MAAM,CAAC;IAEd,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;IAEb,uBAAuB;IACvB,OAAO,EAAE,WAAW,CAAC;IAErB,6FAA6F;IAC7F,OAAO,EAAE,OAAO,CAAC;IAEjB,oGAAoG;IACpG,UAAU,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;IAE3C,kKAAkK;IAClK,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAElC,4FAA4F;IAC5F,QAAQ,EAAE,MAAM,qBAAqB,CAAC;IAEtC,kCAAkC;IAClC,KAAK,EAAE,MAAM,IAAI,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,mBAAmB,CA2HrF"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { c as ce } from "../../_virtual/compiler-runtime.js";
|
|
2
|
+
import { useState as g } from "react";
|
|
3
|
+
import { toE164 as ne, isUnknownCallingCode as ue, detectCountryFromInput as fe, resolveInitialCountry as de, validatePhoneNumber as me, detectCountryChange as le, isIncompletePhoneNumber as Ce, formatPhoneNumber as ie, extractNationalNumber as Ve } from "./phone-input-helpers.js";
|
|
4
|
+
import { getCountryCallingCode as re } from "../../node_modules/libphonenumber-js/min/exports/getCountryCallingCode.js";
|
|
5
|
+
const he = /[^\d+\s\-().]/g;
|
|
6
|
+
function Ne(p) {
|
|
7
|
+
const e = ce.c(71);
|
|
8
|
+
let v;
|
|
9
|
+
e[0] !== p ? (v = p === void 0 ? {} : p, e[0] = p, e[1] = v) : v = e[1];
|
|
10
|
+
const ae = v, {
|
|
11
|
+
defaultCountry: z,
|
|
12
|
+
defaultValue: c,
|
|
13
|
+
isRequired: oe,
|
|
14
|
+
customValidator: y,
|
|
15
|
+
locale: se
|
|
16
|
+
} = ae, f = oe === void 0 ? !1 : oe, i = se === void 0 ? "en-US" : se;
|
|
17
|
+
let N;
|
|
18
|
+
e[2] !== z || e[3] !== c || e[4] !== i ? (N = () => {
|
|
19
|
+
if (c?.trim().startsWith("+")) {
|
|
20
|
+
const s = fe(c);
|
|
21
|
+
if (s)
|
|
22
|
+
return s;
|
|
23
|
+
}
|
|
24
|
+
return de(z, i);
|
|
25
|
+
}, e[2] = z, e[3] = c, e[4] = i, e[5] = N) : N = e[5];
|
|
26
|
+
const [u] = g(N);
|
|
27
|
+
let P;
|
|
28
|
+
e[6] !== c || e[7] !== u ? (P = () => c ?? `+${re(u)}`, e[6] = c, e[7] = u, e[8] = P) : P = e[8];
|
|
29
|
+
const [R] = g(P), [o, V] = g(R), [t, E] = g(u), [G, L] = g(!1);
|
|
30
|
+
let I;
|
|
31
|
+
e[9] !== t || e[10] !== o ? (I = ne(o, t), e[9] = t, e[10] = o, e[11] = I) : I = e[11];
|
|
32
|
+
const O = I;
|
|
33
|
+
let b;
|
|
34
|
+
e[12] !== o ? (b = ue(o), e[12] = o, e[13] = b) : b = e[13];
|
|
35
|
+
const W = b;
|
|
36
|
+
let M;
|
|
37
|
+
e[14] !== y || e[15] !== f || e[16] !== i ? (M = (s, n, l) => {
|
|
38
|
+
const a = me(s, n, {
|
|
39
|
+
isRequired: f,
|
|
40
|
+
showValidation: l,
|
|
41
|
+
locale: i
|
|
42
|
+
});
|
|
43
|
+
if (a.isValid && y) {
|
|
44
|
+
const H = y(ne(s, n));
|
|
45
|
+
if (H)
|
|
46
|
+
return {
|
|
47
|
+
isValid: !1,
|
|
48
|
+
errorMessage: l ? H : void 0
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return a;
|
|
52
|
+
}, e[14] = y, e[15] = f, e[16] = i, e[17] = M) : M = e[17];
|
|
53
|
+
const d = M;
|
|
54
|
+
let _;
|
|
55
|
+
e[18] !== t || e[19] !== d || e[20] !== G || e[21] !== o ? (_ = d(o, t, G), e[18] = t, e[19] = d, e[20] = G, e[21] = o, e[22] = _) : _ = e[22];
|
|
56
|
+
const h = _;
|
|
57
|
+
let S;
|
|
58
|
+
e[23] !== d ? (S = (s, n) => {
|
|
59
|
+
const l = d(s, n, !0);
|
|
60
|
+
return L(l.errorMessage !== void 0), l;
|
|
61
|
+
}, e[23] = d, e[24] = S) : S = e[24];
|
|
62
|
+
const r = S;
|
|
63
|
+
let w;
|
|
64
|
+
e[25] !== t ? (w = (s) => {
|
|
65
|
+
const n = s.target.value.replace(he, "");
|
|
66
|
+
V(n);
|
|
67
|
+
let l = t;
|
|
68
|
+
const a = le(n, t);
|
|
69
|
+
a && (E(a), l = a), L((H) => H && Ce(n, l));
|
|
70
|
+
}, e[25] = t, e[26] = w) : w = e[26];
|
|
71
|
+
const X = w;
|
|
72
|
+
let x;
|
|
73
|
+
e[27] !== t || e[28] !== r || e[29] !== o ? (x = () => {
|
|
74
|
+
const s = ie(o, t);
|
|
75
|
+
r(s, t), s !== o && V(s);
|
|
76
|
+
}, e[27] = t, e[28] = r, e[29] = o, e[30] = x) : x = e[30];
|
|
77
|
+
const j = x;
|
|
78
|
+
let B;
|
|
79
|
+
e[31] !== t || e[32] !== r || e[33] !== o ? (B = (s, n) => {
|
|
80
|
+
const l = Ve(o, t), a = l ? ie(l, s) : `+${re(s)}`;
|
|
81
|
+
E(s), V(a), n && l && r(a, s);
|
|
82
|
+
}, e[31] = t, e[32] = r, e[33] = o, e[34] = B) : B = e[34];
|
|
83
|
+
const m = B;
|
|
84
|
+
let U;
|
|
85
|
+
e[35] !== m ? (U = (s) => m(s, !0), e[35] = m, e[36] = U) : U = e[36];
|
|
86
|
+
const J = U;
|
|
87
|
+
let $;
|
|
88
|
+
e[37] !== t || e[38] !== r || e[39] !== o ? ($ = () => r(o, t), e[37] = t, e[38] = r, e[39] = o, e[40] = $) : $ = e[40];
|
|
89
|
+
const K = $;
|
|
90
|
+
let k;
|
|
91
|
+
e[41] !== u || e[42] !== R ? (k = () => {
|
|
92
|
+
V(R), E(u), L(!1);
|
|
93
|
+
}, e[41] = u, e[42] = R, e[43] = k) : k = e[43];
|
|
94
|
+
const Q = k;
|
|
95
|
+
let q;
|
|
96
|
+
e[44] !== t ? (q = (s) => {
|
|
97
|
+
V(s);
|
|
98
|
+
const n = le(s, t);
|
|
99
|
+
n && E(n);
|
|
100
|
+
}, e[44] = t, e[45] = q) : q = e[45];
|
|
101
|
+
const T = q, Y = h.errorMessage !== void 0, Z = h.errorMessage;
|
|
102
|
+
let A;
|
|
103
|
+
e[46] !== t || e[47] !== Z || e[48] !== j || e[49] !== X || e[50] !== J || e[51] !== i || e[52] !== W || e[53] !== o ? (A = {
|
|
104
|
+
value: o,
|
|
105
|
+
onChange: X,
|
|
106
|
+
onBlur: j,
|
|
107
|
+
country: t,
|
|
108
|
+
onCountryChange: J,
|
|
109
|
+
unknownPrefix: W,
|
|
110
|
+
errorMessage: Z,
|
|
111
|
+
locale: i
|
|
112
|
+
}, e[46] = t, e[47] = Z, e[48] = j, e[49] = X, e[50] = J, e[51] = i, e[52] = W, e[53] = o, e[54] = A) : A = e[54];
|
|
113
|
+
const ee = A;
|
|
114
|
+
let D;
|
|
115
|
+
e[55] !== Y || e[56] !== f ? (D = {
|
|
116
|
+
isRequired: f,
|
|
117
|
+
isInvalid: Y
|
|
118
|
+
}, e[55] = Y, e[56] = f, e[57] = D) : D = e[57];
|
|
119
|
+
const te = D;
|
|
120
|
+
let C;
|
|
121
|
+
e[58] !== m ? (C = (s) => m(s, !1), e[58] = m, e[59] = C) : C = e[59];
|
|
122
|
+
let F;
|
|
123
|
+
return e[60] !== t || e[61] !== O || e[62] !== te || e[63] !== ee || e[64] !== Q || e[65] !== T || e[66] !== C || e[67] !== K || e[68] !== h.isValid || e[69] !== o ? (F = {
|
|
124
|
+
inputProps: ee,
|
|
125
|
+
formControlProps: te,
|
|
126
|
+
value: o,
|
|
127
|
+
e164: O,
|
|
128
|
+
country: t,
|
|
129
|
+
isValid: h.isValid,
|
|
130
|
+
setCountry: C,
|
|
131
|
+
setValue: T,
|
|
132
|
+
validate: K,
|
|
133
|
+
reset: Q
|
|
134
|
+
}, e[60] = t, e[61] = O, e[62] = te, e[63] = ee, e[64] = Q, e[65] = T, e[66] = C, e[67] = K, e[68] = h.isValid, e[69] = o, e[70] = F) : F = e[70], F;
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
Ne as usePhoneInput
|
|
138
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-phone-input.spec.d.ts","sourceRoot":"","sources":["../../../lib/components/phone-input/use-phone-input.spec.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Return value of {@link useMeasuredWidth}: the ref to attach to the element, and its
|
|
4
|
+
* current width in px (`null` until measured, or while inactive).
|
|
5
|
+
*/
|
|
6
|
+
export type MeasuredWidth<T extends HTMLElement = HTMLElement> = readonly [
|
|
7
|
+
ref: RefObject<T | null>,
|
|
8
|
+
width: number | null
|
|
9
|
+
];
|
|
10
|
+
/**
|
|
11
|
+
* Tracks the rendered width (in px) of an element.
|
|
12
|
+
*
|
|
13
|
+
* Measuring inside a layout effect commits the width *before* the browser paints, and a
|
|
14
|
+
* ResizeObserver keeps it in sync as the element later resizes — so consumers get a correct
|
|
15
|
+
* value on the first frame with no visible flash.
|
|
16
|
+
*
|
|
17
|
+
* @param active - Whether to measure. Pass `false` to skip work while the element is absent;
|
|
18
|
+
* the width resets to `null`.
|
|
19
|
+
* @returns A tuple of the ref to attach to the element and its current width (`null` until
|
|
20
|
+
* measured, or while inactive).
|
|
21
|
+
*/
|
|
22
|
+
export declare function useMeasuredWidth<T extends HTMLElement = HTMLElement>(active?: boolean): MeasuredWidth<T>;
|
|
23
|
+
//# sourceMappingURL=use-measured-width.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-measured-width.d.ts","sourceRoot":"","sources":["../../lib/hooks/use-measured-width.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,IAAI,SAAS;IACzE,GAAG,EAAE,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,GAAG,IAAI;CACpB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,MAAM,UAAO,GAAG,aAAa,CAAC,CAAC,CAAC,CAkBrG"}
|