@sharadox/form-web-library 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.
- package/NOTICE.md +6 -0
- package/README.md +22 -2
- package/distribution/calling-code/index.d.ts +257 -0
- package/distribution/calling-code/index.d.ts.map +1 -0
- package/distribution/calling-code/index.js +268 -0
- package/distribution/calling-code/index.js.map +1 -0
- package/distribution/phone-field/index.d.ts +14 -0
- package/distribution/phone-field/index.d.ts.map +1 -0
- package/distribution/phone-field/index.js +95 -0
- package/distribution/phone-field/index.js.map +1 -0
- package/distribution/phone-field/index.module.css +104 -0
- package/distribution/phone-field/type.d.ts +21 -0
- package/distribution/phone-field/type.d.ts.map +1 -0
- package/distribution/phone-field/type.js +2 -0
- package/distribution/phone-field/type.js.map +1 -0
- package/distribution/phone-number/index.d.ts +22 -0
- package/distribution/phone-number/index.d.ts.map +1 -0
- package/distribution/phone-number/index.js +37 -0
- package/distribution/phone-number/index.js.map +1 -0
- package/llms.txt +5 -0
- package/package.json +23 -4
package/NOTICE.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
Direitos de autor © 2026 Micael Pires (Sharadox).
|
|
2
2
|
Licenciado ao abrigo da Licença Sharadox de Código Aberto, versão 0.1.0.
|
|
3
3
|
https://github.com/Sharadox/sharadox-open-source-license
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Os indicativos internacionais (`source/calling-code`) vêm dos metadados da libphonenumber, da Google, sob a licença Apache 2.0:
|
|
8
|
+
The international calling codes (`source/calling-code`) come from Google's libphonenumber metadata, under the Apache License 2.0:
|
|
9
|
+
https://github.com/google/libphonenumber · https://www.apache.org/licenses/LICENSE-2.0
|
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# @sharadox/form-web-library
|
|
2
2
|
|
|
3
|
-
Forms
|
|
3
|
+
Forms, written once for every site.
|
|
4
|
+
|
|
5
|
+
In the browser:
|
|
6
|
+
|
|
7
|
+
- **A phone field (`phone-field`):** a button with the country's flag and calling code opens a searchable list of every country, named in the page's language, and the number box beside it takes digits only. Pasting "+44…" or "0044…" picks the country. The form receives one field with "+351 912345678". Its colors come from the text and the `--phone-field-*` variables (`-line`, `-accent`, `-surface`, `-popover`, `-radius`, `-gap`). Flags come from `@sharadox/icon-web-library` and load on their own, after the field.
|
|
8
|
+
|
|
9
|
+
On the server:
|
|
4
10
|
|
|
5
11
|
- **Field reading:** trimmed and capped in length.
|
|
6
12
|
- **Bot checks:** a hidden honeypot field, and a minimum time to fill the form.
|
|
@@ -13,6 +19,19 @@ Forms on the server, written once for every site:
|
|
|
13
19
|
- add single-line fields (`fields: { place: "Home" }`)
|
|
14
20
|
- write the email in the inbox's language (`labels`)
|
|
15
21
|
|
|
22
|
+
```tsx
|
|
23
|
+
<PhoneField
|
|
24
|
+
name="phone"
|
|
25
|
+
locale="pt"
|
|
26
|
+
defaultCountry="PT"
|
|
27
|
+
labels={{ country: "País", search: "Procurar" }}
|
|
28
|
+
inputProps={{ id: "phone", "aria-describedby": "phone-error" }}
|
|
29
|
+
inputClassName={styles.input}
|
|
30
|
+
/>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Also: `calling-code` (`CALLING_CODES` by country, `MAIN_CALLING_COUNTRY` for shared codes) and `phone-number` (`readPhone(text, country)`, `fullPhone(country, digits)`).
|
|
34
|
+
|
|
16
35
|
## Install
|
|
17
36
|
|
|
18
37
|
```sh
|
|
@@ -29,7 +48,7 @@ export const sendContact = createContactAction({
|
|
|
29
48
|
site: "example.com",
|
|
30
49
|
choices: { website: "Website", logo: "Logo", other: "Others" },
|
|
31
50
|
logo: async () => ({ content: await readFile(LOGO), contentType: "image/png", filename: "logo.png" }),
|
|
32
|
-
design:
|
|
51
|
+
design: EXAMPLE_EMAIL, // the brand's EmailDesign (email-web-library): colors, type, rules, header, signature
|
|
33
52
|
acknowledgement: {
|
|
34
53
|
en: {
|
|
35
54
|
subject: "Example · We received your message",
|
|
@@ -37,6 +56,7 @@ export const sendContact = createContactAction({
|
|
|
37
56
|
heading: (name) => `Thank you, ${name}.`,
|
|
38
57
|
paragraphs: ["We'll get back to you shortly."],
|
|
39
58
|
messageLabel: "Your message",
|
|
59
|
+
button: { label: "Visit example.com", href: "https://example.com" }, // optional
|
|
40
60
|
},
|
|
41
61
|
},
|
|
42
62
|
});
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every country's international calling code (digits after the "+"), by ISO 3166-1 alpha-2 code. Countries sharing
|
|
3
|
+
* a code (the United States, Canada and the Caribbean share 1) each have it. From libphonenumber's metadata (Apache
|
|
4
|
+
* 2.0, see NOTICE.md).
|
|
5
|
+
*/
|
|
6
|
+
export declare const CALLING_CODES: {
|
|
7
|
+
readonly AC: "247";
|
|
8
|
+
readonly AD: "376";
|
|
9
|
+
readonly AE: "971";
|
|
10
|
+
readonly AF: "93";
|
|
11
|
+
readonly AG: "1";
|
|
12
|
+
readonly AI: "1";
|
|
13
|
+
readonly AL: "355";
|
|
14
|
+
readonly AM: "374";
|
|
15
|
+
readonly AO: "244";
|
|
16
|
+
readonly AR: "54";
|
|
17
|
+
readonly AS: "1";
|
|
18
|
+
readonly AT: "43";
|
|
19
|
+
readonly AU: "61";
|
|
20
|
+
readonly AW: "297";
|
|
21
|
+
readonly AX: "358";
|
|
22
|
+
readonly AZ: "994";
|
|
23
|
+
readonly BA: "387";
|
|
24
|
+
readonly BB: "1";
|
|
25
|
+
readonly BD: "880";
|
|
26
|
+
readonly BE: "32";
|
|
27
|
+
readonly BF: "226";
|
|
28
|
+
readonly BG: "359";
|
|
29
|
+
readonly BH: "973";
|
|
30
|
+
readonly BI: "257";
|
|
31
|
+
readonly BJ: "229";
|
|
32
|
+
readonly BL: "590";
|
|
33
|
+
readonly BM: "1";
|
|
34
|
+
readonly BN: "673";
|
|
35
|
+
readonly BO: "591";
|
|
36
|
+
readonly BQ: "599";
|
|
37
|
+
readonly BR: "55";
|
|
38
|
+
readonly BS: "1";
|
|
39
|
+
readonly BT: "975";
|
|
40
|
+
readonly BW: "267";
|
|
41
|
+
readonly BY: "375";
|
|
42
|
+
readonly BZ: "501";
|
|
43
|
+
readonly CA: "1";
|
|
44
|
+
readonly CC: "61";
|
|
45
|
+
readonly CD: "243";
|
|
46
|
+
readonly CF: "236";
|
|
47
|
+
readonly CG: "242";
|
|
48
|
+
readonly CH: "41";
|
|
49
|
+
readonly CI: "225";
|
|
50
|
+
readonly CK: "682";
|
|
51
|
+
readonly CL: "56";
|
|
52
|
+
readonly CM: "237";
|
|
53
|
+
readonly CN: "86";
|
|
54
|
+
readonly CO: "57";
|
|
55
|
+
readonly CR: "506";
|
|
56
|
+
readonly CU: "53";
|
|
57
|
+
readonly CV: "238";
|
|
58
|
+
readonly CW: "599";
|
|
59
|
+
readonly CX: "61";
|
|
60
|
+
readonly CY: "357";
|
|
61
|
+
readonly CZ: "420";
|
|
62
|
+
readonly DE: "49";
|
|
63
|
+
readonly DJ: "253";
|
|
64
|
+
readonly DK: "45";
|
|
65
|
+
readonly DM: "1";
|
|
66
|
+
readonly DO: "1";
|
|
67
|
+
readonly DZ: "213";
|
|
68
|
+
readonly EC: "593";
|
|
69
|
+
readonly EE: "372";
|
|
70
|
+
readonly EG: "20";
|
|
71
|
+
readonly EH: "212";
|
|
72
|
+
readonly ER: "291";
|
|
73
|
+
readonly ES: "34";
|
|
74
|
+
readonly ET: "251";
|
|
75
|
+
readonly FI: "358";
|
|
76
|
+
readonly FJ: "679";
|
|
77
|
+
readonly FK: "500";
|
|
78
|
+
readonly FM: "691";
|
|
79
|
+
readonly FO: "298";
|
|
80
|
+
readonly FR: "33";
|
|
81
|
+
readonly GA: "241";
|
|
82
|
+
readonly GB: "44";
|
|
83
|
+
readonly GD: "1";
|
|
84
|
+
readonly GE: "995";
|
|
85
|
+
readonly GF: "594";
|
|
86
|
+
readonly GG: "44";
|
|
87
|
+
readonly GH: "233";
|
|
88
|
+
readonly GI: "350";
|
|
89
|
+
readonly GL: "299";
|
|
90
|
+
readonly GM: "220";
|
|
91
|
+
readonly GN: "224";
|
|
92
|
+
readonly GP: "590";
|
|
93
|
+
readonly GQ: "240";
|
|
94
|
+
readonly GR: "30";
|
|
95
|
+
readonly GT: "502";
|
|
96
|
+
readonly GU: "1";
|
|
97
|
+
readonly GW: "245";
|
|
98
|
+
readonly GY: "592";
|
|
99
|
+
readonly HK: "852";
|
|
100
|
+
readonly HN: "504";
|
|
101
|
+
readonly HR: "385";
|
|
102
|
+
readonly HT: "509";
|
|
103
|
+
readonly HU: "36";
|
|
104
|
+
readonly ID: "62";
|
|
105
|
+
readonly IE: "353";
|
|
106
|
+
readonly IL: "972";
|
|
107
|
+
readonly IM: "44";
|
|
108
|
+
readonly IN: "91";
|
|
109
|
+
readonly IO: "246";
|
|
110
|
+
readonly IQ: "964";
|
|
111
|
+
readonly IR: "98";
|
|
112
|
+
readonly IS: "354";
|
|
113
|
+
readonly IT: "39";
|
|
114
|
+
readonly JE: "44";
|
|
115
|
+
readonly JM: "1";
|
|
116
|
+
readonly JO: "962";
|
|
117
|
+
readonly JP: "81";
|
|
118
|
+
readonly KE: "254";
|
|
119
|
+
readonly KG: "996";
|
|
120
|
+
readonly KH: "855";
|
|
121
|
+
readonly KI: "686";
|
|
122
|
+
readonly KM: "269";
|
|
123
|
+
readonly KN: "1";
|
|
124
|
+
readonly KP: "850";
|
|
125
|
+
readonly KR: "82";
|
|
126
|
+
readonly KW: "965";
|
|
127
|
+
readonly KY: "1";
|
|
128
|
+
readonly KZ: "7";
|
|
129
|
+
readonly LA: "856";
|
|
130
|
+
readonly LB: "961";
|
|
131
|
+
readonly LC: "1";
|
|
132
|
+
readonly LI: "423";
|
|
133
|
+
readonly LK: "94";
|
|
134
|
+
readonly LR: "231";
|
|
135
|
+
readonly LS: "266";
|
|
136
|
+
readonly LT: "370";
|
|
137
|
+
readonly LU: "352";
|
|
138
|
+
readonly LV: "371";
|
|
139
|
+
readonly LY: "218";
|
|
140
|
+
readonly MA: "212";
|
|
141
|
+
readonly MC: "377";
|
|
142
|
+
readonly MD: "373";
|
|
143
|
+
readonly ME: "382";
|
|
144
|
+
readonly MF: "590";
|
|
145
|
+
readonly MG: "261";
|
|
146
|
+
readonly MH: "692";
|
|
147
|
+
readonly MK: "389";
|
|
148
|
+
readonly ML: "223";
|
|
149
|
+
readonly MM: "95";
|
|
150
|
+
readonly MN: "976";
|
|
151
|
+
readonly MO: "853";
|
|
152
|
+
readonly MP: "1";
|
|
153
|
+
readonly MQ: "596";
|
|
154
|
+
readonly MR: "222";
|
|
155
|
+
readonly MS: "1";
|
|
156
|
+
readonly MT: "356";
|
|
157
|
+
readonly MU: "230";
|
|
158
|
+
readonly MV: "960";
|
|
159
|
+
readonly MW: "265";
|
|
160
|
+
readonly MX: "52";
|
|
161
|
+
readonly MY: "60";
|
|
162
|
+
readonly MZ: "258";
|
|
163
|
+
readonly NA: "264";
|
|
164
|
+
readonly NC: "687";
|
|
165
|
+
readonly NE: "227";
|
|
166
|
+
readonly NF: "672";
|
|
167
|
+
readonly NG: "234";
|
|
168
|
+
readonly NI: "505";
|
|
169
|
+
readonly NL: "31";
|
|
170
|
+
readonly NO: "47";
|
|
171
|
+
readonly NP: "977";
|
|
172
|
+
readonly NR: "674";
|
|
173
|
+
readonly NU: "683";
|
|
174
|
+
readonly NZ: "64";
|
|
175
|
+
readonly OM: "968";
|
|
176
|
+
readonly PA: "507";
|
|
177
|
+
readonly PE: "51";
|
|
178
|
+
readonly PF: "689";
|
|
179
|
+
readonly PG: "675";
|
|
180
|
+
readonly PH: "63";
|
|
181
|
+
readonly PK: "92";
|
|
182
|
+
readonly PL: "48";
|
|
183
|
+
readonly PM: "508";
|
|
184
|
+
readonly PR: "1";
|
|
185
|
+
readonly PS: "970";
|
|
186
|
+
readonly PT: "351";
|
|
187
|
+
readonly PW: "680";
|
|
188
|
+
readonly PY: "595";
|
|
189
|
+
readonly QA: "974";
|
|
190
|
+
readonly RE: "262";
|
|
191
|
+
readonly RO: "40";
|
|
192
|
+
readonly RS: "381";
|
|
193
|
+
readonly RU: "7";
|
|
194
|
+
readonly RW: "250";
|
|
195
|
+
readonly SA: "966";
|
|
196
|
+
readonly SB: "677";
|
|
197
|
+
readonly SC: "248";
|
|
198
|
+
readonly SD: "249";
|
|
199
|
+
readonly SE: "46";
|
|
200
|
+
readonly SG: "65";
|
|
201
|
+
readonly SH: "290";
|
|
202
|
+
readonly SI: "386";
|
|
203
|
+
readonly SJ: "47";
|
|
204
|
+
readonly SK: "421";
|
|
205
|
+
readonly SL: "232";
|
|
206
|
+
readonly SM: "378";
|
|
207
|
+
readonly SN: "221";
|
|
208
|
+
readonly SO: "252";
|
|
209
|
+
readonly SR: "597";
|
|
210
|
+
readonly SS: "211";
|
|
211
|
+
readonly ST: "239";
|
|
212
|
+
readonly SV: "503";
|
|
213
|
+
readonly SX: "1";
|
|
214
|
+
readonly SY: "963";
|
|
215
|
+
readonly SZ: "268";
|
|
216
|
+
readonly TA: "290";
|
|
217
|
+
readonly TC: "1";
|
|
218
|
+
readonly TD: "235";
|
|
219
|
+
readonly TG: "228";
|
|
220
|
+
readonly TH: "66";
|
|
221
|
+
readonly TJ: "992";
|
|
222
|
+
readonly TK: "690";
|
|
223
|
+
readonly TL: "670";
|
|
224
|
+
readonly TM: "993";
|
|
225
|
+
readonly TN: "216";
|
|
226
|
+
readonly TO: "676";
|
|
227
|
+
readonly TR: "90";
|
|
228
|
+
readonly TT: "1";
|
|
229
|
+
readonly TV: "688";
|
|
230
|
+
readonly TW: "886";
|
|
231
|
+
readonly TZ: "255";
|
|
232
|
+
readonly UA: "380";
|
|
233
|
+
readonly UG: "256";
|
|
234
|
+
readonly US: "1";
|
|
235
|
+
readonly UY: "598";
|
|
236
|
+
readonly UZ: "998";
|
|
237
|
+
readonly VA: "39";
|
|
238
|
+
readonly VC: "1";
|
|
239
|
+
readonly VE: "58";
|
|
240
|
+
readonly VG: "1";
|
|
241
|
+
readonly VI: "1";
|
|
242
|
+
readonly VN: "84";
|
|
243
|
+
readonly VU: "678";
|
|
244
|
+
readonly WF: "681";
|
|
245
|
+
readonly WS: "685";
|
|
246
|
+
readonly XK: "383";
|
|
247
|
+
readonly YE: "967";
|
|
248
|
+
readonly YT: "262";
|
|
249
|
+
readonly ZA: "27";
|
|
250
|
+
readonly ZM: "260";
|
|
251
|
+
readonly ZW: "263";
|
|
252
|
+
};
|
|
253
|
+
/** A country that has a calling code. */
|
|
254
|
+
export type CallingCountry = keyof typeof CALLING_CODES;
|
|
255
|
+
/** For a calling code several countries share, the one it belongs to first (1 is the United States). */
|
|
256
|
+
export declare const MAIN_CALLING_COUNTRY: Readonly<Record<string, CallingCountry>>;
|
|
257
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/calling-code/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsPhB,CAAC;AAEX,yCAAyC;AACzC,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,aAAa,CAAC;AAExD,wGAAwG;AACxG,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAazE,CAAC"}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every country's international calling code (digits after the "+"), by ISO 3166-1 alpha-2 code. Countries sharing
|
|
3
|
+
* a code (the United States, Canada and the Caribbean share 1) each have it. From libphonenumber's metadata (Apache
|
|
4
|
+
* 2.0, see NOTICE.md).
|
|
5
|
+
*/
|
|
6
|
+
export const CALLING_CODES = {
|
|
7
|
+
AC: "247",
|
|
8
|
+
AD: "376",
|
|
9
|
+
AE: "971",
|
|
10
|
+
AF: "93",
|
|
11
|
+
AG: "1",
|
|
12
|
+
AI: "1",
|
|
13
|
+
AL: "355",
|
|
14
|
+
AM: "374",
|
|
15
|
+
AO: "244",
|
|
16
|
+
AR: "54",
|
|
17
|
+
AS: "1",
|
|
18
|
+
AT: "43",
|
|
19
|
+
AU: "61",
|
|
20
|
+
AW: "297",
|
|
21
|
+
AX: "358",
|
|
22
|
+
AZ: "994",
|
|
23
|
+
BA: "387",
|
|
24
|
+
BB: "1",
|
|
25
|
+
BD: "880",
|
|
26
|
+
BE: "32",
|
|
27
|
+
BF: "226",
|
|
28
|
+
BG: "359",
|
|
29
|
+
BH: "973",
|
|
30
|
+
BI: "257",
|
|
31
|
+
BJ: "229",
|
|
32
|
+
BL: "590",
|
|
33
|
+
BM: "1",
|
|
34
|
+
BN: "673",
|
|
35
|
+
BO: "591",
|
|
36
|
+
BQ: "599",
|
|
37
|
+
BR: "55",
|
|
38
|
+
BS: "1",
|
|
39
|
+
BT: "975",
|
|
40
|
+
BW: "267",
|
|
41
|
+
BY: "375",
|
|
42
|
+
BZ: "501",
|
|
43
|
+
CA: "1",
|
|
44
|
+
CC: "61",
|
|
45
|
+
CD: "243",
|
|
46
|
+
CF: "236",
|
|
47
|
+
CG: "242",
|
|
48
|
+
CH: "41",
|
|
49
|
+
CI: "225",
|
|
50
|
+
CK: "682",
|
|
51
|
+
CL: "56",
|
|
52
|
+
CM: "237",
|
|
53
|
+
CN: "86",
|
|
54
|
+
CO: "57",
|
|
55
|
+
CR: "506",
|
|
56
|
+
CU: "53",
|
|
57
|
+
CV: "238",
|
|
58
|
+
CW: "599",
|
|
59
|
+
CX: "61",
|
|
60
|
+
CY: "357",
|
|
61
|
+
CZ: "420",
|
|
62
|
+
DE: "49",
|
|
63
|
+
DJ: "253",
|
|
64
|
+
DK: "45",
|
|
65
|
+
DM: "1",
|
|
66
|
+
DO: "1",
|
|
67
|
+
DZ: "213",
|
|
68
|
+
EC: "593",
|
|
69
|
+
EE: "372",
|
|
70
|
+
EG: "20",
|
|
71
|
+
EH: "212",
|
|
72
|
+
ER: "291",
|
|
73
|
+
ES: "34",
|
|
74
|
+
ET: "251",
|
|
75
|
+
FI: "358",
|
|
76
|
+
FJ: "679",
|
|
77
|
+
FK: "500",
|
|
78
|
+
FM: "691",
|
|
79
|
+
FO: "298",
|
|
80
|
+
FR: "33",
|
|
81
|
+
GA: "241",
|
|
82
|
+
GB: "44",
|
|
83
|
+
GD: "1",
|
|
84
|
+
GE: "995",
|
|
85
|
+
GF: "594",
|
|
86
|
+
GG: "44",
|
|
87
|
+
GH: "233",
|
|
88
|
+
GI: "350",
|
|
89
|
+
GL: "299",
|
|
90
|
+
GM: "220",
|
|
91
|
+
GN: "224",
|
|
92
|
+
GP: "590",
|
|
93
|
+
GQ: "240",
|
|
94
|
+
GR: "30",
|
|
95
|
+
GT: "502",
|
|
96
|
+
GU: "1",
|
|
97
|
+
GW: "245",
|
|
98
|
+
GY: "592",
|
|
99
|
+
HK: "852",
|
|
100
|
+
HN: "504",
|
|
101
|
+
HR: "385",
|
|
102
|
+
HT: "509",
|
|
103
|
+
HU: "36",
|
|
104
|
+
ID: "62",
|
|
105
|
+
IE: "353",
|
|
106
|
+
IL: "972",
|
|
107
|
+
IM: "44",
|
|
108
|
+
IN: "91",
|
|
109
|
+
IO: "246",
|
|
110
|
+
IQ: "964",
|
|
111
|
+
IR: "98",
|
|
112
|
+
IS: "354",
|
|
113
|
+
IT: "39",
|
|
114
|
+
JE: "44",
|
|
115
|
+
JM: "1",
|
|
116
|
+
JO: "962",
|
|
117
|
+
JP: "81",
|
|
118
|
+
KE: "254",
|
|
119
|
+
KG: "996",
|
|
120
|
+
KH: "855",
|
|
121
|
+
KI: "686",
|
|
122
|
+
KM: "269",
|
|
123
|
+
KN: "1",
|
|
124
|
+
KP: "850",
|
|
125
|
+
KR: "82",
|
|
126
|
+
KW: "965",
|
|
127
|
+
KY: "1",
|
|
128
|
+
KZ: "7",
|
|
129
|
+
LA: "856",
|
|
130
|
+
LB: "961",
|
|
131
|
+
LC: "1",
|
|
132
|
+
LI: "423",
|
|
133
|
+
LK: "94",
|
|
134
|
+
LR: "231",
|
|
135
|
+
LS: "266",
|
|
136
|
+
LT: "370",
|
|
137
|
+
LU: "352",
|
|
138
|
+
LV: "371",
|
|
139
|
+
LY: "218",
|
|
140
|
+
MA: "212",
|
|
141
|
+
MC: "377",
|
|
142
|
+
MD: "373",
|
|
143
|
+
ME: "382",
|
|
144
|
+
MF: "590",
|
|
145
|
+
MG: "261",
|
|
146
|
+
MH: "692",
|
|
147
|
+
MK: "389",
|
|
148
|
+
ML: "223",
|
|
149
|
+
MM: "95",
|
|
150
|
+
MN: "976",
|
|
151
|
+
MO: "853",
|
|
152
|
+
MP: "1",
|
|
153
|
+
MQ: "596",
|
|
154
|
+
MR: "222",
|
|
155
|
+
MS: "1",
|
|
156
|
+
MT: "356",
|
|
157
|
+
MU: "230",
|
|
158
|
+
MV: "960",
|
|
159
|
+
MW: "265",
|
|
160
|
+
MX: "52",
|
|
161
|
+
MY: "60",
|
|
162
|
+
MZ: "258",
|
|
163
|
+
NA: "264",
|
|
164
|
+
NC: "687",
|
|
165
|
+
NE: "227",
|
|
166
|
+
NF: "672",
|
|
167
|
+
NG: "234",
|
|
168
|
+
NI: "505",
|
|
169
|
+
NL: "31",
|
|
170
|
+
NO: "47",
|
|
171
|
+
NP: "977",
|
|
172
|
+
NR: "674",
|
|
173
|
+
NU: "683",
|
|
174
|
+
NZ: "64",
|
|
175
|
+
OM: "968",
|
|
176
|
+
PA: "507",
|
|
177
|
+
PE: "51",
|
|
178
|
+
PF: "689",
|
|
179
|
+
PG: "675",
|
|
180
|
+
PH: "63",
|
|
181
|
+
PK: "92",
|
|
182
|
+
PL: "48",
|
|
183
|
+
PM: "508",
|
|
184
|
+
PR: "1",
|
|
185
|
+
PS: "970",
|
|
186
|
+
PT: "351",
|
|
187
|
+
PW: "680",
|
|
188
|
+
PY: "595",
|
|
189
|
+
QA: "974",
|
|
190
|
+
RE: "262",
|
|
191
|
+
RO: "40",
|
|
192
|
+
RS: "381",
|
|
193
|
+
RU: "7",
|
|
194
|
+
RW: "250",
|
|
195
|
+
SA: "966",
|
|
196
|
+
SB: "677",
|
|
197
|
+
SC: "248",
|
|
198
|
+
SD: "249",
|
|
199
|
+
SE: "46",
|
|
200
|
+
SG: "65",
|
|
201
|
+
SH: "290",
|
|
202
|
+
SI: "386",
|
|
203
|
+
SJ: "47",
|
|
204
|
+
SK: "421",
|
|
205
|
+
SL: "232",
|
|
206
|
+
SM: "378",
|
|
207
|
+
SN: "221",
|
|
208
|
+
SO: "252",
|
|
209
|
+
SR: "597",
|
|
210
|
+
SS: "211",
|
|
211
|
+
ST: "239",
|
|
212
|
+
SV: "503",
|
|
213
|
+
SX: "1",
|
|
214
|
+
SY: "963",
|
|
215
|
+
SZ: "268",
|
|
216
|
+
TA: "290",
|
|
217
|
+
TC: "1",
|
|
218
|
+
TD: "235",
|
|
219
|
+
TG: "228",
|
|
220
|
+
TH: "66",
|
|
221
|
+
TJ: "992",
|
|
222
|
+
TK: "690",
|
|
223
|
+
TL: "670",
|
|
224
|
+
TM: "993",
|
|
225
|
+
TN: "216",
|
|
226
|
+
TO: "676",
|
|
227
|
+
TR: "90",
|
|
228
|
+
TT: "1",
|
|
229
|
+
TV: "688",
|
|
230
|
+
TW: "886",
|
|
231
|
+
TZ: "255",
|
|
232
|
+
UA: "380",
|
|
233
|
+
UG: "256",
|
|
234
|
+
US: "1",
|
|
235
|
+
UY: "598",
|
|
236
|
+
UZ: "998",
|
|
237
|
+
VA: "39",
|
|
238
|
+
VC: "1",
|
|
239
|
+
VE: "58",
|
|
240
|
+
VG: "1",
|
|
241
|
+
VI: "1",
|
|
242
|
+
VN: "84",
|
|
243
|
+
VU: "678",
|
|
244
|
+
WF: "681",
|
|
245
|
+
WS: "685",
|
|
246
|
+
XK: "383",
|
|
247
|
+
YE: "967",
|
|
248
|
+
YT: "262",
|
|
249
|
+
ZA: "27",
|
|
250
|
+
ZM: "260",
|
|
251
|
+
ZW: "263",
|
|
252
|
+
};
|
|
253
|
+
/** For a calling code several countries share, the one it belongs to first (1 is the United States). */
|
|
254
|
+
export const MAIN_CALLING_COUNTRY = {
|
|
255
|
+
"1": "US",
|
|
256
|
+
"7": "RU",
|
|
257
|
+
"39": "IT",
|
|
258
|
+
"44": "GB",
|
|
259
|
+
"47": "NO",
|
|
260
|
+
"61": "AU",
|
|
261
|
+
"212": "MA",
|
|
262
|
+
"262": "RE",
|
|
263
|
+
"290": "SH",
|
|
264
|
+
"358": "FI",
|
|
265
|
+
"590": "GP",
|
|
266
|
+
"599": "CW",
|
|
267
|
+
};
|
|
268
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/calling-code/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,KAAK;IACT,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AAG;IACP,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,KAAK;IACT,EAAE,EAAE,KAAK;CACD,CAAC;AAKX,wGAAwG;AACxG,MAAM,CAAC,MAAM,oBAAoB,GAA6C;IAC5E,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,IAAI;CACZ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PhoneFieldProperties } from "@sharadox/form-web-library/phone-field/type";
|
|
2
|
+
/**
|
|
3
|
+
* A phone number with its country: a button with the country's flag and calling code opens a searchable list of every
|
|
4
|
+
* country (names in the page's language), and beside it a box that takes digits only. Pasting or typing a number
|
|
5
|
+
* that starts with "+" or "00" picks its country. The form receives one field, `name`, holding "+351 912345678" (or
|
|
6
|
+
* nothing when no digits were typed). Arrow keys, Enter and Escape work in the list. Colors come from the text and
|
|
7
|
+
* from `--phone-field-*` variables; the number box takes `inputProps` (id, aria attributes, handlers) and the site's
|
|
8
|
+
* own input styles through `inputClassName`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* <PhoneField name="phone" locale="pt" defaultCountry="PT" inputProps={{ id: "phone" }} />
|
|
12
|
+
*/
|
|
13
|
+
export declare function PhoneField({ name, locale, defaultCountry, labels, inputProps, className, inputClassName, }: PhoneFieldProperties): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/phone-field/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAexF;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,EACzB,IAAI,EACJ,MAAM,EACN,cAAqB,EACrB,MAAiD,EACjD,UAAU,EACV,SAAS,EACT,cAAc,GACf,EAAE,oBAAoB,+BAyItB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { lazy, Suspense, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { Icon } from "@sharadox/icon-web-library/icon";
|
|
5
|
+
import { CALLING_CODES } from "@sharadox/form-web-library/calling-code";
|
|
6
|
+
import { fullPhone, readPhone } from "@sharadox/form-web-library/phone-number";
|
|
7
|
+
import styles from "./index.module.css";
|
|
8
|
+
// The flags are one module of about 47 KB compressed: loaded on their own, after the field is on screen.
|
|
9
|
+
const Flag = lazy(() => import("@sharadox/icon-web-library/flag").then((module) => ({ default: module.Flag })));
|
|
10
|
+
const COUNTRIES = Object.keys(CALLING_CODES);
|
|
11
|
+
/** A flag, with an empty box of the same size until the flags have loaded. */
|
|
12
|
+
function CountryFlag({ country }) {
|
|
13
|
+
return (_jsx(Suspense, { fallback: _jsx("span", { className: styles.flag }), children: _jsx(Flag, { country: country, className: styles.flag }) }));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A phone number with its country: a button with the country's flag and calling code opens a searchable list of every
|
|
17
|
+
* country (names in the page's language), and beside it a box that takes digits only. Pasting or typing a number
|
|
18
|
+
* that starts with "+" or "00" picks its country. The form receives one field, `name`, holding "+351 912345678" (or
|
|
19
|
+
* nothing when no digits were typed). Arrow keys, Enter and Escape work in the list. Colors come from the text and
|
|
20
|
+
* from `--phone-field-*` variables; the number box takes `inputProps` (id, aria attributes, handlers) and the site's
|
|
21
|
+
* own input styles through `inputClassName`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* <PhoneField name="phone" locale="pt" defaultCountry="PT" inputProps={{ id: "phone" }} />
|
|
25
|
+
*/
|
|
26
|
+
export function PhoneField({ name, locale, defaultCountry = "PT", labels = { country: "Country", search: "Search" }, inputProps, className, inputClassName, }) {
|
|
27
|
+
const [country, setCountry] = useState(defaultCountry);
|
|
28
|
+
const [digits, setDigits] = useState("");
|
|
29
|
+
const [open, setOpen] = useState(false);
|
|
30
|
+
const [query, setQuery] = useState("");
|
|
31
|
+
const [active, setActive] = useState(0);
|
|
32
|
+
const root = useRef(null);
|
|
33
|
+
const button = useRef(null);
|
|
34
|
+
const list = useRef(null);
|
|
35
|
+
const id = useId();
|
|
36
|
+
const names = useMemo(() => new Intl.DisplayNames([locale], { type: "region" }), [locale]);
|
|
37
|
+
// Every country by name in the page's language, the default one first.
|
|
38
|
+
const sorted = useMemo(() => [...COUNTRIES].sort((a, b) => a === defaultCountry ? -1 : b === defaultCountry ? 1 : names.of(a).localeCompare(names.of(b), locale)), [names, locale, defaultCountry]);
|
|
39
|
+
const wanted = query.trim().toLowerCase().replace(/^\+/, "");
|
|
40
|
+
const shown = wanted
|
|
41
|
+
? sorted.filter((code) => names.of(code).toLowerCase().includes(wanted) ||
|
|
42
|
+
code.toLowerCase() === wanted ||
|
|
43
|
+
CALLING_CODES[code].startsWith(wanted))
|
|
44
|
+
: sorted;
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!open)
|
|
47
|
+
return;
|
|
48
|
+
const away = (event) => {
|
|
49
|
+
if (!root.current.contains(event.target))
|
|
50
|
+
setOpen(false);
|
|
51
|
+
};
|
|
52
|
+
document.addEventListener("pointerdown", away);
|
|
53
|
+
return () => document.removeEventListener("pointerdown", away);
|
|
54
|
+
}, [open]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
list.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView?.({ block: "nearest" });
|
|
57
|
+
}, [active, open]);
|
|
58
|
+
const choose = (code) => {
|
|
59
|
+
setCountry(code);
|
|
60
|
+
setOpen(false);
|
|
61
|
+
setQuery("");
|
|
62
|
+
button.current.focus();
|
|
63
|
+
};
|
|
64
|
+
const keys = (event) => {
|
|
65
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
const step = event.key === "ArrowDown" ? 1 : -1;
|
|
68
|
+
setActive((index) => Math.min(Math.max(index + step, 0), Math.max(shown.length - 1, 0)));
|
|
69
|
+
}
|
|
70
|
+
else if (event.key === "Enter") {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
if (shown[active])
|
|
73
|
+
choose(shown[active]);
|
|
74
|
+
}
|
|
75
|
+
else if (event.key === "Escape") {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
setOpen(false);
|
|
78
|
+
button.current.focus();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const optionId = (index) => `${id}-option-${index}`;
|
|
82
|
+
return (_jsxs("div", { ref: root, className: [styles.field, className].filter(Boolean).join(" "), children: [_jsx("input", { type: "hidden", name: name, value: fullPhone(country, digits) }), _jsxs("button", { ref: button, type: "button", className: styles.prefix, "aria-haspopup": "listbox", "aria-expanded": open, "aria-label": `${labels.country}: ${names.of(country)} +${CALLING_CODES[country]}`, onClick: () => {
|
|
83
|
+
setOpen((now) => !now);
|
|
84
|
+
setActive(0);
|
|
85
|
+
}, children: [_jsx(CountryFlag, { country: country }), _jsxs("span", { children: ["+", CALLING_CODES[country]] }), _jsx(Icon, { name: "chevron-down", className: styles.chevron })] }), _jsx("input", { ...inputProps, type: "tel", inputMode: "numeric", autoComplete: "tel-national", className: inputClassName, value: digits, onChange: (event) => {
|
|
86
|
+
const read = readPhone(event.target.value, country);
|
|
87
|
+
setCountry(read.country);
|
|
88
|
+
setDigits(read.digits.slice(0, 15));
|
|
89
|
+
inputProps?.onChange?.(event);
|
|
90
|
+
} }), open && (_jsxs("div", { className: styles.popover, children: [_jsx("input", { className: styles.search, type: "search", role: "combobox", "aria-label": labels.search, "aria-expanded": true, "aria-controls": `${id}-list`, "aria-activedescendant": shown.length ? optionId(active) : undefined, placeholder: labels.search, value: query, autoFocus: true, onChange: (event) => {
|
|
91
|
+
setQuery(event.target.value);
|
|
92
|
+
setActive(0);
|
|
93
|
+
}, onKeyDown: keys }), _jsx("ul", { ref: list, id: `${id}-list`, role: "listbox", "aria-label": labels.country, className: styles.list, children: shown.map((code, index) => (_jsxs("li", { id: optionId(index), role: "option", "aria-selected": code === country, "data-index": index, "data-active": index === active || undefined, onPointerMove: () => setActive(index), onClick: () => choose(code), children: [_jsx(CountryFlag, { country: code }), _jsx("span", { className: styles.name, children: names.of(code) }), _jsxs("span", { className: styles.code, children: ["+", CALLING_CODES[code]] })] }, code))) })] }))] }));
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/phone-field/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAsB,MAAM,OAAO,CAAC;AACxG,OAAO,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AACvD,OAAO,EAAE,aAAa,EAAuB,MAAM,yCAAyC,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAGxC,yGAAyG;AACzG,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,iCAAiC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EA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OAAO,EAAE,IAAI,EAAC,SAAS,gBAAa,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,YAC/F,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAC1B,cAEE,EAAE,EAAE,QAAQ,CAAC,KAAK,CAAC,EACnB,IAAI,EAAC,QAAQ,mBACE,IAAI,KAAK,OAAO,gBACnB,KAAK,iBACJ,KAAK,KAAK,MAAM,IAAI,SAAS,EAC1C,aAAa,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EACrC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,aAE3B,KAAC,WAAW,IAAC,OAAO,EAAE,IAAI,GAAI,EAC9B,eAAM,SAAS,EAAE,MAAM,CAAC,IAAI,YAAG,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,GAAQ,EACrD,gBAAM,SAAS,EAAE,MAAM,CAAC,IAAI,kBAAI,aAAa,CAAC,IAAI,CAAC,IAAQ,KAXtD,IAAI,CAYN,CACN,CAAC,GACC,IACD,CACP,IACG,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/* The prefix button and the number box side by side; the list opens under both. */
|
|
2
|
+
.field {
|
|
3
|
+
position: relative;
|
|
4
|
+
display: grid;
|
|
5
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
6
|
+
align-items: stretch;
|
|
7
|
+
gap: var(--phone-field-gap, 8px);
|
|
8
|
+
}
|
|
9
|
+
.prefix {
|
|
10
|
+
display: inline-flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
gap: 8px;
|
|
13
|
+
padding: 0 12px;
|
|
14
|
+
border: 1px solid var(--phone-field-line, color-mix(in srgb, currentColor 22%, transparent));
|
|
15
|
+
border-radius: var(--phone-field-radius, 10px);
|
|
16
|
+
background: var(--phone-field-surface, transparent);
|
|
17
|
+
color: inherit;
|
|
18
|
+
font: inherit;
|
|
19
|
+
font-variant-numeric: tabular-nums;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
transition: border-color 0.2s;
|
|
22
|
+
}
|
|
23
|
+
.prefix:hover,
|
|
24
|
+
.prefix[aria-expanded="true"] {
|
|
25
|
+
border-color: var(--phone-field-accent, currentColor);
|
|
26
|
+
}
|
|
27
|
+
.prefix:focus-visible {
|
|
28
|
+
outline: 2px solid var(--phone-field-accent, currentColor);
|
|
29
|
+
outline-offset: 2px;
|
|
30
|
+
}
|
|
31
|
+
.flag {
|
|
32
|
+
display: inline-block;
|
|
33
|
+
flex: none;
|
|
34
|
+
width: 1.5em;
|
|
35
|
+
height: 1em;
|
|
36
|
+
border-radius: 2px;
|
|
37
|
+
box-shadow: 0 0 0 1px color-mix(in srgb, currentColor 18%, transparent);
|
|
38
|
+
overflow: hidden;
|
|
39
|
+
}
|
|
40
|
+
.chevron {
|
|
41
|
+
width: 0.9em;
|
|
42
|
+
height: 0.9em;
|
|
43
|
+
opacity: 0.6;
|
|
44
|
+
}
|
|
45
|
+
.popover {
|
|
46
|
+
position: absolute;
|
|
47
|
+
z-index: 20;
|
|
48
|
+
top: calc(100% + 6px);
|
|
49
|
+
left: 0;
|
|
50
|
+
width: min(340px, 100%);
|
|
51
|
+
display: grid;
|
|
52
|
+
gap: 6px;
|
|
53
|
+
padding: 8px;
|
|
54
|
+
border: 1px solid var(--phone-field-line, color-mix(in srgb, currentColor 22%, transparent));
|
|
55
|
+
border-radius: var(--phone-field-radius, 10px);
|
|
56
|
+
background: var(--phone-field-popover, Canvas);
|
|
57
|
+
box-shadow: 0 24px 48px -16px rgb(0 0 0 / 0.45);
|
|
58
|
+
}
|
|
59
|
+
.search {
|
|
60
|
+
width: 100%;
|
|
61
|
+
padding: 10px 12px;
|
|
62
|
+
border: 1px solid var(--phone-field-line, color-mix(in srgb, currentColor 22%, transparent));
|
|
63
|
+
border-radius: calc(var(--phone-field-radius, 10px) - 2px);
|
|
64
|
+
background: transparent;
|
|
65
|
+
color: inherit;
|
|
66
|
+
font: inherit;
|
|
67
|
+
}
|
|
68
|
+
.search:focus-visible {
|
|
69
|
+
outline: none;
|
|
70
|
+
border-color: var(--phone-field-accent, currentColor);
|
|
71
|
+
}
|
|
72
|
+
.list {
|
|
73
|
+
max-height: 260px;
|
|
74
|
+
margin: 0;
|
|
75
|
+
padding: 0;
|
|
76
|
+
overflow-y: auto;
|
|
77
|
+
overscroll-behavior: contain;
|
|
78
|
+
list-style: none;
|
|
79
|
+
}
|
|
80
|
+
.list li {
|
|
81
|
+
display: grid;
|
|
82
|
+
grid-template-columns: auto minmax(0, 1fr) auto;
|
|
83
|
+
align-items: center;
|
|
84
|
+
gap: 10px;
|
|
85
|
+
padding: 8px 10px;
|
|
86
|
+
border-radius: 6px;
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
}
|
|
89
|
+
.list li[data-active] {
|
|
90
|
+
background: color-mix(in srgb, var(--phone-field-accent, currentColor) 14%, transparent);
|
|
91
|
+
}
|
|
92
|
+
.list li[aria-selected="true"] .name {
|
|
93
|
+
color: var(--phone-field-accent, inherit);
|
|
94
|
+
}
|
|
95
|
+
.name {
|
|
96
|
+
overflow: hidden;
|
|
97
|
+
text-overflow: ellipsis;
|
|
98
|
+
white-space: nowrap;
|
|
99
|
+
text-align: left;
|
|
100
|
+
}
|
|
101
|
+
.code {
|
|
102
|
+
opacity: 0.6;
|
|
103
|
+
font-variant-numeric: tabular-nums;
|
|
104
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { InputHTMLAttributes } from "react";
|
|
2
|
+
import type { CallingCountry } from "@sharadox/form-web-library/calling-code";
|
|
3
|
+
export interface PhoneFieldProperties {
|
|
4
|
+
/** The form field that receives the full number, "+351 912345678". */
|
|
5
|
+
name: string;
|
|
6
|
+
/** The page's language, for the countries' names (BCP 47, "pt" or "en-GB"). */
|
|
7
|
+
locale: string;
|
|
8
|
+
/** The country chosen at first, and first in the list. Defaults to Portugal. */
|
|
9
|
+
defaultCountry?: CallingCountry;
|
|
10
|
+
/** The picker's words for assistive technology and the search box. Default English. */
|
|
11
|
+
labels?: {
|
|
12
|
+
country: string;
|
|
13
|
+
search: string;
|
|
14
|
+
};
|
|
15
|
+
/** Passed to the number box: id, aria attributes, maxLength, onChange and so on (not type, value or name). */
|
|
16
|
+
inputProps?: Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "value" | "name" | "defaultValue">;
|
|
17
|
+
className?: string;
|
|
18
|
+
/** The site's own class for the number box. */
|
|
19
|
+
inputClassName?: string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/phone-field/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAE9E,MAAM,WAAW,oBAAoB;IACnC,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,uFAAuF;IACvF,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,8GAA8G;IAC9G,UAAU,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,cAAc,CAAC,CAAC;IACrG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/phone-field/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type CallingCountry } from "@sharadox/form-web-library/calling-code";
|
|
2
|
+
/**
|
|
3
|
+
* Splits what someone typed or pasted into a phone field. A leading "+" or "00" starts an international number, so
|
|
4
|
+
* its calling code picks the country (the longest code that matches; `current` stays when it shares that code, so
|
|
5
|
+
* Canada isn't swapped for the United States, and otherwise a shared code goes to its main country). Everything else that isn't a digit is dropped.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* readPhone("+351 912 345 678", "GB"); // { country: "PT", digits: "912345678" }
|
|
9
|
+
* readPhone("912-345", "PT"); // { country: "PT", digits: "912345" }
|
|
10
|
+
*/
|
|
11
|
+
export declare function readPhone(text: string, current: CallingCountry): {
|
|
12
|
+
country: CallingCountry;
|
|
13
|
+
digits: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The full number to send: "+<calling code> <digits>", or nothing without digits.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* fullPhone("PT", "912345678"); // "+351 912345678"
|
|
20
|
+
*/
|
|
21
|
+
export declare function fullPhone(country: CallingCountry, digits: string): string;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/phone-number/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAEnH;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG;IAAE,OAAO,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAc5G;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEzE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CALLING_CODES, MAIN_CALLING_COUNTRY } from "@sharadox/form-web-library/calling-code";
|
|
2
|
+
/**
|
|
3
|
+
* Splits what someone typed or pasted into a phone field. A leading "+" or "00" starts an international number, so
|
|
4
|
+
* its calling code picks the country (the longest code that matches; `current` stays when it shares that code, so
|
|
5
|
+
* Canada isn't swapped for the United States, and otherwise a shared code goes to its main country). Everything else that isn't a digit is dropped.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* readPhone("+351 912 345 678", "GB"); // { country: "PT", digits: "912345678" }
|
|
9
|
+
* readPhone("912-345", "PT"); // { country: "PT", digits: "912345" }
|
|
10
|
+
*/
|
|
11
|
+
export function readPhone(text, current) {
|
|
12
|
+
const international = /^\s*(\+|00)/.exec(text);
|
|
13
|
+
const digits = text.replace(/\D/g, "");
|
|
14
|
+
if (!international)
|
|
15
|
+
return { country: current, digits };
|
|
16
|
+
const rest = international[1] === "00" ? digits.slice(2) : digits;
|
|
17
|
+
for (let length = 3; length >= 1; length--) {
|
|
18
|
+
const code = rest.slice(0, length);
|
|
19
|
+
if (CALLING_CODES[current] === code)
|
|
20
|
+
return { country: current, digits: rest.slice(length) };
|
|
21
|
+
const country = MAIN_CALLING_COUNTRY[code] ??
|
|
22
|
+
Object.keys(CALLING_CODES).find((key) => CALLING_CODES[key] === code);
|
|
23
|
+
if (country)
|
|
24
|
+
return { country, digits: rest.slice(length) };
|
|
25
|
+
}
|
|
26
|
+
return { country: current, digits: rest };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The full number to send: "+<calling code> <digits>", or nothing without digits.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* fullPhone("PT", "912345678"); // "+351 912345678"
|
|
33
|
+
*/
|
|
34
|
+
export function fullPhone(country, digits) {
|
|
35
|
+
return digits ? `+${CALLING_CODES[country]} ${digits}` : "";
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|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,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC5C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,OAAuB,EAAE,MAAc;IAC/D,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,OAAO,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC9D,CAAC"}
|
package/llms.txt
CHANGED
|
@@ -8,3 +8,8 @@
|
|
|
8
8
|
- /contact-check isEmail(text), isPhone(text) (browser-safe, same rules as the server); /bot-check isLikelyBot; /rate-limit createRateLimiter({ window, maximum }); /field readField(form, name, max)
|
|
9
9
|
- Env: EMAIL_SERVER_HOST/PORT/USERNAME/PASSWORD, EMAIL_SENDER_ADDRESS. License: Sharadox Open Source License 0.1.0
|
|
10
10
|
- 0.5.0: createContactAction takes `design` (email-web-library ^0.4.0 EmailDesign; plainDesign(company) by default) instead of `theme`, and lays out both emails with emailLayout; the notice has a button to answer the visitor (labels.reply "Reply to" + first name, or labels.call "Call" when only a phone was left); an acknowledgement may carry a `button`; with a design signature, the reply leaves out its line to the site; contact-email (brandedEmailHtml) is removed: use email-web-library's emailLayout
|
|
11
|
+
- 0.5.1: README's example passes a real EmailDesign
|
|
12
|
+
- phone-field (client, React): PhoneField({ name, locale, defaultCountry?="PT", labels?={country,search}, inputProps?, className?, inputClassName? }); flag+calling-code button opens searchable listbox (Intl.DisplayNames names, default country first, arrows/Enter/Escape, outside press closes); number box digits only (max 15), "+"/"00" paste picks country; hidden input `name` = "+<code> <digits>" or ""; CSS vars --phone-field-line/-accent/-surface/-popover/-radius/-gap; flags lazy-loaded from @sharadox/icon-web-library/flag
|
|
13
|
+
- calling-code: CALLING_CODES (ISO alpha-2 → digits, 245 countries, from libphonenumber metadata, Apache 2.0), MAIN_CALLING_COUNTRY (shared code → main country), type CallingCountry
|
|
14
|
+
- phone-number: readPhone(text, current) → { country, digits }; fullPhone(country, digits) → "+351 912345678" | ""
|
|
15
|
+
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/form-web-library",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Forms on the server
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Forms: a phone field with every country's flag and calling code, and on the server field reading, honeypot and fill-time bot checks, rate limiting and a contact form action that emails messages with the visitor as reply-to.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENCA.md",
|
|
7
7
|
"author": "Sharadox <contact@sharadox.com>",
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"NOTICE.md",
|
|
28
28
|
"llms.txt"
|
|
29
29
|
],
|
|
30
|
-
"sideEffects":
|
|
30
|
+
"sideEffects": [
|
|
31
|
+
"**/*.css"
|
|
32
|
+
],
|
|
31
33
|
"engines": {
|
|
32
34
|
"node": ">=26"
|
|
33
35
|
},
|
|
@@ -48,16 +50,24 @@
|
|
|
48
50
|
"homepage": "https://github.com/Sharadox/form-web-library#readme",
|
|
49
51
|
"devDependencies": {
|
|
50
52
|
"@sharadox/es-lint-configuration-web-library": "^0.1.1",
|
|
53
|
+
"@sharadox/library-build-web-library": "^0.1.2",
|
|
51
54
|
"@sharadox/prettier-configuration-web-library": "^0.1.0",
|
|
52
55
|
"@sharadox/turborepo-configuration-web-library": "^0.1.0",
|
|
53
56
|
"@sharadox/type-script-configuration-web-library": "^0.2.0",
|
|
54
57
|
"@sharadox/vitest-configuration-web-library": "^0.1.2",
|
|
58
|
+
"@testing-library/dom": "^10.4.2",
|
|
59
|
+
"@testing-library/react": "^16.3.3",
|
|
55
60
|
"@types/node": "^24.19.2",
|
|
61
|
+
"@types/react": "^19.3.0",
|
|
62
|
+
"@types/react-dom": "^19.3.0",
|
|
56
63
|
"@vitest/coverage-v8": "^5.1.0",
|
|
57
64
|
"eslint": "9.39.5",
|
|
65
|
+
"happy-dom": "^21.0.4",
|
|
58
66
|
"husky": "^9.1.7",
|
|
59
67
|
"lint-staged": "^17.6.0",
|
|
60
68
|
"prettier": "^3.10.0",
|
|
69
|
+
"react": "^19.3.1",
|
|
70
|
+
"react-dom": "^19.3.1",
|
|
61
71
|
"turbo": "^2.11.10",
|
|
62
72
|
"typedoc": "^0.28.20",
|
|
63
73
|
"typescript": "6.0.3",
|
|
@@ -65,10 +75,19 @@
|
|
|
65
75
|
},
|
|
66
76
|
"dependencies": {
|
|
67
77
|
"@sharadox/email-web-library": "^0.4.0",
|
|
78
|
+
"@sharadox/icon-web-library": "^0.6.0",
|
|
68
79
|
"@sharadox/web-library": "^0.7.0"
|
|
69
80
|
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"react": ">=19"
|
|
83
|
+
},
|
|
84
|
+
"peerDependenciesMeta": {
|
|
85
|
+
"react": {
|
|
86
|
+
"optional": true
|
|
87
|
+
}
|
|
88
|
+
},
|
|
70
89
|
"scripts": {
|
|
71
|
-
"build": "
|
|
90
|
+
"build": "library-build",
|
|
72
91
|
"lint": "eslint --max-warnings=0 .",
|
|
73
92
|
"format": "prettier --write .",
|
|
74
93
|
"format:check": "prettier --check .",
|