@ticketmaster/tm-global-address 0.5.0 → 0.6.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.
|
@@ -2,23 +2,24 @@ import { jsxs as s, jsx as a } from "react/jsx-runtime";
|
|
|
2
2
|
import { useState as z, useRef as V, useEffect as ee, useCallback as T } from "react";
|
|
3
3
|
import c from "styled-components";
|
|
4
4
|
import { tokens as e, atDesktop as re } from "../../styles/tokens.js";
|
|
5
|
-
import { getCountryConfig as q, getSubdivisions as oe, COUNTRY_OPTIONS as
|
|
6
|
-
import { FIELD_CONSTRAINTS as
|
|
5
|
+
import { getCountryConfig as q, getSubdivisions as oe, COUNTRY_OPTIONS as A } from "../../data/countryData.js";
|
|
6
|
+
import { FIELD_CONSTRAINTS as x } from "../../validation/constants.js";
|
|
7
|
+
import { PhoneField as te } from "../PhoneField/PhoneField.js";
|
|
7
8
|
import { validateTextField as S } from "../../validation/validateTextField.js";
|
|
8
|
-
import { validatePostalCode as
|
|
9
|
-
import { validateState as
|
|
10
|
-
import { validatePhoneNumber as
|
|
11
|
-
import { validateForm as
|
|
12
|
-
const
|
|
9
|
+
import { validatePostalCode as ae } from "../../validation/validatePostalCode.js";
|
|
10
|
+
import { validateState as de } from "../../validation/validateState.js";
|
|
11
|
+
import { validatePhoneNumber as se } from "../../validation/validatePhoneNumber.js";
|
|
12
|
+
import { validateForm as ne } from "../../validation/validateForm.js";
|
|
13
|
+
const le = c.form`
|
|
13
14
|
display: flex;
|
|
14
15
|
flex-direction: column;
|
|
15
16
|
gap: ${e.space4};
|
|
16
|
-
`,
|
|
17
|
+
`, ie = c.h2`
|
|
17
18
|
margin: 0 0 ${e.space2};
|
|
18
19
|
font-size: ${e.fontSizeHeading};
|
|
19
20
|
font-weight: ${e.fontWeightBold};
|
|
20
21
|
color: ${e.colorTextPrimary};
|
|
21
|
-
`,
|
|
22
|
+
`, _ = c.div`
|
|
22
23
|
display: grid;
|
|
23
24
|
grid-template-columns: 1fr;
|
|
24
25
|
gap: ${e.space4};
|
|
@@ -27,7 +28,7 @@ const ne = c.form`
|
|
|
27
28
|
display: flex;
|
|
28
29
|
flex-direction: column;
|
|
29
30
|
gap: ${e.space1};
|
|
30
|
-
`,
|
|
31
|
+
`, y = c.label`
|
|
31
32
|
font-size: ${e.fontSizeLabel};
|
|
32
33
|
font-weight: ${e.fontWeightNormal};
|
|
33
34
|
color: ${e.colorTextPrimary};
|
|
@@ -39,7 +40,7 @@ const ne = c.form`
|
|
|
39
40
|
aria-hidden: true;
|
|
40
41
|
}
|
|
41
42
|
`}
|
|
42
|
-
`,
|
|
43
|
+
`, C = c.input`
|
|
43
44
|
width: 100%;
|
|
44
45
|
padding: ${e.space2} ${e.space3};
|
|
45
46
|
font-size: ${e.fontSizeInput};
|
|
@@ -98,18 +99,18 @@ const ne = c.form`
|
|
|
98
99
|
border-color: ${e.colorBorderInputDisabled};
|
|
99
100
|
cursor: not-allowed;
|
|
100
101
|
}
|
|
101
|
-
`,
|
|
102
|
+
`, v = c.p`
|
|
102
103
|
margin: 0;
|
|
103
104
|
font-size: ${e.fontSizeError};
|
|
104
105
|
color: ${e.colorTextError};
|
|
105
106
|
display: flex;
|
|
106
107
|
align-items: center;
|
|
107
108
|
gap: ${e.space1};
|
|
108
|
-
`,
|
|
109
|
+
`, ce = c.div`
|
|
109
110
|
display: flex;
|
|
110
111
|
align-items: center;
|
|
111
112
|
gap: ${e.space2};
|
|
112
|
-
`,
|
|
113
|
+
`, ue = c.input`
|
|
113
114
|
width: 18px;
|
|
114
115
|
height: 18px;
|
|
115
116
|
cursor: pointer;
|
|
@@ -118,17 +119,17 @@ const ne = c.form`
|
|
|
118
119
|
&:disabled {
|
|
119
120
|
cursor: not-allowed;
|
|
120
121
|
}
|
|
121
|
-
`,
|
|
122
|
+
`, pe = c.label`
|
|
122
123
|
font-size: ${e.fontSizeBody};
|
|
123
124
|
color: ${e.colorTextPrimary};
|
|
124
125
|
cursor: pointer;
|
|
125
|
-
`,
|
|
126
|
+
`, me = c.div`
|
|
126
127
|
display: flex;
|
|
127
128
|
justify-content: flex-end;
|
|
128
129
|
gap: ${e.space3};
|
|
129
130
|
flex-wrap: wrap;
|
|
130
131
|
margin-block-start: ${e.space2};
|
|
131
|
-
`,
|
|
132
|
+
`, fe = c.button`
|
|
132
133
|
appearance: none;
|
|
133
134
|
padding: ${e.space2} ${e.space6};
|
|
134
135
|
font-size: ${e.fontSizeBody};
|
|
@@ -154,7 +155,7 @@ const ne = c.form`
|
|
|
154
155
|
opacity: 0.6;
|
|
155
156
|
cursor: not-allowed;
|
|
156
157
|
}
|
|
157
|
-
`,
|
|
158
|
+
`, he = c.button`
|
|
158
159
|
appearance: none;
|
|
159
160
|
padding: ${e.space2} ${e.space6};
|
|
160
161
|
font-size: ${e.fontSizeBody};
|
|
@@ -183,29 +184,14 @@ const ne = c.form`
|
|
|
183
184
|
opacity: 0.6;
|
|
184
185
|
cursor: not-allowed;
|
|
185
186
|
}
|
|
186
|
-
`, he = c.div`
|
|
187
|
-
display: flex;
|
|
188
|
-
gap: ${e.space2};
|
|
189
187
|
`, be = c.div`
|
|
190
|
-
display: flex;
|
|
191
|
-
align-items: center;
|
|
192
|
-
gap: ${e.space1};
|
|
193
|
-
padding: ${e.space2} ${e.space3};
|
|
194
|
-
background: ${e.colorSurfaceSecondary};
|
|
195
|
-
border: ${e.borderWidthInput} solid ${e.colorBorderInput};
|
|
196
|
-
border-radius: ${e.borderRadiusInput};
|
|
197
|
-
font-size: ${e.fontSizeBody};
|
|
198
|
-
color: ${e.colorTextPrimary};
|
|
199
|
-
white-space: nowrap;
|
|
200
|
-
flex-shrink: 0;
|
|
201
|
-
`, ye = c.div`
|
|
202
188
|
padding: ${e.space3} ${e.space4};
|
|
203
189
|
background: ${e.colorFeedbackErrorSurface};
|
|
204
190
|
border: ${e.borderWidthInput} solid ${e.colorFeedbackErrorBorder};
|
|
205
191
|
border-radius: ${e.borderRadiusInput};
|
|
206
192
|
font-size: ${e.fontSizeBody};
|
|
207
193
|
color: ${e.colorTextError};
|
|
208
|
-
`,
|
|
194
|
+
`, ye = c.span`
|
|
209
195
|
display: inline-block;
|
|
210
196
|
width: 16px;
|
|
211
197
|
height: 16px;
|
|
@@ -220,13 +206,13 @@ const ne = c.form`
|
|
|
220
206
|
}
|
|
221
207
|
}
|
|
222
208
|
`;
|
|
223
|
-
function
|
|
209
|
+
function $e(r) {
|
|
224
210
|
const m = {};
|
|
225
|
-
for (const
|
|
226
|
-
m[
|
|
211
|
+
for (const N of r)
|
|
212
|
+
m[N.field] || (m[N.field] = N.message);
|
|
227
213
|
return m;
|
|
228
214
|
}
|
|
229
|
-
function
|
|
215
|
+
function ge(r) {
|
|
230
216
|
return {
|
|
231
217
|
firstName: (r == null ? void 0 : r.firstName) ?? "",
|
|
232
218
|
lastName: (r == null ? void 0 : r.lastName) ?? "",
|
|
@@ -243,18 +229,18 @@ function ve(r) {
|
|
|
243
229
|
const Te = ({
|
|
244
230
|
mode: r,
|
|
245
231
|
initialValues: m,
|
|
246
|
-
countryWhitelist:
|
|
232
|
+
countryWhitelist: N,
|
|
247
233
|
showPhoneNumber: F = !1,
|
|
248
234
|
screenReaderErrorPrefix: f,
|
|
249
|
-
addressLabel:
|
|
235
|
+
addressLabel: L,
|
|
250
236
|
isLoading: P = !1,
|
|
251
237
|
disabled: j = !1,
|
|
252
238
|
serverErrors: E = [],
|
|
253
239
|
onCancel: G,
|
|
254
240
|
onSubmit: H
|
|
255
241
|
}) => {
|
|
256
|
-
var
|
|
257
|
-
const [d,
|
|
242
|
+
var M;
|
|
243
|
+
const [d, W] = z(() => ge(m)), [K, I] = z({}), [D, R] = z(""), U = V(null), $ = q(d.country), Y = oe(d.country), J = $.stateCodes.length > 0 || $.stateRequired, Q = N ? A.filter((t) => N.includes(t.code)) : A;
|
|
258
244
|
ee(() => {
|
|
259
245
|
if (E.length === 0) return;
|
|
260
246
|
const t = {};
|
|
@@ -265,34 +251,34 @@ const Te = ({
|
|
|
265
251
|
}, [E]);
|
|
266
252
|
const X = T((t) => {
|
|
267
253
|
const n = t.target.value;
|
|
268
|
-
|
|
269
|
-
const { country: l, state:
|
|
254
|
+
W((i) => ({ ...i, country: n, state: "" })), I((i) => {
|
|
255
|
+
const { country: l, state: g, ...B } = i;
|
|
270
256
|
return B;
|
|
271
257
|
});
|
|
272
|
-
}, []),
|
|
258
|
+
}, []), h = T(
|
|
273
259
|
(t) => (n) => {
|
|
274
260
|
const i = n.target.type === "checkbox" ? n.target.checked : n.target.value;
|
|
275
|
-
|
|
276
|
-
const { [t]:
|
|
261
|
+
W((l) => ({ ...l, [t]: i })), I((l) => {
|
|
262
|
+
const { [t]: g, ...B } = l;
|
|
277
263
|
return B;
|
|
278
264
|
});
|
|
279
265
|
},
|
|
280
266
|
[]
|
|
281
|
-
),
|
|
267
|
+
), b = T(
|
|
282
268
|
(t) => () => {
|
|
283
269
|
const n = d[t];
|
|
284
270
|
if (typeof n != "string") return;
|
|
285
271
|
const i = q(d.country);
|
|
286
272
|
let l = null;
|
|
287
|
-
t === "firstName" ? l = S("firstName", n,
|
|
288
|
-
if (l) return { ...
|
|
289
|
-
const { [t]: B, ...k } =
|
|
273
|
+
t === "firstName" ? l = S("firstName", n, x.firstName) : t === "lastName" ? l = S("lastName", n, x.lastName) : t === "address1" ? l = S("address1", n, x.address1) : t === "address2" && n !== "" ? l = S("address2", n, x.address2) : t === "city" ? l = S("city", n, x.city) : t === "postal" && n !== "" ? l = ae(n, x.postal, i) : t === "state" ? l = de(n || void 0, i) : t === "phoneNumber" && n !== "" && F ? l = se(n, i) : t === "country" && n === "" && (l = { message: "Please select your country" }), I((g) => {
|
|
274
|
+
if (l) return { ...g, [t]: l.message };
|
|
275
|
+
const { [t]: B, ...k } = g;
|
|
290
276
|
return k;
|
|
291
277
|
});
|
|
292
278
|
},
|
|
293
279
|
[d, F]
|
|
294
280
|
), Z = (t) => {
|
|
295
|
-
var
|
|
281
|
+
var g;
|
|
296
282
|
t.preventDefault(), R("");
|
|
297
283
|
const n = {
|
|
298
284
|
mode: r,
|
|
@@ -307,11 +293,11 @@ const Te = ({
|
|
|
307
293
|
country: d.country,
|
|
308
294
|
...d.state ? { state: d.state } : {},
|
|
309
295
|
...F && d.phoneNumber ? { phoneNumber: d.phoneNumber.trim() } : {}
|
|
310
|
-
}, i = q(d.country), l =
|
|
296
|
+
}, i = q(d.country), l = ne(n, i, { showPhoneNumber: F });
|
|
311
297
|
if (!l.valid) {
|
|
312
|
-
const B =
|
|
298
|
+
const B = $e(l.errors);
|
|
313
299
|
I(B);
|
|
314
|
-
const k = (
|
|
300
|
+
const k = (g = l.errors[0]) == null ? void 0 : g.field;
|
|
315
301
|
if (k) {
|
|
316
302
|
const w = document.getElementById(`field-${k}`);
|
|
317
303
|
w && (w.focus(), U.current = w);
|
|
@@ -320,25 +306,25 @@ const Te = ({
|
|
|
320
306
|
}
|
|
321
307
|
H(n);
|
|
322
308
|
}, u = j || P, o = (t) => K[t] ?? "";
|
|
323
|
-
return /* @__PURE__ */ s(
|
|
324
|
-
/* @__PURE__ */ a(
|
|
325
|
-
|
|
309
|
+
return /* @__PURE__ */ s(le, { onSubmit: Z, noValidate: !0, "aria-label": L, children: [
|
|
310
|
+
/* @__PURE__ */ a(ie, { children: L }),
|
|
311
|
+
D && /* @__PURE__ */ s(be, { role: "alert", children: [
|
|
326
312
|
f,
|
|
327
313
|
" ",
|
|
328
|
-
|
|
314
|
+
D
|
|
329
315
|
] }),
|
|
330
|
-
/* @__PURE__ */ s(
|
|
316
|
+
/* @__PURE__ */ s(_, { children: [
|
|
331
317
|
/* @__PURE__ */ s(p, { children: [
|
|
332
|
-
/* @__PURE__ */ a(
|
|
318
|
+
/* @__PURE__ */ a(y, { htmlFor: "field-firstName", $required: !0, children: "First Name" }),
|
|
333
319
|
/* @__PURE__ */ a(
|
|
334
|
-
|
|
320
|
+
C,
|
|
335
321
|
{
|
|
336
322
|
id: "field-firstName",
|
|
337
323
|
type: "text",
|
|
338
324
|
autoComplete: "given-name",
|
|
339
325
|
value: d.firstName,
|
|
340
|
-
onChange:
|
|
341
|
-
onBlur:
|
|
326
|
+
onChange: h("firstName"),
|
|
327
|
+
onBlur: b("firstName"),
|
|
342
328
|
maxLength: 30,
|
|
343
329
|
disabled: u,
|
|
344
330
|
$hasError: !!o("firstName"),
|
|
@@ -347,7 +333,7 @@ const Te = ({
|
|
|
347
333
|
"aria-describedby": o("firstName") ? "err-firstName" : void 0
|
|
348
334
|
}
|
|
349
335
|
),
|
|
350
|
-
o("firstName") && /* @__PURE__ */ s(
|
|
336
|
+
o("firstName") && /* @__PURE__ */ s(v, { id: "err-firstName", role: "alert", children: [
|
|
351
337
|
/* @__PURE__ */ a("span", { "aria-hidden": "true", children: "⚠" }),
|
|
352
338
|
f,
|
|
353
339
|
" ",
|
|
@@ -355,16 +341,16 @@ const Te = ({
|
|
|
355
341
|
] })
|
|
356
342
|
] }),
|
|
357
343
|
/* @__PURE__ */ s(p, { children: [
|
|
358
|
-
/* @__PURE__ */ a(
|
|
344
|
+
/* @__PURE__ */ a(y, { htmlFor: "field-lastName", $required: !0, children: "Last Name" }),
|
|
359
345
|
/* @__PURE__ */ a(
|
|
360
|
-
|
|
346
|
+
C,
|
|
361
347
|
{
|
|
362
348
|
id: "field-lastName",
|
|
363
349
|
type: "text",
|
|
364
350
|
autoComplete: "family-name",
|
|
365
351
|
value: d.lastName,
|
|
366
|
-
onChange:
|
|
367
|
-
onBlur:
|
|
352
|
+
onChange: h("lastName"),
|
|
353
|
+
onBlur: b("lastName"),
|
|
368
354
|
maxLength: 40,
|
|
369
355
|
disabled: u,
|
|
370
356
|
$hasError: !!o("lastName"),
|
|
@@ -373,7 +359,7 @@ const Te = ({
|
|
|
373
359
|
"aria-describedby": o("lastName") ? "err-lastName" : void 0
|
|
374
360
|
}
|
|
375
361
|
),
|
|
376
|
-
o("lastName") && /* @__PURE__ */ s(
|
|
362
|
+
o("lastName") && /* @__PURE__ */ s(v, { id: "err-lastName", role: "alert", children: [
|
|
377
363
|
/* @__PURE__ */ a("span", { "aria-hidden": "true", children: "⚠" }),
|
|
378
364
|
f,
|
|
379
365
|
" ",
|
|
@@ -382,14 +368,14 @@ const Te = ({
|
|
|
382
368
|
] })
|
|
383
369
|
] }),
|
|
384
370
|
/* @__PURE__ */ s(p, { children: [
|
|
385
|
-
/* @__PURE__ */ a(
|
|
371
|
+
/* @__PURE__ */ a(y, { htmlFor: "field-country", $required: !0, children: "Country" }),
|
|
386
372
|
/* @__PURE__ */ s(
|
|
387
373
|
O,
|
|
388
374
|
{
|
|
389
375
|
id: "field-country",
|
|
390
376
|
value: d.country,
|
|
391
377
|
onChange: X,
|
|
392
|
-
onBlur:
|
|
378
|
+
onBlur: b("country"),
|
|
393
379
|
disabled: u,
|
|
394
380
|
$hasError: !!o("country"),
|
|
395
381
|
"aria-required": "true",
|
|
@@ -406,7 +392,7 @@ const Te = ({
|
|
|
406
392
|
]
|
|
407
393
|
}
|
|
408
394
|
),
|
|
409
|
-
o("country") && /* @__PURE__ */ s(
|
|
395
|
+
o("country") && /* @__PURE__ */ s(v, { id: "err-country", role: "alert", children: [
|
|
410
396
|
/* @__PURE__ */ a("span", { "aria-hidden": "true", children: "⚠" }),
|
|
411
397
|
f,
|
|
412
398
|
" ",
|
|
@@ -414,16 +400,16 @@ const Te = ({
|
|
|
414
400
|
] })
|
|
415
401
|
] }),
|
|
416
402
|
/* @__PURE__ */ s(p, { children: [
|
|
417
|
-
/* @__PURE__ */ a(
|
|
403
|
+
/* @__PURE__ */ a(y, { htmlFor: "field-address1", $required: !0, children: "Address Line 1" }),
|
|
418
404
|
/* @__PURE__ */ a(
|
|
419
|
-
|
|
405
|
+
C,
|
|
420
406
|
{
|
|
421
407
|
id: "field-address1",
|
|
422
408
|
type: "text",
|
|
423
409
|
autoComplete: "address-line1",
|
|
424
410
|
value: d.address1,
|
|
425
|
-
onChange:
|
|
426
|
-
onBlur:
|
|
411
|
+
onChange: h("address1"),
|
|
412
|
+
onBlur: b("address1"),
|
|
427
413
|
maxLength: 50,
|
|
428
414
|
disabled: u,
|
|
429
415
|
$hasError: !!o("address1"),
|
|
@@ -432,7 +418,7 @@ const Te = ({
|
|
|
432
418
|
"aria-describedby": o("address1") ? "err-address1" : void 0
|
|
433
419
|
}
|
|
434
420
|
),
|
|
435
|
-
o("address1") && /* @__PURE__ */ s(
|
|
421
|
+
o("address1") && /* @__PURE__ */ s(v, { id: "err-address1", role: "alert", children: [
|
|
436
422
|
/* @__PURE__ */ a("span", { "aria-hidden": "true", children: "⚠" }),
|
|
437
423
|
f,
|
|
438
424
|
" ",
|
|
@@ -440,34 +426,34 @@ const Te = ({
|
|
|
440
426
|
] })
|
|
441
427
|
] }),
|
|
442
428
|
/* @__PURE__ */ s(p, { children: [
|
|
443
|
-
/* @__PURE__ */ a(
|
|
429
|
+
/* @__PURE__ */ a(y, { htmlFor: "field-address2", children: "Address Line 2 (Optional)" }),
|
|
444
430
|
/* @__PURE__ */ a(
|
|
445
|
-
|
|
431
|
+
C,
|
|
446
432
|
{
|
|
447
433
|
id: "field-address2",
|
|
448
434
|
type: "text",
|
|
449
435
|
autoComplete: "address-line2",
|
|
450
436
|
value: d.address2,
|
|
451
|
-
onChange:
|
|
452
|
-
onBlur:
|
|
437
|
+
onChange: h("address2"),
|
|
438
|
+
onBlur: b("address2"),
|
|
453
439
|
maxLength: 50,
|
|
454
440
|
disabled: u,
|
|
455
441
|
$hasError: !1
|
|
456
442
|
}
|
|
457
443
|
)
|
|
458
444
|
] }),
|
|
459
|
-
/* @__PURE__ */ s(
|
|
445
|
+
/* @__PURE__ */ s(_, { children: [
|
|
460
446
|
/* @__PURE__ */ s(p, { children: [
|
|
461
|
-
/* @__PURE__ */ a(
|
|
447
|
+
/* @__PURE__ */ a(y, { htmlFor: "field-city", $required: !0, children: "City" }),
|
|
462
448
|
/* @__PURE__ */ a(
|
|
463
|
-
|
|
449
|
+
C,
|
|
464
450
|
{
|
|
465
451
|
id: "field-city",
|
|
466
452
|
type: "text",
|
|
467
453
|
autoComplete: "address-level2",
|
|
468
454
|
value: d.city,
|
|
469
|
-
onChange:
|
|
470
|
-
onBlur:
|
|
455
|
+
onChange: h("city"),
|
|
456
|
+
onBlur: b("city"),
|
|
471
457
|
maxLength: 30,
|
|
472
458
|
disabled: u,
|
|
473
459
|
$hasError: !!o("city"),
|
|
@@ -476,7 +462,7 @@ const Te = ({
|
|
|
476
462
|
"aria-describedby": o("city") ? "err-city" : void 0
|
|
477
463
|
}
|
|
478
464
|
),
|
|
479
|
-
o("city") && /* @__PURE__ */ s(
|
|
465
|
+
o("city") && /* @__PURE__ */ s(v, { id: "err-city", role: "alert", children: [
|
|
480
466
|
/* @__PURE__ */ a("span", { "aria-hidden": "true", children: "⚠" }),
|
|
481
467
|
f,
|
|
482
468
|
" ",
|
|
@@ -484,18 +470,18 @@ const Te = ({
|
|
|
484
470
|
] })
|
|
485
471
|
] }),
|
|
486
472
|
/* @__PURE__ */ s(p, { children: [
|
|
487
|
-
/* @__PURE__ */ a(
|
|
473
|
+
/* @__PURE__ */ a(y, { htmlFor: "field-postal", $required: !0, children: "Postal Code" }),
|
|
488
474
|
/* @__PURE__ */ a(
|
|
489
|
-
|
|
475
|
+
C,
|
|
490
476
|
{
|
|
491
477
|
id: "field-postal",
|
|
492
478
|
type: "text",
|
|
493
479
|
autoComplete: "postal-code",
|
|
494
|
-
inputMode:
|
|
495
|
-
placeholder:
|
|
480
|
+
inputMode: $.postalInputMode,
|
|
481
|
+
placeholder: $.postalExamples,
|
|
496
482
|
value: d.postal,
|
|
497
|
-
onChange:
|
|
498
|
-
onBlur:
|
|
483
|
+
onChange: h("postal"),
|
|
484
|
+
onBlur: b("postal"),
|
|
499
485
|
maxLength: 10,
|
|
500
486
|
disabled: u,
|
|
501
487
|
$hasError: !!o("postal"),
|
|
@@ -504,7 +490,7 @@ const Te = ({
|
|
|
504
490
|
"aria-describedby": o("postal") ? "err-postal" : void 0
|
|
505
491
|
}
|
|
506
492
|
),
|
|
507
|
-
o("postal") && /* @__PURE__ */ s(
|
|
493
|
+
o("postal") && /* @__PURE__ */ s(v, { id: "err-postal", role: "alert", children: [
|
|
508
494
|
/* @__PURE__ */ a("span", { "aria-hidden": "true", children: "⚠" }),
|
|
509
495
|
f,
|
|
510
496
|
" ",
|
|
@@ -513,17 +499,17 @@ const Te = ({
|
|
|
513
499
|
] })
|
|
514
500
|
] }),
|
|
515
501
|
J && /* @__PURE__ */ s(p, { children: [
|
|
516
|
-
/* @__PURE__ */ a(
|
|
502
|
+
/* @__PURE__ */ a(y, { htmlFor: "field-state", $required: $.stateRequired, children: "State / Province" }),
|
|
517
503
|
/* @__PURE__ */ s(
|
|
518
504
|
O,
|
|
519
505
|
{
|
|
520
506
|
id: "field-state",
|
|
521
507
|
value: d.state,
|
|
522
|
-
onChange:
|
|
523
|
-
onBlur:
|
|
508
|
+
onChange: h("state"),
|
|
509
|
+
onBlur: b("state"),
|
|
524
510
|
disabled: u,
|
|
525
511
|
$hasError: !!o("state"),
|
|
526
|
-
"aria-required":
|
|
512
|
+
"aria-required": $.stateRequired,
|
|
527
513
|
"aria-invalid": !!o("state"),
|
|
528
514
|
"aria-describedby": o("state") ? "err-state" : void 0,
|
|
529
515
|
autoComplete: "address-level1",
|
|
@@ -533,7 +519,7 @@ const Te = ({
|
|
|
533
519
|
]
|
|
534
520
|
}
|
|
535
521
|
),
|
|
536
|
-
o("state") && /* @__PURE__ */ s(
|
|
522
|
+
o("state") && /* @__PURE__ */ s(v, { id: "err-state", role: "alert", children: [
|
|
537
523
|
/* @__PURE__ */ a("span", { "aria-hidden": "true", children: "⚠" }),
|
|
538
524
|
f,
|
|
539
525
|
" ",
|
|
@@ -541,54 +527,41 @@ const Te = ({
|
|
|
541
527
|
] })
|
|
542
528
|
] }),
|
|
543
529
|
F && /* @__PURE__ */ s(p, { children: [
|
|
544
|
-
/* @__PURE__ */ a(
|
|
545
|
-
/* @__PURE__ */
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
disabled: u,
|
|
562
|
-
$hasError: !!o("phoneNumber"),
|
|
563
|
-
"aria-invalid": !!o("phoneNumber"),
|
|
564
|
-
"aria-describedby": o("phoneNumber") ? "err-phoneNumber" : void 0
|
|
565
|
-
}
|
|
566
|
-
)
|
|
567
|
-
] }),
|
|
568
|
-
o("phoneNumber") && /* @__PURE__ */ s(g, { id: "err-phoneNumber", role: "alert", children: [
|
|
569
|
-
/* @__PURE__ */ a("span", { "aria-hidden": "true", children: "⚠" }),
|
|
570
|
-
f,
|
|
571
|
-
" ",
|
|
572
|
-
o("phoneNumber")
|
|
573
|
-
] })
|
|
530
|
+
/* @__PURE__ */ a(y, { htmlFor: "field-phoneNumber", children: "Phone Number" }),
|
|
531
|
+
/* @__PURE__ */ a(
|
|
532
|
+
te,
|
|
533
|
+
{
|
|
534
|
+
id: "field-phoneNumber",
|
|
535
|
+
value: d.phoneNumber,
|
|
536
|
+
dialCode: $.dialCode,
|
|
537
|
+
flagEmoji: ((M = A.find((t) => t.code === d.country)) == null ? void 0 : M.flag) ?? "",
|
|
538
|
+
countryCode: d.country,
|
|
539
|
+
onChange: h("phoneNumber"),
|
|
540
|
+
onBlur: b("phoneNumber"),
|
|
541
|
+
disabled: u,
|
|
542
|
+
hasError: !!o("phoneNumber"),
|
|
543
|
+
errorMessage: o("phoneNumber") || void 0,
|
|
544
|
+
screenReaderErrorPrefix: f
|
|
545
|
+
}
|
|
546
|
+
)
|
|
574
547
|
] }),
|
|
575
|
-
/* @__PURE__ */ a(p, { children: /* @__PURE__ */ s(
|
|
548
|
+
/* @__PURE__ */ a(p, { children: /* @__PURE__ */ s(ce, { children: [
|
|
576
549
|
/* @__PURE__ */ a(
|
|
577
|
-
|
|
550
|
+
ue,
|
|
578
551
|
{
|
|
579
552
|
id: "field-defaultAddress",
|
|
580
553
|
type: "checkbox",
|
|
581
554
|
checked: d.defaultAddress,
|
|
582
|
-
onChange:
|
|
555
|
+
onChange: h("defaultAddress"),
|
|
583
556
|
disabled: u
|
|
584
557
|
}
|
|
585
558
|
),
|
|
586
|
-
/* @__PURE__ */ a(
|
|
559
|
+
/* @__PURE__ */ a(pe, { htmlFor: "field-defaultAddress", children: "Make this my default address." })
|
|
587
560
|
] }) }),
|
|
588
|
-
/* @__PURE__ */ s(
|
|
589
|
-
/* @__PURE__ */ a(
|
|
590
|
-
/* @__PURE__ */ s(
|
|
591
|
-
P && /* @__PURE__ */ a(
|
|
561
|
+
/* @__PURE__ */ s(me, { children: [
|
|
562
|
+
/* @__PURE__ */ a(fe, { type: "button", disabled: u, onClick: G, children: "Cancel" }),
|
|
563
|
+
/* @__PURE__ */ s(he, { type: "submit", disabled: u, children: [
|
|
564
|
+
P && /* @__PURE__ */ a(ye, { "aria-hidden": "true" }),
|
|
592
565
|
"Confirm Address"
|
|
593
566
|
] })
|
|
594
567
|
] })
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface PhoneFieldProps {
|
|
3
|
+
/** Current phone number value (local number, without dial code) */
|
|
4
|
+
value: string;
|
|
5
|
+
/** Dial code to display as non-editable prefix (e.g. '+1', '+44') */
|
|
6
|
+
dialCode: string;
|
|
7
|
+
/** Flag emoji for the selected country (e.g. '🇺🇸') */
|
|
8
|
+
flagEmoji: string;
|
|
9
|
+
/** ISO 3166-1 alpha-2 code used for aria-label on the dial code prefix */
|
|
10
|
+
countryCode: string;
|
|
11
|
+
/** Called when the input value changes */
|
|
12
|
+
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
13
|
+
/** Called when the input loses focus */
|
|
14
|
+
onBlur: () => void;
|
|
15
|
+
/** Disable all interaction */
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
/** Whether the field is in an error state (red border) */
|
|
18
|
+
hasError?: boolean;
|
|
19
|
+
/** Error message to render below the field */
|
|
20
|
+
errorMessage?: string;
|
|
21
|
+
/** Screen reader prefix prepended to error messages (GDS requirement) */
|
|
22
|
+
screenReaderErrorPrefix?: string;
|
|
23
|
+
/** id attribute for the underlying <input> — used for label association */
|
|
24
|
+
id?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* PhoneField — a phone number input with a non-interactive country dial code prefix.
|
|
28
|
+
*
|
|
29
|
+
* The dial code is derived from the country selected in the parent `AddressForm` and
|
|
30
|
+
* is read-only — the fan selects their country in the country dropdown, which updates
|
|
31
|
+
* the dial code automatically. The fan only types the local number portion here.
|
|
32
|
+
*
|
|
33
|
+
* Phone is optional — empty value does not trigger validation. Validation occurs on
|
|
34
|
+
* blur when the field is non-empty, using `validatePhoneNumber` (libphonenumber-js/max).
|
|
35
|
+
*
|
|
36
|
+
* Usage in AddressForm:
|
|
37
|
+
* ```tsx
|
|
38
|
+
* <PhoneField
|
|
39
|
+
* id="field-phoneNumber"
|
|
40
|
+
* value={values.phoneNumber}
|
|
41
|
+
* dialCode={countryConfig.dialCode}
|
|
42
|
+
* flagEmoji={flag}
|
|
43
|
+
* countryCode={values.country}
|
|
44
|
+
* onChange={handleChange('phoneNumber')}
|
|
45
|
+
* onBlur={handleBlur('phoneNumber')}
|
|
46
|
+
* disabled={isDisabled}
|
|
47
|
+
* hasError={Boolean(getFieldError('phoneNumber'))}
|
|
48
|
+
* errorMessage={getFieldError('phoneNumber')}
|
|
49
|
+
* screenReaderErrorPrefix={screenReaderErrorPrefix}
|
|
50
|
+
* />
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* TODO(GDS swap): Replace with GDS PhoneNumber component. The GDS PhoneNumber
|
|
54
|
+
* component provides built-in dial code selection integrated with the CountryPicker.
|
|
55
|
+
*/
|
|
56
|
+
export declare const PhoneField: React.FC<PhoneFieldProps>;
|
|
57
|
+
export default PhoneField;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsxs as r, jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import e from "styled-components";
|
|
3
|
+
import { tokens as o } from "../../styles/tokens.js";
|
|
4
|
+
const f = e.div`
|
|
5
|
+
display: flex;
|
|
6
|
+
gap: ${o.space2};
|
|
7
|
+
align-items: flex-start;
|
|
8
|
+
`, m = e.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: ${o.space1};
|
|
12
|
+
padding: ${o.space2} ${o.space3};
|
|
13
|
+
background: ${o.colorSurfaceSecondary};
|
|
14
|
+
border: ${o.borderWidthInput} solid ${o.colorBorderInput};
|
|
15
|
+
border-radius: ${o.borderRadiusInput};
|
|
16
|
+
font-size: ${o.fontSizeBody};
|
|
17
|
+
color: ${o.colorTextPrimary};
|
|
18
|
+
white-space: nowrap;
|
|
19
|
+
flex-shrink: 0;
|
|
20
|
+
/* Align vertically with the input */
|
|
21
|
+
height: fit-content;
|
|
22
|
+
`, x = e.input`
|
|
23
|
+
flex: 1;
|
|
24
|
+
width: 100%;
|
|
25
|
+
padding: ${o.space2} ${o.space3};
|
|
26
|
+
font-size: ${o.fontSizeInput};
|
|
27
|
+
font-family: ${o.fontFamily};
|
|
28
|
+
color: ${o.colorTextPrimary};
|
|
29
|
+
background: ${o.colorSurfacePrimary};
|
|
30
|
+
border: ${o.borderWidthInput} solid
|
|
31
|
+
${(t) => t.$hasError ? o.colorBorderInputError : o.colorBorderInput};
|
|
32
|
+
border-radius: ${o.borderRadiusInput};
|
|
33
|
+
box-sizing: border-box;
|
|
34
|
+
transition: border-color ${o.transitionFast};
|
|
35
|
+
|
|
36
|
+
&::placeholder {
|
|
37
|
+
color: ${o.colorTextPlaceholder};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&:hover:not(:disabled) {
|
|
41
|
+
border-color: ${o.colorBorderInputFocus};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&:focus {
|
|
45
|
+
outline: none;
|
|
46
|
+
border-color: ${o.colorBorderInputFocus};
|
|
47
|
+
box-shadow: 0 0 0 ${o.borderWidthInputFocus} ${o.colorBorderInputFocus};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
&:disabled {
|
|
51
|
+
background: ${o.colorSurfaceDisabled};
|
|
52
|
+
color: ${o.colorTextDisabled};
|
|
53
|
+
border-color: ${o.colorBorderInputDisabled};
|
|
54
|
+
cursor: not-allowed;
|
|
55
|
+
}
|
|
56
|
+
`, g = e.p`
|
|
57
|
+
margin: ${o.space1} 0 0;
|
|
58
|
+
font-size: ${o.fontSizeError};
|
|
59
|
+
color: ${o.colorTextError};
|
|
60
|
+
display: flex;
|
|
61
|
+
align-items: center;
|
|
62
|
+
gap: ${o.space1};
|
|
63
|
+
`, v = ({
|
|
64
|
+
value: t,
|
|
65
|
+
dialCode: i,
|
|
66
|
+
flagEmoji: s,
|
|
67
|
+
countryCode: p,
|
|
68
|
+
onChange: u,
|
|
69
|
+
onBlur: $,
|
|
70
|
+
disabled: b = !1,
|
|
71
|
+
hasError: a = !1,
|
|
72
|
+
errorMessage: d,
|
|
73
|
+
screenReaderErrorPrefix: h,
|
|
74
|
+
id: l = "field-phoneNumber"
|
|
75
|
+
}) => {
|
|
76
|
+
const n = `${l}-error`;
|
|
77
|
+
return /* @__PURE__ */ r("div", { children: [
|
|
78
|
+
/* @__PURE__ */ r(f, { children: [
|
|
79
|
+
i && /* @__PURE__ */ r(
|
|
80
|
+
m,
|
|
81
|
+
{
|
|
82
|
+
"aria-label": `Dial code ${i}`,
|
|
83
|
+
"data-testid": `dial-code-${p}`,
|
|
84
|
+
children: [
|
|
85
|
+
s,
|
|
86
|
+
" ",
|
|
87
|
+
i
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
),
|
|
91
|
+
/* @__PURE__ */ c(
|
|
92
|
+
x,
|
|
93
|
+
{
|
|
94
|
+
id: l,
|
|
95
|
+
type: "tel",
|
|
96
|
+
autoComplete: "tel",
|
|
97
|
+
value: t,
|
|
98
|
+
onChange: u,
|
|
99
|
+
onBlur: $,
|
|
100
|
+
maxLength: 20,
|
|
101
|
+
disabled: b,
|
|
102
|
+
$hasError: a,
|
|
103
|
+
"aria-invalid": a,
|
|
104
|
+
"aria-describedby": d ? n : void 0,
|
|
105
|
+
"data-testid": "phone-input"
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
] }),
|
|
109
|
+
d && /* @__PURE__ */ r(g, { id: n, role: "alert", children: [
|
|
110
|
+
/* @__PURE__ */ c("span", { "aria-hidden": "true", children: "⚠" }),
|
|
111
|
+
h,
|
|
112
|
+
" ",
|
|
113
|
+
d
|
|
114
|
+
] })
|
|
115
|
+
] });
|
|
116
|
+
};
|
|
117
|
+
export {
|
|
118
|
+
v as PhoneField
|
|
119
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { GlobalAddress } from './components/GlobalAddress/GlobalAddress';
|
|
2
2
|
export { AddressForm } from './components/AddressForm/AddressForm';
|
|
3
3
|
export type { AddressFormProps } from './components/AddressForm/AddressForm';
|
|
4
|
+
export { PhoneField } from './components/PhoneField/PhoneField';
|
|
5
|
+
export type { PhoneFieldProps } from './components/PhoneField/PhoneField';
|
|
4
6
|
export { AddressCard, formatAddressSummary } from './components/AddressCard/AddressCard';
|
|
5
7
|
export type { AddressCardProps } from './components/AddressCard/AddressCard';
|
|
6
8
|
export { AddressSummary } from './components/AddressSummary/AddressSummary';
|
package/dist/index.js
CHANGED
|
@@ -1,45 +1,47 @@
|
|
|
1
1
|
import { GlobalAddress as e } from "./components/GlobalAddress/GlobalAddress.js";
|
|
2
2
|
import { AddressForm as m } from "./components/AddressForm/AddressForm.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
3
|
+
import { PhoneField as a } from "./components/PhoneField/PhoneField.js";
|
|
4
|
+
import { AddressCard as x, formatAddressSummary as p } from "./components/AddressCard/AddressCard.js";
|
|
5
|
+
import { AddressSummary as S } from "./components/AddressSummary/AddressSummary.js";
|
|
6
|
+
import { AddressList as l } from "./components/AddressList/AddressList.js";
|
|
7
|
+
import { COUNTRIES as T, getCountryByCode as N } from "./data/countries.js";
|
|
8
|
+
import { SUBDIVISIONS as O, getSubdivisions as n } from "./data/states.js";
|
|
9
|
+
import { POSTAL_PATTERNS as P, getPostalPattern as u } from "./data/postalPatterns.js";
|
|
10
|
+
import { STATE_REQUIRED_CODES as R } from "./data/countryConfig.js";
|
|
11
|
+
import { COUNTRY_CONFIGS as v, COUNTRY_OPTIONS as y, getCountryConfig as F, getCountryName as _ } from "./data/countryData.js";
|
|
12
|
+
import { FIELD_CONSTRAINTS as D } from "./validation/constants.js";
|
|
13
|
+
import { HelloWorld as L } from "./components/HelloWorld/HelloWorld.js";
|
|
14
|
+
import { sanitize as B } from "./validation/sanitize.js";
|
|
15
|
+
import { validateForm as Y } from "./validation/validateForm.js";
|
|
16
|
+
import { validatePhoneNumber as H } from "./validation/validatePhoneNumber.js";
|
|
17
|
+
import { validatePostalCode as V } from "./validation/validatePostalCode.js";
|
|
18
|
+
import { validateState as c } from "./validation/validateState.js";
|
|
19
|
+
import { validateTextField as k } from "./validation/validateTextField.js";
|
|
19
20
|
export {
|
|
20
|
-
|
|
21
|
+
x as AddressCard,
|
|
21
22
|
m as AddressForm,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
l as AddressList,
|
|
24
|
+
S as AddressSummary,
|
|
25
|
+
T as COUNTRIES,
|
|
26
|
+
v as COUNTRY_CONFIGS,
|
|
27
|
+
y as COUNTRY_OPTIONS,
|
|
28
|
+
D as FIELD_CONSTRAINTS,
|
|
28
29
|
e as GlobalAddress,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
H as
|
|
43
|
-
V as
|
|
44
|
-
c as
|
|
30
|
+
L as HelloWorld,
|
|
31
|
+
P as POSTAL_PATTERNS,
|
|
32
|
+
a as PhoneField,
|
|
33
|
+
R as STATE_REQUIRED_CODES,
|
|
34
|
+
O as SUBDIVISIONS,
|
|
35
|
+
p as formatAddressSummary,
|
|
36
|
+
N as getCountryByCode,
|
|
37
|
+
F as getCountryConfig,
|
|
38
|
+
_ as getCountryName,
|
|
39
|
+
u as getPostalPattern,
|
|
40
|
+
n as getSubdivisions,
|
|
41
|
+
B as sanitize,
|
|
42
|
+
Y as validateForm,
|
|
43
|
+
H as validatePhoneNumber,
|
|
44
|
+
V as validatePostalCode,
|
|
45
|
+
c as validateState,
|
|
46
|
+
k as validateTextField
|
|
45
47
|
};
|