@flipdish/ui-library 0.63.0 → 0.64.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/README.md +12 -11
- package/dist/components/__internal__/listOption/listOption.styles.cjs +20 -0
- package/dist/components/__internal__/listOption/listOption.styles.cjs.map +1 -0
- package/dist/components/__internal__/listOption/listOption.styles.d.ts +16 -0
- package/dist/components/__internal__/listOption/listOption.styles.d.ts.map +1 -0
- package/dist/components/__internal__/listOption/listOption.styles.js +18 -0
- package/dist/components/__internal__/listOption/listOption.styles.js.map +1 -0
- package/dist/components/atoms/PhoneInput/components/PhoneInputCountrySelect.cjs +35 -0
- package/dist/components/atoms/PhoneInput/components/PhoneInputCountrySelect.cjs.map +1 -0
- package/dist/components/atoms/PhoneInput/components/PhoneInputCountrySelect.d.ts +24 -0
- package/dist/components/atoms/PhoneInput/components/PhoneInputCountrySelect.d.ts.map +1 -0
- package/dist/components/atoms/PhoneInput/components/PhoneInputCountrySelect.js +33 -0
- package/dist/components/atoms/PhoneInput/components/PhoneInputCountrySelect.js.map +1 -0
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.cjs +100 -0
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.cjs.map +1 -0
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.d.ts +35 -0
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.d.ts.map +1 -0
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.js +98 -0
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.js.map +1 -0
- package/dist/components/atoms/PhoneInput/index.cjs +79 -0
- package/dist/components/atoms/PhoneInput/index.cjs.map +1 -0
- package/dist/components/atoms/PhoneInput/index.d.ts +48 -0
- package/dist/components/atoms/PhoneInput/index.d.ts.map +1 -0
- package/dist/components/atoms/PhoneInput/index.js +77 -0
- package/dist/components/atoms/PhoneInput/index.js.map +1 -0
- package/dist/components/atoms/PhoneInput/phoneInput.types.d.ts +17 -0
- package/dist/components/atoms/PhoneInput/phoneInput.types.d.ts.map +1 -0
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.cjs +304 -0
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.cjs.map +1 -0
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.d.ts +147 -0
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.d.ts.map +1 -0
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.js +288 -0
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs +10 -1
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs.map +1 -1
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts.map +1 -1
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js +10 -1
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js.map +1 -1
- package/dist/components/forms/fields/FormPhoneInput/index.cjs +36 -0
- package/dist/components/forms/fields/FormPhoneInput/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormPhoneInput/index.d.ts +19 -0
- package/dist/components/forms/fields/FormPhoneInput/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormPhoneInput/index.js +34 -0
- package/dist/components/forms/fields/FormPhoneInput/index.js.map +1 -0
- package/dist/components/forms/validation/index.cjs +25 -56
- package/dist/components/forms/validation/index.cjs.map +1 -1
- package/dist/components/forms/validation/index.d.ts +2 -12
- package/dist/components/forms/validation/index.d.ts.map +1 -1
- package/dist/components/forms/validation/index.js +1 -32
- package/dist/components/forms/validation/index.js.map +1 -1
- package/dist/components/forms/validation/phoneNumber/index.cjs +20 -0
- package/dist/components/forms/validation/phoneNumber/index.cjs.map +1 -0
- package/dist/components/forms/validation/phoneNumber/index.d.ts +14 -0
- package/dist/components/forms/validation/phoneNumber/index.d.ts.map +1 -0
- package/dist/components/forms/validation/phoneNumber/index.js +18 -0
- package/dist/components/forms/validation/phoneNumber/index.js.map +1 -0
- package/dist/components/forms/validation/utilities/validation.utils.cjs +34 -0
- package/dist/components/forms/validation/utilities/validation.utils.cjs.map +1 -1
- package/dist/components/forms/validation/utilities/validation.utils.d.ts +29 -1
- package/dist/components/forms/validation/utilities/validation.utils.d.ts.map +1 -1
- package/dist/components/forms/validation/utilities/validation.utils.js +33 -2
- package/dist/components/forms/validation/utilities/validation.utils.js.map +1 -1
- package/dist/components/forms/validation/validation.types.d.ts +10 -0
- package/dist/components/forms/validation/validation.types.d.ts.map +1 -1
- package/dist/components/molecules/Selects/Select/components/Popover.cjs +2 -3
- package/dist/components/molecules/Selects/Select/components/Popover.cjs.map +1 -1
- package/dist/components/molecules/Selects/Select/components/Popover.d.ts.map +1 -1
- package/dist/components/molecules/Selects/Select/components/Popover.js +2 -3
- package/dist/components/molecules/Selects/Select/components/Popover.js.map +1 -1
- package/dist/components/molecules/Selects/components/SelectItem.cjs +2 -1
- package/dist/components/molecules/Selects/components/SelectItem.cjs.map +1 -1
- package/dist/components/molecules/Selects/components/SelectItem.d.ts.map +1 -1
- package/dist/components/molecules/Selects/components/SelectItem.js +2 -1
- package/dist/components/molecules/Selects/components/SelectItem.js.map +1 -1
- package/dist/native/components/atoms/PhoneInput/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormPhoneInput/index.d.ts +12 -0
- package/dist/native/components/forms/validation/phoneNumber/index.d.ts +12 -0
- package/package.json +6 -1
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { isSupportedCountry, getCountries, getCountryCallingCode, getExampleNumber, AsYouType, parseDigits } from 'libphonenumber-js/min';
|
|
2
|
+
import metadata from 'libphonenumber-js/min/metadata';
|
|
3
|
+
import examples from 'libphonenumber-js/mobile/examples';
|
|
4
|
+
import { getCountryName } from '../../Flag/flag.utils.js';
|
|
5
|
+
|
|
6
|
+
// Where an empty field starts when neither the app nor the user's locale names a country.
|
|
7
|
+
const FALLBACK_COUNTRY = 'IE';
|
|
8
|
+
/**
|
|
9
|
+
* Reads the characters of a phone number that count: its digits, in any script, and a plus only where it leads.
|
|
10
|
+
*
|
|
11
|
+
* @param text The number as typed or pasted, with any spaces, brackets and dashes.
|
|
12
|
+
* @returns The digits as ASCII, after a leading plus when the text has one before any digit.
|
|
13
|
+
*/
|
|
14
|
+
const significantChars = (text) => {
|
|
15
|
+
let significant = '';
|
|
16
|
+
for (const char of text) {
|
|
17
|
+
if (char === '+') {
|
|
18
|
+
if (significant === '')
|
|
19
|
+
significant = '+';
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
significant += parseDigits(char);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return significant;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Finds where the cursor belongs in a formatted number, so it stays beside the digit the user was at when the spacing changes.
|
|
29
|
+
*
|
|
30
|
+
* @param text The formatted number.
|
|
31
|
+
* @param position How many significant characters sit before the cursor.
|
|
32
|
+
* @returns The index in `text` just after that many significant characters: before the first one for none, and the end once every one is passed.
|
|
33
|
+
*/
|
|
34
|
+
const caretAfter = (text, position) => {
|
|
35
|
+
let seen = 0;
|
|
36
|
+
for (let index = 0; index < text.length; index++) {
|
|
37
|
+
const isSignificant = /\d/.test(text[index]) || (text[index] === '+' && seen === 0);
|
|
38
|
+
if (!isSignificant)
|
|
39
|
+
continue;
|
|
40
|
+
if (position <= 0)
|
|
41
|
+
return index;
|
|
42
|
+
seen++;
|
|
43
|
+
if (seen === position)
|
|
44
|
+
return /\d/.test(text.slice(index + 1)) ? index + 1 : text.length;
|
|
45
|
+
}
|
|
46
|
+
return text.length;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Reads an edit to the formatted number as an edit to its digits. A delete that took only a space or a bracket would
|
|
50
|
+
* format back to the same text, so it takes the digit beside it instead.
|
|
51
|
+
*
|
|
52
|
+
* @param edit The text before and after the edit, the cursor and the kind of edit.
|
|
53
|
+
* @returns The significant characters after the edit, and how many of them sit before the cursor.
|
|
54
|
+
*/
|
|
55
|
+
const editedDigits = ({ previous, next, caret, inputType }) => {
|
|
56
|
+
const significant = significantChars(next);
|
|
57
|
+
const position = significantChars(next.slice(0, caret)).length;
|
|
58
|
+
const isDelete = inputType ? inputType.startsWith('delete') : next.length < previous.length;
|
|
59
|
+
if (!isDelete || significant !== significantChars(previous))
|
|
60
|
+
return { significant, position };
|
|
61
|
+
const isForward = inputType === 'deleteContentForward';
|
|
62
|
+
const index = isForward ? position : position - 1;
|
|
63
|
+
if (index < 0 || index >= significant.length)
|
|
64
|
+
return { significant, position };
|
|
65
|
+
return { significant: significant.slice(0, index) + significant.slice(index + 1), position: index };
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Formats a number as it is typed, in a country's national style, or internationally when it starts with a plus.
|
|
69
|
+
*
|
|
70
|
+
* @param country The country whose style applies.
|
|
71
|
+
* @param significant The digits typed so far, after a plus for an international number.
|
|
72
|
+
* @returns The number spaced as that country writes it, as far as it has been typed. Digits typed without the country's
|
|
73
|
+
* trunk prefix, as after a calling code, are spaced as the international form spaces them.
|
|
74
|
+
*/
|
|
75
|
+
const formatTyped = (country, significant) => {
|
|
76
|
+
const national = new AsYouType(country).input(significant);
|
|
77
|
+
if (significant.startsWith('+') || national !== significant)
|
|
78
|
+
return national;
|
|
79
|
+
// The national format of many countries needs the trunk prefix, so a number typed without it would get no spacing at all.
|
|
80
|
+
const callingCode = getCountryCallingCode(country);
|
|
81
|
+
return new AsYouType().input(`+${callingCode}${significant}`).replace(`+${callingCode}`, '').trim();
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Writes what the field shows as one international number, the form an API stores.
|
|
85
|
+
*
|
|
86
|
+
* @param entry The chosen country and the number as typed.
|
|
87
|
+
* @returns The number in E.164 form, such as `+353861234567`, as far as it has been typed, or `''` before any digit that counts.
|
|
88
|
+
*/
|
|
89
|
+
const toInternational = ({ country, text }) => {
|
|
90
|
+
const typed = new AsYouType(country);
|
|
91
|
+
typed.input(text);
|
|
92
|
+
return typed.getNumber()?.number ?? '';
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Finds the calling code a run of digits starts with. No calling code starts with another, so the first match is the code.
|
|
96
|
+
*
|
|
97
|
+
* @param digits The digits after a plus.
|
|
98
|
+
* @returns The calling code, or `undefined` while the digits are not yet one.
|
|
99
|
+
*/
|
|
100
|
+
const leadingCallingCode = (digits) => {
|
|
101
|
+
for (let length = 1; length <= Math.min(3, digits.length); length++) {
|
|
102
|
+
const code = digits.slice(0, length);
|
|
103
|
+
if (code in metadata.country_calling_codes)
|
|
104
|
+
return code;
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Picks the country an international number belongs to. The library tells most numbers apart by their digits, such as
|
|
110
|
+
* a Canadian or a Jamaican number on +1; where it cannot, as for a number not yet whole, the country the field is on
|
|
111
|
+
* stays when it uses the calling code, and otherwise the code's main country.
|
|
112
|
+
*
|
|
113
|
+
* @param international The number, after a plus.
|
|
114
|
+
* @param current The country the field is on.
|
|
115
|
+
* @param allowed The countries the field offers, when the app restricts them.
|
|
116
|
+
* @returns The country, or `undefined` for a number with no calling code yet or one only countries the field does not offer use.
|
|
117
|
+
*/
|
|
118
|
+
const countryForNumber = (international, current, allowed) => {
|
|
119
|
+
const typed = new AsYouType();
|
|
120
|
+
typed.input(international);
|
|
121
|
+
const callingCode = typed.getCallingCode();
|
|
122
|
+
if (!callingCode)
|
|
123
|
+
return undefined;
|
|
124
|
+
const possible = typed.getNumber()?.getPossibleCountries() ?? [];
|
|
125
|
+
// The library lists a code's main country first.
|
|
126
|
+
const sharing = (metadata.country_calling_codes[callingCode] ?? []).filter((code) => isSupportedCountry(code));
|
|
127
|
+
const candidates = (possible.length > 0 ? possible : sharing).filter((code) => !allowed || allowed.includes(code));
|
|
128
|
+
return candidates.includes(current) ? current : candidates[0];
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Reads an international number as the country and national number the field shows, for a saved value or one pasted whole.
|
|
132
|
+
*
|
|
133
|
+
* @param value The number, with its plus and calling code.
|
|
134
|
+
* @param current The country the field is on, kept where the number could belong to it.
|
|
135
|
+
* @param allowed The countries the field offers, when the app restricts them.
|
|
136
|
+
* @returns The country and the number in its national format, or `undefined` for a value that is not an international
|
|
137
|
+
* number or belongs to a country the field does not offer.
|
|
138
|
+
*/
|
|
139
|
+
const fromInternational = (value, current, allowed) => {
|
|
140
|
+
const significant = significantChars(value);
|
|
141
|
+
const country = significant.startsWith('+') ? countryForNumber(significant, current, allowed) : undefined;
|
|
142
|
+
if (!country)
|
|
143
|
+
return undefined;
|
|
144
|
+
const typed = new AsYouType();
|
|
145
|
+
typed.input(significant);
|
|
146
|
+
const number = typed.getNumber();
|
|
147
|
+
// A whole number is written the way the country writes it, with its trunk prefix; a partial one has no such form yet.
|
|
148
|
+
const text = number?.isPossible() ? number.formatNational() : formatTyped(country, number?.nationalNumber ?? '');
|
|
149
|
+
return { country, text };
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Gives the national digits of an international number, as a country switch keeps them.
|
|
153
|
+
*
|
|
154
|
+
* @param international The number, after a plus.
|
|
155
|
+
* @returns The digits after the calling code, or `''` before the code is whole.
|
|
156
|
+
*/
|
|
157
|
+
const nationalDigits = (international) => {
|
|
158
|
+
const typed = new AsYouType();
|
|
159
|
+
typed.input(international);
|
|
160
|
+
return typed.getNumber()?.nationalNumber ?? '';
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Rewrites a number typed with a country's international dialling prefix, such as `00` in Ireland or `011` in the
|
|
164
|
+
* United States, with a plus in its place.
|
|
165
|
+
*
|
|
166
|
+
* @param country The country whose dialling prefix applies.
|
|
167
|
+
* @param significant The digits typed.
|
|
168
|
+
* @param position How many of them sit before the cursor.
|
|
169
|
+
* @returns The number after a plus with the cursor moved to match, `pending` while only the prefix or part of a calling
|
|
170
|
+
* code is typed, or `undefined` for digits that do not start with the prefix.
|
|
171
|
+
*/
|
|
172
|
+
const fromDiallingPrefix = (country, significant, position) => {
|
|
173
|
+
const typed = new AsYouType(country);
|
|
174
|
+
typed.input(significant);
|
|
175
|
+
if (!typed.isInternational())
|
|
176
|
+
return undefined;
|
|
177
|
+
const callingCode = typed.getCallingCode();
|
|
178
|
+
if (!callingCode)
|
|
179
|
+
return 'pending';
|
|
180
|
+
const international = `+${callingCode}${typed.getNumber()?.nationalNumber ?? ''}`;
|
|
181
|
+
// The prefix gives way to a single plus, so the cursor moves back by the rest of it.
|
|
182
|
+
const prefixLength = significant.length - (international.length - 1);
|
|
183
|
+
return { significant: international, position: Math.max(1, position - prefixLength + 1) };
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Works out what the field shows after an edit. National digits are formatted for the country the field is on. A plus,
|
|
187
|
+
* or the country's own dialling prefix such as `00`, starts an international number: once the digits before the cursor
|
|
188
|
+
* hold a whole calling code, the field moves to that code's country and keeps the rest as the national number.
|
|
189
|
+
*
|
|
190
|
+
* @param country The country the field is on.
|
|
191
|
+
* @param significant The significant characters in the field after the edit.
|
|
192
|
+
* @param position How many of them sit before the cursor.
|
|
193
|
+
* @param allowed The countries the field offers, when the app restricts them.
|
|
194
|
+
* @returns The country, text and cursor position to show, or `undefined` while a calling code is still being typed, when
|
|
195
|
+
* the text should stay as the user wrote it. A number from a country the field does not offer stays international.
|
|
196
|
+
*/
|
|
197
|
+
const entryFor = (country, significant, position, allowed) => {
|
|
198
|
+
let digits = significant;
|
|
199
|
+
let cursor = position;
|
|
200
|
+
if (!digits.startsWith('+')) {
|
|
201
|
+
const dialled = fromDiallingPrefix(country, digits, cursor);
|
|
202
|
+
if (dialled === 'pending')
|
|
203
|
+
return undefined;
|
|
204
|
+
if (!dialled)
|
|
205
|
+
return { country, text: formatTyped(country, digits), position: cursor };
|
|
206
|
+
({ significant: digits, position: cursor } = dialled);
|
|
207
|
+
}
|
|
208
|
+
// Only the digits between the plus and the cursor name the country, so a plus typed before a number does not read its digits as a code.
|
|
209
|
+
const before = digits.slice(1, Math.max(1, cursor));
|
|
210
|
+
const callingCode = leadingCallingCode(before);
|
|
211
|
+
if (!callingCode)
|
|
212
|
+
return undefined;
|
|
213
|
+
const entry = fromInternational(digits, country, allowed);
|
|
214
|
+
if (!entry)
|
|
215
|
+
return { country, text: formatTyped(country, digits), position: cursor };
|
|
216
|
+
// The national digits before the cursor, shifted by any trunk prefix the national format adds in front of them.
|
|
217
|
+
const nationalLength = digits.length - 1 - callingCode.length;
|
|
218
|
+
const trunkLength = significantChars(entry.text).length - nationalLength;
|
|
219
|
+
return { ...entry, position: before.length - callingCode.length + Math.max(0, trunkLength) };
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Lists the countries the field offers, named and sorted for the user's language.
|
|
223
|
+
*
|
|
224
|
+
* @param locale The user's locale, which names and orders the countries.
|
|
225
|
+
* @param allowed The countries to offer; every country the library knows without it. A code the library does not know is left out.
|
|
226
|
+
* @returns Each country with its name and calling code, in the locale's alphabetical order.
|
|
227
|
+
*/
|
|
228
|
+
const countryOptions = (locale, allowed) => {
|
|
229
|
+
// Called with the code alone: `filter` would hand the library its index as a second argument.
|
|
230
|
+
const codes = allowed ? allowed.filter((code) => isSupportedCountry(code)) : getCountries();
|
|
231
|
+
const { compare } = new Intl.Collator(locale);
|
|
232
|
+
return codes
|
|
233
|
+
.map((code) => ({ code, name: getCountryName(code, locale), callingCode: getCountryCallingCode(code) }))
|
|
234
|
+
.sort((first, second) => compare(first.name, second.name));
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Gives a number that shows a country's format, for the field's placeholder.
|
|
238
|
+
*
|
|
239
|
+
* @param country The country to show.
|
|
240
|
+
* @returns A mobile number in that country's national format, or `''` when the library has none.
|
|
241
|
+
*/
|
|
242
|
+
const exampleNumber = (country) => getExampleNumber(country, examples)?.formatNational() ?? '';
|
|
243
|
+
// Reads the tag's region alone, so neither an extension key (`en-u-ca-gregory`) nor a POSIX codeset (`en_US.UTF-8`) is taken for one.
|
|
244
|
+
const localeRegion = (locale) => {
|
|
245
|
+
try {
|
|
246
|
+
return new Intl.Locale(locale.replace(/[.@].*$/, '').replace(/_/g, '-')).region;
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* Picks the country an empty field starts on.
|
|
254
|
+
*
|
|
255
|
+
* @param requested The country the app asked for, if any.
|
|
256
|
+
* @param locale The user's locale, such as `en-IE`.
|
|
257
|
+
* @param allowed The countries the field offers, in the order the app passed them, when it restricts them.
|
|
258
|
+
* @returns The requested country when the field offers it, else the region the locale names when the field offers it,
|
|
259
|
+
* else the first country offered, else Ireland.
|
|
260
|
+
*/
|
|
261
|
+
const startingCountry = (requested, locale, allowed) => {
|
|
262
|
+
const isOffered = (code) => Boolean(code) && isSupportedCountry(code) && (!allowed || allowed.includes(code));
|
|
263
|
+
if (isOffered(requested))
|
|
264
|
+
return requested;
|
|
265
|
+
const region = localeRegion(locale);
|
|
266
|
+
if (isOffered(region))
|
|
267
|
+
return region;
|
|
268
|
+
return allowed?.[0] ?? FALLBACK_COUNTRY;
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Tells whether focus moving to an element stays inside the field, so leaving one of its parts for another is not a blur.
|
|
272
|
+
*
|
|
273
|
+
* @param next The element taking focus; `null` when focus leaves the page or lands on nothing focusable.
|
|
274
|
+
* @param parts The field's parts: the group that holds the country trigger and the number, and the country list, which
|
|
275
|
+
* renders in a portal outside it; `null` for one not on the page, such as the list while it is closed.
|
|
276
|
+
* @returns `true` when `next` sits inside one of the parts.
|
|
277
|
+
*/
|
|
278
|
+
const isFocusInside = (next, parts) => next !== null && parts.some((part) => part?.contains(next));
|
|
279
|
+
/**
|
|
280
|
+
* Reads the countries an app passes as the ones the field offers.
|
|
281
|
+
*
|
|
282
|
+
* @param countries The two-letter codes, in the order the app passed them, joined with commas so a new array each render reads the same.
|
|
283
|
+
* @returns The codes the library knows, in that order, or `undefined` when the app offers every country.
|
|
284
|
+
*/
|
|
285
|
+
const offeredCountries = (countries) => countries === undefined ? undefined : countries.split(',').filter((code) => isSupportedCountry(code));
|
|
286
|
+
|
|
287
|
+
export { caretAfter, countryForNumber, countryOptions, editedDigits, entryFor, exampleNumber, formatTyped, fromInternational, isFocusInside, leadingCallingCode, nationalDigits, offeredCountries, significantChars, startingCountry, toInternational };
|
|
288
|
+
//# sourceMappingURL=phoneInput.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phoneInput.utils.js","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneInput.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAMA;AACA,MAAM,gBAAgB,GAAqB,IAAI;AAE/C;;;;;AAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,IAAY,KAAY;IACvD,IAAI,WAAW,GAAG,EAAE;AACpB,IAAA,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;AACvB,QAAA,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,IAAI,WAAW,KAAK,EAAE;gBAAE,WAAW,GAAG,GAAG;QAC3C;aAAO;AACL,YAAA,WAAW,IAAI,WAAW,CAAC,IAAI,CAAC;QAClC;IACF;AACA,IAAA,OAAO,WAAW;AACpB;AAEA;;;;;;AAMG;MACU,UAAU,GAAG,CAAC,IAAY,EAAE,QAAgB,KAAY;IACnE,IAAI,IAAI,GAAG,CAAC;AACZ,IAAA,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAChD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,IAAI,K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MAAM,SAAS,GAAG,CAAC,IAAwB,KACzC,OAAO,CAAC,IAAI,CAAC,IAAI,kBAAkB,CAAC,IAAc,CAAC,KAAK,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAwB,CAAC,CAAC;IACjH,IAAI,SAAS,CAAC,SAAS,CAAC;AAAE,QAAA,OAAO,SAAS;AAC1C,IAAA,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;IACnC,IAAI,SAAS,CAAC,MAAM,CAAC;AAAE,QAAA,OAAO,MAAM;AACpC,IAAA,OAAO,OAAO,GAAG,CAAC,CAAC,IAAI,gBAAgB;AACzC;AAEA;;;;;;;AAOG;AACI,MAAM,aAAa,GAAG,CAAC,IAAwB,EAAE,KAA+B,KACrF,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE,QAAQ,CAAC,IAAY,CAAC;AAEpE;;;;;AAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,SAA6B,KAC5D,SAAS,KAAK,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,KAA+B,kBAAkB,CAAC,IAAI,CAAC;;"}
|
|
@@ -57,8 +57,17 @@ const useFocusThroughSubmit = (fieldRef, isSubmitting) => {
|
|
|
57
57
|
setHasReadFocus(false);
|
|
58
58
|
// Focus sits on `<body>` only when the lock took it; anywhere else, the user chose it.
|
|
59
59
|
const isStillLost = state.wasLost && ownerDocument.activeElement === ownerDocument.body;
|
|
60
|
-
|
|
60
|
+
// Focus the lock took goes back to the element that held it, such as a phone field's country trigger, not the control's first.
|
|
61
|
+
const heldBy = state.heldBy;
|
|
62
|
+
if (state.isOwed)
|
|
61
63
|
control.focus();
|
|
64
|
+
else if (isStillLost) {
|
|
65
|
+
if (heldBy?.isConnected && !heldBy.matches(':disabled'))
|
|
66
|
+
heldBy.focus();
|
|
67
|
+
// An element hidden meanwhile refuses focus, so the control's own focus target takes it instead.
|
|
68
|
+
if (ownerDocument.activeElement === ownerDocument.body)
|
|
69
|
+
control.focus();
|
|
70
|
+
}
|
|
62
71
|
focus.current = { heldBy: null, wasLost: false, isOwed: false };
|
|
63
72
|
}, [isSubmitting, hasReadFocus]);
|
|
64
73
|
return { ref, isLocked };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusThroughSubmit.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"sourcesContent":[null],"names":["useRef","useState","useCallback","useLayoutEffect"],"mappings":";;;;AAeA;;;;;;;;AAQG;MACU,qBAAqB,GAAG,CAAC,QAAqB,EAAE,YAAqB,KAAI;AACpF,IAAA,MAAM,MAAM,GAAGA,YAAM,CAAqB,IAAI,CAAC;AAC/C,IAAA,MAAM,KAAK,GAAGA,YAAM,CAAgE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;;IAEpI,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;AACvD,IAAA,MAAM,QAAQ,GAAG,YAAY,IAAI,YAAY;AAE7C,IAAA,MAAM,GAAG,GAAGC,iBAAW,CACrB,CAAC,QAA4B,KAAI;AAC/B,QAAA,MAAM,CAAC,OAAO,GAAG,QAAQ;AACzB,QAAA,IAAI,CAAC,QAAQ;AAAE,YAAA,OAAO,QAAQ,CAAC,IAAI,CAAC;AACpC,QAAA,QAAQ,CAAC;YACP,KAAK,EAAE,MAAK;gBACV,QAAQ,CAAC,KAAK,EAAE;AAChB,gBAAA,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,aAAa,CAAC;YACjF,CAAC;YACD,MAAM,EAAE,MAAM,QAAQ,CAAC,MAAM,IAAI;AAClC,SAAA,CAAC;AACJ,IAAA,CAAC,EACD,CAAC,QAAQ,CAAC,CACX;IAEDC,qBAAe,CAAC,MAAK;AACnB,QAAA,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO;AAC3B,QAAA,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO;AAC9B,QAAA,IAAI,CAAC,OAAO;AAAE,YAAA,OAAO,eAAe,CAAC,YAAY,CAAC;AAClD,QAAA,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO;AACjC,QAAA,IAAI,YAAY,IAAI,CAAC,YAAY,EAAE;AACjC,YAAA,MAAM,OAAO,GAAG,aAAa,CAAC,aAAa;AAC3C,YAAA,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,IAAI;;AAEzD,YAAA,KAAK,CAAC,MAAM,GAAG,KAAK;AACpB,YAAA,OAAO,eAAe,CAAC,IAAI,CAAC;QAC9B;QACA,IAAI,YAAY,EAAE;;AAEhB,YAAA,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,KAAK;;;YAG3D,MAAM,MAAM,GAAG,MAAK;AAClB,gBAAA,KAAK,CAAC,OAAO,GAAG,KAAK;AACrB,gBAAA,KAAK,CAAC,MAAM,GAAG,KAAK;AACtB,YAAA,CAAC;AACD,YAAA,aAAa,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC;YACjD,OAAO,MAAM,aAAa,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC;QACnE;QACA,eAAe,CAAC,KAAK,CAAC;;AAEtB,QAAA,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,IAAI,aAAa,CAAC,aAAa,KAAK,aAAa,CAAC,IAAI
|
|
1
|
+
{"version":3,"file":"useFocusThroughSubmit.cjs","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"sourcesContent":[null],"names":["useRef","useState","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AAC,YAAY,EAAE,YAAY,CAAC,CAAC;AAEhC,IAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE;AAC1B;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusThroughSubmit.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,kIAAkI;AAClI,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,mHAAmH;IACnH,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,OAAO,CAAC;IACzC,yEAAyE;IACzE,aAAa,EAAE,QAAQ,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,mGAAmG;IACnG,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,WAAW,EAAE,cAAc,OAAO;oBAQnE,WAAW,GAAG,IAAI;;
|
|
1
|
+
{"version":3,"file":"useFocusThroughSubmit.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,kIAAkI;AAClI,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,mHAAmH;IACnH,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,OAAO,CAAC;IACzC,yEAAyE;IACzE,aAAa,EAAE,QAAQ,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,mGAAmG;IACnG,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,WAAW,EAAE,cAAc,OAAO;oBAQnE,WAAW,GAAG,IAAI;;CAqDhC,CAAC"}
|
|
@@ -55,8 +55,17 @@ const useFocusThroughSubmit = (fieldRef, isSubmitting) => {
|
|
|
55
55
|
setHasReadFocus(false);
|
|
56
56
|
// Focus sits on `<body>` only when the lock took it; anywhere else, the user chose it.
|
|
57
57
|
const isStillLost = state.wasLost && ownerDocument.activeElement === ownerDocument.body;
|
|
58
|
-
|
|
58
|
+
// Focus the lock took goes back to the element that held it, such as a phone field's country trigger, not the control's first.
|
|
59
|
+
const heldBy = state.heldBy;
|
|
60
|
+
if (state.isOwed)
|
|
59
61
|
control.focus();
|
|
62
|
+
else if (isStillLost) {
|
|
63
|
+
if (heldBy?.isConnected && !heldBy.matches(':disabled'))
|
|
64
|
+
heldBy.focus();
|
|
65
|
+
// An element hidden meanwhile refuses focus, so the control's own focus target takes it instead.
|
|
66
|
+
if (ownerDocument.activeElement === ownerDocument.body)
|
|
67
|
+
control.focus();
|
|
68
|
+
}
|
|
60
69
|
focus.current = { heldBy: null, wasLost: false, isOwed: false };
|
|
61
70
|
}, [isSubmitting, hasReadFocus]);
|
|
62
71
|
return { ref, isLocked };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusThroughSubmit.js","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAeA;;;;;;;;AAQG;MACU,qBAAqB,GAAG,CAAC,QAAqB,EAAE,YAAqB,KAAI;AACpF,IAAA,MAAM,MAAM,GAAG,MAAM,CAAqB,IAAI,CAAC;AAC/C,IAAA,MAAM,KAAK,GAAG,MAAM,CAAgE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;;IAEpI,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,C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,GAAG,MAAK;AAClB,gBAAA,KAAK,CAAC,OAAO,GAAG,KAAK;AACrB,gBAAA,KAAK,CAAC,MAAM,GAAG,KAAK;AACtB,YAAA,CAAC;AACD,YAAA,aAAa,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC;YACjD,OAAO,MAAM,aAAa,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC;QACnE;QACA,eAAe,CAAC,KAAK,CAAC;;AAEtB,QAAA,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,IAAI,aAAa,CAAC,aAAa,KAAK,aAAa,CAAC,IAAI
|
|
1
|
+
{"version":3,"file":"useFocusThroughSubmit.js","sources":["../../../../../../src/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAeA;;;;;;;;AAQG;MACU,qBAAqB,GAAG,CAAC,QAAqB,EAAE,YAAqB,KAAI;AACpF,IAAA,MAAM,MAAM,GAAG,MAAM,CAAqB,IAAI,CAAC;AAC/C,IAAA,MAAM,KAAK,GAAG,MAAM,CAAgE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;;IAEpI,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;AACvD,IAAA,MAAM,QAAQ,GAAG,YAAY,IAAI,YAAY;AAE7C,IAAA,MAAM,GAAG,GAAG,WAAW,CACrB,CAAC,QAA4B,KAAI;AAC/B,QAAA,MAAM,CAAC,OAAO,GAAG,QAAQ;AACzB,QAAA,IAAI,CAAC,QAAQ;AAAE,YAAA,OAAO,QAAQ,CAAC,IAAI,CAAC;AACpC,QAAA,QAAQ,CAAC;YACP,KAAK,EAAE,MAAK;gBACV,QAAQ,CAAC,KAAK,EAAE;AAChB,gBAAA,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAA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,MAAM,GAAG,KAAK,CAAC,MAA4B;QACjD,IAAI,KAAK,CAAC,MAAM;YAAE,OAAO,CAAC,KAAK,EAAE;aAC5B,IAAI,WAAW,EAAE;YACpB,IAAI,MAAM,EAAE,WAAW,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC;gBAAE,MAAM,CAAC,KAAK,EAAE;;AAEvE,YAAA,IAAI,aAAa,CAAC,aAAa,KAAK,aAAa,CAAC,IAAI;gBAAE,OAAO,CAAC,KAAK,EAAE;QACzE;AACA,QAAA,KAAK,CAAC,OAAO,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;AACjE,IAAA,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AAEhC,IAAA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE;AAC1B;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var PhoneInput = require('@flipdish/ui-library/components/atoms/PhoneInput');
|
|
5
|
+
var useFocusTarget = require('../../__internal__/formField/hooks/useFocusTarget.cjs');
|
|
6
|
+
var useFormField = require('../../__internal__/formField/hooks/useFormField.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A `PhoneInput` bound to a react-hook-form field: it holds the number in international form, such as `+353861234567`,
|
|
10
|
+
* marks itself invalid and shows the field's error in place of `hint`. Use it for a phone number in a react-hook-form form.
|
|
11
|
+
*
|
|
12
|
+
* @summary phone number input bound to a react-hook-form field
|
|
13
|
+
*/
|
|
14
|
+
const FormPhoneInput = ({ name, revalidates, hint, ...phoneInputProps }) => {
|
|
15
|
+
const { value, ref, onChange, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField.useFormField(name, revalidates);
|
|
16
|
+
// The whole field, trigger included, is what the form focuses and locks; a failed submit lands on the number.
|
|
17
|
+
const focusRef = useFocusTarget.useFocusTarget(ref, 'input[type="tel"]');
|
|
18
|
+
// Picking a country is a finished edit, checked at once as a select's choice is; an empty field has no number to check yet.
|
|
19
|
+
const handleCountryChange = (country) => {
|
|
20
|
+
phoneInputProps.onCountryChange?.(country);
|
|
21
|
+
if (value)
|
|
22
|
+
onBlur();
|
|
23
|
+
};
|
|
24
|
+
return (jsxRuntime.jsx(PhoneInput.PhoneInput
|
|
25
|
+
// The form's schema validates; the browser's own `required` check would block the submit before it runs.
|
|
26
|
+
, {
|
|
27
|
+
// The form's schema validates; the browser's own `required` check would block the submit before it runs.
|
|
28
|
+
validationBehavior: "aria", ...phoneInputProps, groupRef: focusRef, name: name, onChange: onChange, onBlur: onBlur, onCountryChange: handleCountryChange,
|
|
29
|
+
// An unset field is `undefined`, which would flip the input between uncontrolled and controlled.
|
|
30
|
+
value: value ?? '', isInvalid: isInvalid, hint: errorMessage ?? hint, isDisabled: phoneInputProps.isDisabled || isDisabled,
|
|
31
|
+
// Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
|
|
32
|
+
isReadOnly: phoneInputProps.isReadOnly || isLocked }));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.FormPhoneInput = FormPhoneInput;
|
|
36
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../../src/components/forms/fields/FormPhoneInput/index.tsx"],"sourcesContent":[null],"names":["useFormField","useFocusTarget","_jsx","PhoneInput"],"mappings":";;;;;;;AAkBA;;;;;AAKG;AACI,MAAM,cAAc,GAAG,CAA4C,EACxE,IAAI,EACJ,WAAW,EACX,IAAI,EACJ,GAAG,eAAe,EACW,KAAI;IACjC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAGA,yBAAY,CAAkB,IAAI,EAAE,WAAW,CAAC;;IAExI,MAAM,QAAQ,GAAGC,6BAAc,CAAC,GAAG,EAAE,mBAAmB,CAAC;;AAEzD,IAAA,MAAM,mBAAmB,GAAuC,CAAC,OAAO,KAAI;AAC1E,QAAA,eAAe,CAAC,eAAe,GAAG,OAAO,CAAC;AAC1C,QAAA,IAAI,KAAK;AAAE,YAAA,MAAM,EAAE;AACrB,IAAA,CAAC;IAED,QACEC,eAACC;;;;QAEC,kBAAkB,EAAC,MAAM,EAAA,GACrB,eAAe,EACnB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,mBAAmB;;QAEpC,KAAK,EAAE,KAAK,IAAI,EAAE,EAClB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,YAAY,IAAI,IAAI,EAC1B,UAAU,EAAE,eAAe,CAAC,UAAU,IAAI,UAAU;;QAEpD,UAAU,EAAE,eAAe,CAAC,UAAU,IAAI,QAAQ,EAAA,CAClD;AAEN;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type PhoneInputProps } from '@flipdish/ui-library/components/atoms/PhoneInput';
|
|
2
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
3
|
+
export interface FormPhoneInputProps<TValues extends FieldValues = FieldValues> extends Omit<PhoneInputProps, 'name' | 'value' | 'defaultValue' | 'onChange' | 'onBlur' | 'isInvalid' | 'groupRef'> {
|
|
4
|
+
/** The field's path in the form values, such as `phone` or `contact.phone`. */
|
|
5
|
+
name: FieldPath<TValues>;
|
|
6
|
+
/**
|
|
7
|
+
* Other fields to re-validate when this changes. A `crossFieldRules` rule validated through `useSchemaResolver` names them
|
|
8
|
+
* itself, so pass this only for a rule written another way, such as a zod `superRefine` in the same schema, or for a nested field.
|
|
9
|
+
*/
|
|
10
|
+
revalidates?: FieldPath<TValues> | FieldPath<TValues>[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A `PhoneInput` bound to a react-hook-form field: it holds the number in international form, such as `+353861234567`,
|
|
14
|
+
* marks itself invalid and shows the field's error in place of `hint`. Use it for a phone number in a react-hook-form form.
|
|
15
|
+
*
|
|
16
|
+
* @summary phone number input bound to a react-hook-form field
|
|
17
|
+
*/
|
|
18
|
+
export declare const FormPhoneInput: <TValues extends FieldValues = FieldValues>({ name, revalidates, hint, ...phoneInputProps }: FormPhoneInputProps<TValues>) => import("react").JSX.Element;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/fields/FormPhoneInput/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,kDAAkD,CAAC;AACpG,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9D,MAAM,WAAW,mBAAmB,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CAC5E,SAAQ,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,GAAG,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAC;IACnH,+EAA+E;IAC/E,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;CACzD;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,iDAKvE,mBAAmB,CAAC,OAAO,CAAC,gCA6B9B,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { PhoneInput } from '@flipdish/ui-library/components/atoms/PhoneInput';
|
|
3
|
+
import { useFocusTarget } from '../../__internal__/formField/hooks/useFocusTarget.js';
|
|
4
|
+
import { useFormField } from '../../__internal__/formField/hooks/useFormField.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A `PhoneInput` bound to a react-hook-form field: it holds the number in international form, such as `+353861234567`,
|
|
8
|
+
* marks itself invalid and shows the field's error in place of `hint`. Use it for a phone number in a react-hook-form form.
|
|
9
|
+
*
|
|
10
|
+
* @summary phone number input bound to a react-hook-form field
|
|
11
|
+
*/
|
|
12
|
+
const FormPhoneInput = ({ name, revalidates, hint, ...phoneInputProps }) => {
|
|
13
|
+
const { value, ref, onChange, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField(name, revalidates);
|
|
14
|
+
// The whole field, trigger included, is what the form focuses and locks; a failed submit lands on the number.
|
|
15
|
+
const focusRef = useFocusTarget(ref, 'input[type="tel"]');
|
|
16
|
+
// Picking a country is a finished edit, checked at once as a select's choice is; an empty field has no number to check yet.
|
|
17
|
+
const handleCountryChange = (country) => {
|
|
18
|
+
phoneInputProps.onCountryChange?.(country);
|
|
19
|
+
if (value)
|
|
20
|
+
onBlur();
|
|
21
|
+
};
|
|
22
|
+
return (jsx(PhoneInput
|
|
23
|
+
// The form's schema validates; the browser's own `required` check would block the submit before it runs.
|
|
24
|
+
, {
|
|
25
|
+
// The form's schema validates; the browser's own `required` check would block the submit before it runs.
|
|
26
|
+
validationBehavior: "aria", ...phoneInputProps, groupRef: focusRef, name: name, onChange: onChange, onBlur: onBlur, onCountryChange: handleCountryChange,
|
|
27
|
+
// An unset field is `undefined`, which would flip the input between uncontrolled and controlled.
|
|
28
|
+
value: value ?? '', isInvalid: isInvalid, hint: errorMessage ?? hint, isDisabled: phoneInputProps.isDisabled || isDisabled,
|
|
29
|
+
// Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
|
|
30
|
+
isReadOnly: phoneInputProps.isReadOnly || isLocked }));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { FormPhoneInput };
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/components/forms/fields/FormPhoneInput/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;AAkBA;;;;;AAKG;AACI,MAAM,cAAc,GAAG,CAA4C,EACxE,IAAI,EACJ,WAAW,EACX,IAAI,EACJ,GAAG,eAAe,EACW,KAAI;IACjC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAkB,IAAI,EAAE,WAAW,CAAC;;IAExI,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,EAAE,mBAAmB,CAAC;;AAEzD,IAAA,MAAM,mBAAmB,GAAuC,CAAC,OAAO,KAAI;AAC1E,QAAA,eAAe,CAAC,eAAe,GAAG,OAAO,CAAC;AAC1C,QAAA,IAAI,KAAK;AAAE,YAAA,MAAM,EAAE;AACrB,IAAA,CAAC;IAED,QACEA,IAAC;;;;QAEC,kBAAkB,EAAC,MAAM,EAAA,GACrB,eAAe,EACnB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,mBAAmB;;QAEpC,KAAK,EAAE,KAAK,IAAI,EAAE,EAClB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,YAAY,IAAI,IAAI,EAC1B,UAAU,EAAE,eAAe,CAAC,UAAU,IAAI,UAAU;;QAEpD,UAAU,EAAE,eAAe,CAAC,UAAU,IAAI,QAAQ,EAAA,CAClD;AAEN;;"}
|